{"id":25420558,"url":"https://github.com/danielost/sha-1","last_synced_at":"2025-05-13T16:13:55.121Z","repository":{"id":206072802,"uuid":"715535056","full_name":"danielost/sha-1","owner":"danielost","description":"SHA-1 (Secure Hash Algorithm 1) implementation.","archived":false,"fork":false,"pushed_at":"2023-11-08T14:03:10.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T19:48:53.665Z","etag":null,"topics":["cryptography","secure-hash-algorithm","sha-1"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielost.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T10:41:13.000Z","updated_at":"2023-11-08T14:12:38.000Z","dependencies_parsed_at":"2023-11-08T01:29:45.490Z","dependency_job_id":"34e5c9ee-d4ff-46b3-a068-3f48a0fd2999","html_url":"https://github.com/danielost/sha-1","commit_stats":null,"previous_names":["danielost/sha-1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielost%2Fsha-1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielost%2Fsha-1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielost%2Fsha-1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielost%2Fsha-1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielost","download_url":"https://codeload.github.com/danielost/sha-1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253980063,"owners_count":21994043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","secure-hash-algorithm","sha-1"],"created_at":"2025-02-16T19:48:09.303Z","updated_at":"2025-05-13T16:13:55.101Z","avatar_url":"https://github.com/danielost.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SHA-1 (Secure Hash Algorithm 1)\n\nSHA-1 implementation in Golang. Task №5 for the Cryptography for Developers course.\n\nRef: https://en.wikipedia.org/wiki/SHA-1\n\n## How to use\n\nTo use this SHA-1 implementation, execute the following command first:\n```bash\ngo get github.com/danielost/sha-1\n```\nThen simply add the following import to your Go code:\n```golang\nimport (\n\t// Importing the SHA-1 package\n\tsha1 \"github.com/danielost/sha-1\"\n)\n```\nNow it's possible to use the `Sum([]byte) []byte` function, which takes a byte array of an arbitrary length and returns a fixed-size message digest:\n```golang\n// The message for which we want to calculate the SHA-1 hash\nmsg := \"Cats control the outer ear using 32 muscles; humans use 6\"\n\n// Calculate the SHA-1 hash of the message.\n// Sum is represented as a byte array of length 20 (160 bits)\nmsgDigest := sha1.Sum([]byte(msg))\n```\n\u003e The fact that the function takes a byte array as an input means it's possible to hash any data, from text to audio or video files.\n\nFull block of code, that follows the above steps:\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t// Importing the SHA-1 package\n\tsha1 \"github.com/danielost/sha-1\"\n)\n\nfunc main() {\n\t// The message for which we want to calculate the SHA-1 hash\n\tmsg := \"Cats control the outer ear using 32 muscles; humans use 6\"\n\n\t// Calculate the SHA-1 hash of the message.\n\t// Sum is represented as a byte array of length 20 (160 bits)\n\tmsgDigest := sha1.Sum([]byte(msg))\n\n\t// Print the resulting hash in hexadecimal format\n\tfmt.Printf(\"%x\\n\", msgDigest)\n}\n\n```\n\n## Running tests and benchmarks\n\n**1. Tests:**\n\nThe tests are located in `./hash_test.go`. The same input is hashed using this SHA-1 implementation and the [built-in SHA-1](https://pkg.go.dev/crypto/sha1). Then their outputs are compared. The test data set contains some hardcoded values as well as 10000 randomly generated sequences.\n\nTo run the tests, clone the repository and execute the following command:\n```bash\ngo test .\n```\nIf the program works correctly, the output will look as follows:\n```bash\nok      github.com/danielost/sha-1      4.558s\n```\n\n**2. Benchmarks**\n\nBenchmarks were added to compare the execution time of two implementations.\nTo run the benchmark, clone the repository and execute the following command:\n```bash\ngo test -bench=.\n```\nThis command actually runs both the tests and benchmarks, so there is no need to run the tests separately if you are interested in running everything.\n\nThe output of the above command should look like this:\n```bash\ngoos: linux\ngoarch: amd64\npkg: github.com/danielost/sha-1\ncpu: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz\nBenchmarkCustomSha1_2000-2     \t   14986\t     77941 ns/op\nBenchmarkBuiltinSha1_2000-2    \t   19896\t     59004 ns/op\nBenchmarkCustomSha1_20000-2    \t    1592\t    749419 ns/op\nBenchmarkBuiltinSha1_20000-2   \t    1970\t    589291 ns/op\nPASS\nok  \tgithub.com/danielost/sha-1\t13.375s\n```\n\nThe built-in implementation  is slightly faster as it uses additional optimizations.\n\n**Benchmark results can be found in the `Actions` tab of the repository.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielost%2Fsha-1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielost%2Fsha-1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielost%2Fsha-1/lists"}