{"id":15146903,"url":"https://github.com/equim-chan/cryptonight","last_synced_at":"2025-10-25T05:32:01.507Z","repository":{"id":57486871,"uuid":"145248751","full_name":"Equim-chan/cryptonight","owner":"Equim-chan","description":":loop: Pure Go/ASM implementation of CryptoNight hash function with its variants, without any CGO binding.","archived":false,"fork":false,"pushed_at":"2020-02-02T11:24:16.000Z","size":282,"stargazers_count":80,"open_issues_count":2,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-10T01:04:53.737Z","etag":null,"topics":["cryptonight","hash","mining","monero","pow"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Equim-chan.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-18T19:54:42.000Z","updated_at":"2024-09-22T06:38:26.000Z","dependencies_parsed_at":"2022-09-01T23:00:57.092Z","dependency_job_id":null,"html_url":"https://github.com/Equim-chan/cryptonight","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fcryptonight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fcryptonight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fcryptonight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fcryptonight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Equim-chan","download_url":"https://codeload.github.com/Equim-chan/cryptonight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867198,"owners_count":16555821,"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":["cryptonight","hash","mining","monero","pow"],"created_at":"2024-09-26T12:20:30.884Z","updated_at":"2025-10-24T01:31:14.112Z","avatar_url":"https://github.com/Equim-chan.png","language":"Go","readme":"= cryptonight\nEquim \u003chttps://github.com/Equim-chan[@Equim-chan]\u003e\n\nimage:http://img.shields.io/badge/godoc-reference-5272B4.svg[GoDoc, link=https://godoc.org/ekyu.moe/cryptonight]\nimage:https://img.shields.io/github/tag/Equim-chan/cryptonight.svg[tag, link=https://github.com/Equim-chan/cryptonight/tags]\nimage:https://img.shields.io/circleci/project/github/Equim-chan/cryptonight.svg[CircleCI, link=https://circleci.com/gh/Equim-chan/cryptonight]\nimage:https://img.shields.io/codecov/c/github/Equim-chan/cryptonight.svg[Codecov, link=https://codecov.io/github/Equim-chan/cryptonight]\nimage:https://goreportcard.com/badge/github.com/Equim-chan/cryptonight[Go Report Card, link=https://goreportcard.com/report/github.com/Equim-chan/cryptonight]\nimage:https://img.shields.io/github/license/Equim-chan/cryptonight.svg[License, link=https://github.com/Equim-chan/cryptonight/blob/master/LICENSE]\n\nPure Go/ASM implementation of CryptoNight hash function and some of its variant, without any CGO binding.\n\n== Features\n* Support v0, v1, v2 variants.\n* No CGO hell, making builds easier and faster.\n* Hardware acceleration available for amd64 architecture.\n* Use of an internal sync.Pool to manage caches, since it is memory hard.\n\n== Install\n[source,shell]\n----\n$ go get -u ekyu.moe/cryptonight\n----\n\nA simple CLI utility is also available with `go get -u ekyu.moe/cryptonight/cmd/cnhash`.\n\n[source,plain]\n----\nUsage of cnhash:\n  -bench\n        Benchmark mode, don't do anything else.\n  -in-file string\n        Read input from file instead of stdin.\n  -in-hex\n        Read input in hex instead of binary.\n  -include-diff\n        Append the difficulty of the result hash to the output. If -out-binary is not given,\nthe difficulty will be appeneded to the output in decimal with comma separated (CSV friendly)\n, otherwise it will be appeneded to the hash binary (which is 32 bytes long) directly, in 8\nbytes little endian.\n  -out-binary\n        Produce output in binary (little endian) instead of hex.\n  -out-file string\n        Produce output to file instead of stdout.\n  -variant int\n        Set CryptoNight variant, default 0. This applies to benchmark mode as well.\n----\n\n== Example\n[source,go]\n----\npackage main\n\nimport (\n    \"fmt\"\n\n    \"ekyu.moe/cryptonight\"\n)\n\nfunc main() {\n    blob := []byte(\"Hello, 世界\")\n    fmt.Printf(\"%x\\n\", cryptonight.Sum(blob, 0)) // original\n    // Output: 0999794e4e20d86e6a81b54495aeb370b6a9ae795fb5af4f778afaf07c0b2e0e\n\n    blob = []byte(\"variant 1 requires at least 43 bytes of input.\")\n    fmt.Printf(\"%x\\n\", cryptonight.Sum(blob, 1)) // variant 1\n    // Output: 261124c5a6dca5d4aa3667d328a94ead9a819ae714e1f1dc113ceeb14f1ecf99\n\n    blob = []byte(\"Monero is cash for a connected world. It’s fast, private, and secure.\")\n    fmt.Printf(\"%x\\n\", cryptonight.Sum(blob, 2)) // variant 2\n    // Output: abb61f40468c70234051e4bb5e8b670812473b2a71e02c9633ef94996a621b96\n}\n----\n\n== Tested architectures\n* amd64 _(w/ AVX, SSE, AES)_\n* amd64 _(w/o AVX, SSE, AES)_\n* 386\n* arm64\n\n== Benchmarks\nCPU: 4 x Intel(R) Xeon(R) CPU E3-1270 v3 @ 3.50GHz\n\n[source,plain]\n----\ngoos: linux\ngoarch: amd64\npkg: ekyu.moe/cryptonight\nBenchmarkSum/v0-4            100   20208070 ns/op   21584 B/op   2 allocs/op\nBenchmarkSum/v1-4            100   20535318 ns/op   21584 B/op   2 allocs/op\nBenchmarkSum/v2-4            100   22328893 ns/op   21584 B/op   2 allocs/op\nBenchmarkSum/v0-parallel-4   100   10798945 ns/op   42664 B/op   2 allocs/op\nBenchmarkSum/v1-parallel-4   100   10316040 ns/op   42655 B/op   2 allocs/op\nBenchmarkSum/v2-parallel-4   100   11740615 ns/op   42661 B/op   2 allocs/op\nPASS\n----\n\n== Development\nWhile this repository is already out-of-box, which means what you need to do to use it in your code is just a `go get` (or `dep ensure -add` whatsoever), in case you want to hack on this library, some additional steps are required since it uses code generation.\n\n=== Preprocess\nIf you modified a source file in this library that uses C-kind macros (the comments tells), in order to expand them and generate the final code, https://linux.die.net/man/1/cpp[cpp(1)] is needed, which a part of GCC toolchain and should be already available if you have installed gcc (or MinGW for Windows) in your machine.\n\nOnce some modification is made in a file that used macro, simply use `go generate ekyu.moe/cryptonight/\\...` to run the gcc preprocessor on them.\n\n=== Packages information\n``ekyu.moe/cryptonight/internal/aes``:: From Go's crypto/aes. Since CryptoNight's use of AES is quite non-standard and not intended for encryption, you must use this package this package with care for project that's not CryptoNight associated.\n\n``ekyu.moe/cryptonight/internal/sha3``:: From Go's golang.org/x/crypto/sha3. All CryptoNight specific additional works are made in `cn.go` only; other files are untouched at all.\n\n``ekyu.moe/cryptonight/groestl``:: Grøstl-256 implementation. It is directly ported from C and not quite optimized.\n\n``ekyu.moe/cryptonight/jh``:: JH-256 implementation. It is directly ported from C and not quite optimized.\n\n=== Tests, coverage and benchmarks\n[source,shell]\n----\n$ go test -v -race -coverprofile=coverage.txt -covermode=atomic\n$ go tool cover -html=coverage.txt\n$ go test -v -run=^$ -bench=. -benchmem\n----\n\n=== TODO\n* [ ] ARM64-specific optimization\n* [x] Tests on other architectures\n* [x] Improve performance for variant 2\n* [ ] Improve performance for groestl and jh\n* [x] Try a nearly full assembly implementation (except for the final hash) for amd64\n\n== References\n* https://cryptonote.org/cns/cns008.txt[CryptoNote Standard 008 - CryptoNight Hash Function]\n* https://github.com/monero-project/monero/pull/3253[Variant 1]\n* https://github.com/monero-project/monero/pull/4218[Variant 2]\n\n== Donation\nIf you find this lib helpful, maybe consider buying me a cup of coffee at\n\nXMR:: `4777777jHFbZB4gyqrB1JHDtrGFusyj4b3M2nScYDPKEM133ng2QDrK9ycqizXS2XofADw5do5rU19LQmpTGCfeQTerm1Ti`\nBTC:: `1Eqqqq9xR78wJyRXXgvR73HEfKdEwq68BT`\n\nMuch thanks.\n\n== License\nhttps://github.com/Equim-chan/cryptonight/blob/master/LICENSE[MIT]\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequim-chan%2Fcryptonight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fequim-chan%2Fcryptonight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequim-chan%2Fcryptonight/lists"}