├── .github └── workflows │ └── node.js.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── README.md ├── appveyor.yml ├── binding.gyp ├── index.js ├── package-lock.json ├── package.json ├── src ├── bcrypt.c ├── bcrypt.h ├── blake.c ├── blake.h ├── boolberry.cc ├── boolberry.h ├── c11.c ├── c11.h ├── crypto │ ├── aesb.c │ ├── argon2 │ │ ├── argon2.c │ │ ├── argon2.h │ │ ├── blake2 │ │ │ ├── blake2-impl.h │ │ │ ├── blake2.h │ │ │ ├── blake2b.c │ │ │ └── blamka-round-opt.h │ │ ├── core.c │ │ ├── core.h │ │ ├── encoding.c │ │ ├── encoding.h │ │ ├── opt.c │ │ ├── thread.c │ │ └── thread.h │ ├── c_blake256.c │ ├── c_blake256.h │ ├── c_groestl.c │ ├── c_groestl.h │ ├── c_jh.c │ ├── c_jh.h │ ├── c_keccak.c │ ├── c_keccak.h │ ├── c_skein.c │ ├── c_skein.h │ ├── crypto.h │ ├── cryptonote_core │ │ ├── account.cpp │ │ ├── account.h │ │ ├── cryptonote_basic_impl.cpp │ │ ├── cryptonote_basic_impl.h │ │ ├── cryptonote_format_utils.cpp │ │ └── cryptonote_format_utils.h │ ├── cryptonote_protocol │ │ └── cryptonote_protocol_defs.h │ ├── groestl_tables.h │ ├── hash-ops.h │ ├── hash.c │ ├── hash.h │ ├── int-util.h │ ├── lyra2.c │ ├── lyra2.h │ ├── oaes_config.h │ ├── oaes_lib.c │ ├── oaes_lib.h │ ├── sha256.c │ ├── sha256.h │ ├── skein_port.h │ ├── sponge.c │ ├── sponge.h │ ├── variant2_int_sqrt.h │ ├── variant4_random_math.h │ ├── wild_keccak.cpp │ ├── wild_keccak.h │ └── yescrypt │ │ ├── yescrypt-best.c │ │ ├── yescrypt-opt.c │ │ ├── yescrypt-platform.c │ │ ├── yescrypt-simd.c │ │ ├── yescrypt.h │ │ └── yescryptcommon.c ├── cryptonight.c ├── cryptonight.h ├── cryptonight_fast.c ├── cryptonight_fast.h ├── fresh.c ├── fresh.h ├── fugue.c ├── fugue.h ├── groestl.c ├── groestl.h ├── hefty1.c ├── hefty1.h ├── keccak.c ├── keccak.h ├── lbry.c ├── lbry.h ├── lyra2re.c ├── lyra2re.h ├── lyra2z.c ├── lyra2z.h ├── multihashing.cc ├── neoscrypt.c ├── neoscrypt.h ├── nist5.c ├── nist5.h ├── quark.c ├── quark.h ├── qubit.c ├── qubit.h ├── scryptjane.c ├── scryptjane.h ├── scryptjane │ ├── scrypt-jane-chacha.h │ ├── scrypt-jane-hash.h │ ├── scrypt-jane-hash_keccak.h │ ├── scrypt-jane-hash_sha256.h │ ├── scrypt-jane-mix_chacha-avx.h │ ├── scrypt-jane-mix_chacha-sse2.h │ ├── scrypt-jane-mix_chacha-ssse3.h │ ├── scrypt-jane-mix_chacha.h │ ├── scrypt-jane-mix_salsa-avx.h │ ├── scrypt-jane-mix_salsa-sse2.h │ ├── scrypt-jane-mix_salsa.h │ ├── scrypt-jane-mix_salsa64-avx.h │ ├── scrypt-jane-mix_salsa64-sse2.h │ ├── scrypt-jane-mix_salsa64-ssse3.h │ ├── scrypt-jane-mix_salsa64.h │ ├── scrypt-jane-pbkdf2.h │ ├── scrypt-jane-portable-x86.h │ ├── scrypt-jane-portable.h │ ├── scrypt-jane-romix-basic.h │ ├── scrypt-jane-romix-template.h │ ├── scrypt-jane-romix.h │ ├── scrypt-jane-salsa.h │ ├── scrypt-jane-salsa64.h │ └── scrypt-jane-test-vectors.h ├── scryptn.c ├── scryptn.h ├── sha1.c ├── sha1.h ├── sha256d.c ├── sha256d.h ├── sha3 │ ├── aes_helper.c │ ├── hamsi.c │ ├── hamsi_helper.c │ ├── md_helper.c │ ├── sph_blake.c │ ├── sph_blake.h │ ├── sph_bmw.c │ ├── sph_bmw.h │ ├── sph_cubehash.c │ ├── sph_cubehash.h │ ├── sph_echo.c │ ├── sph_echo.h │ ├── sph_fugue.c │ ├── sph_fugue.h │ ├── sph_groestl.c │ ├── sph_groestl.h │ ├── sph_hamsi.h │ ├── sph_hefty1.c │ ├── sph_hefty1.h │ ├── sph_jh.c │ ├── sph_jh.h │ ├── sph_keccak.c │ ├── sph_keccak.h │ ├── sph_luffa.c │ ├── sph_luffa.h │ ├── sph_ripemd.c │ ├── sph_ripemd.h │ ├── sph_sha1.c │ ├── sph_sha1.h │ ├── sph_sha2.c │ ├── sph_sha2.h │ ├── sph_sha2big.c │ ├── sph_shabal.c │ ├── sph_shabal.h │ ├── sph_shavite.c │ ├── sph_shavite.h │ ├── sph_simd.c │ ├── sph_simd.h │ ├── sph_skein.c │ ├── sph_skein.h │ ├── sph_tiger.c │ ├── sph_tiger.h │ ├── sph_types.h │ ├── sph_whirlpool.c │ └── sph_whirlpool.h ├── shavite3.c ├── shavite3.h ├── skein.c ├── skein.h ├── stdint.h ├── x11.c ├── x11.h ├── x13.c ├── x13.h ├── x15.c ├── x15.h ├── x16r.c ├── x16r.h ├── x16rv2.c └── x16rv2.h └── tests ├── cryptonight_monero.js ├── test.vectors.js └── vectors ├── input.json.in ├── set1-input.json ├── set1.json ├── set2-input.json ├── set2.json ├── set3-input.json └── set3.json /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | name: Node.js CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build-legacy: 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | node-version: [0.10.x, 4.x, 6.x] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Use Node.js ${{ matrix.node-version }} 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | - run: npm i 25 | 26 | test: 27 | runs-on: ${{ matrix.os }} 28 | 29 | strategy: 30 | matrix: 31 | os: [ubuntu-latest, macos-latest, windows-2019] 32 | node-version: [8.x, 12.x, 14.x, 16.x] 33 | 34 | steps: 35 | - uses: actions/checkout@v2 36 | - name: Use Node.js ${{ matrix.node-version }} 37 | uses: actions/setup-node@v1 38 | with: 39 | node-version: ${{ matrix.node-version }} 40 | - run: npm i 41 | - run: npm test 42 | env: 43 | SETS: set3 44 | 45 | publish: 46 | runs-on: ubuntu-latest 47 | needs: 48 | - build-legacy 49 | - test 50 | steps: 51 | - uses: actions/checkout@v2 52 | - name: Install dependencies 53 | run: npm ci 54 | - name: Semantic Release 55 | uses: cycjimmy/semantic-release-action@v2 56 | env: 57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 58 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 59 | with: 60 | extra_plugins: | 61 | @semantic-release/changelog 62 | @semantic-release/git 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | - '4' 5 | - '5' 6 | - '6' 7 | - '7' 8 | - '8' 9 | - '9' 10 | deploy: 11 | provider: npm 12 | email: zone117x@gmail.com 13 | api_key: 14 | secure: D9lpUDAx1OudPBji3mapnAhOug3wcEBqFrNgWaFh5XiYesa/f/X0gMOJggLlvzyhLHKs8VdTHShdu3XzlC3EDwr5wCdgYO1JSOyDo93FG7Y/qhPDVFnzdtsKmr813Qtj2UDKIh2ZP+JnjKaITrvUwRmdi/8+B9Enr5o9ulFb/a0= -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.0.2](https://github.com/zone117x/node-multi-hashing/compare/v1.0.1...v1.0.2) (2022-03-10) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * nodejs v16.x support ([#100](https://github.com/zone117x/node-multi-hashing/issues/100)) ([927e960](https://github.com/zone117x/node-multi-hashing/commit/927e9600d05cc734ca21ffcbc0a10d166bb4a66f)) 7 | 8 | ## [1.0.1](https://github.com/zone117x/node-multi-hashing/compare/v1.0.0...v1.0.1) (2021-07-15) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * DEP0128 DeprecationWarning: Invalid 'main' field ([27dd90e](https://github.com/zone117x/node-multi-hashing/commit/27dd90e7476e71774bea5b50888f4df8d3b604a3)) 14 | 15 | # 1.0.0 (2020-08-26) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * building on macos ([951ba10](https://github.com/zone117x/node-multi-hashing/commit/951ba106e234ca99d2b78a0f9b2881fb3f90c81c)) 21 | * bump test timeout ([9dc7dab](https://github.com/zone117x/node-multi-hashing/commit/9dc7dab38186c35723e57d3625ccdef1a13daea6)) 22 | * run gh actions on all branches ([1aa6f9e](https://github.com/zone117x/node-multi-hashing/commit/1aa6f9e8f938cba71ee82722abe593d799b15be8)) 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-multi-hashing 2 | =============== 3 | 4 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/zone117x/node-multi-hashing/Node.js%20CI)](https://github.com/zone117x/node-multi-hashing/actions) [![npm](https://img.shields.io/npm/v/multi-hashing)](https://www.npmjs.com/package/multi-hashing) 5 | 6 | Cryptocurrency hashing functions for node.js. 7 | 8 | 9 | Algorithms 10 | ---------- 11 | Supported algorithms: `quark, x11, x13, x16r, x16rv2, nist5, scrypt, scryptn, scryptjane, keccak, bcrypt, skein, groestl, blake, fugue, qubit, hefty1, shavite3, cryptonight, boolberry, sha256d, lbry`, *__and more!__* 12 | 13 | 14 | Usage 15 | ----- 16 | 17 | Install 18 | 19 | ```bash 20 | npm install multi-hashing 21 | ``` 22 | 23 | Example usage: 24 | 25 | ```javascript 26 | var multiHashing = require('multi-hashing'); 27 | 28 | var algorithms = ['quark', 'x11', 'scrypt', 'scryptn', 'keccak', 'bcrypt', 'skein', 'blake']; 29 | 30 | var data = new Buffer("7000000001e980924e4e1109230383e66d62945ff8e749903bea4336755c00000000000051928aff1b4d72416173a8c3948159a09a73ac3bb556aa6bfbcad1a85da7f4c1d13350531e24031b939b9e2b", "hex"); 31 | 32 | var hashedData = algorithms.map(function(algo){ 33 | return multiHashing[algo](data); 34 | }); 35 | 36 | 37 | console.log(hashedData); 38 | // 39 | 40 | 41 | ``` 42 | 43 | Credits 44 | ------- 45 | * [NSA](http://www.nsa.gov/) and [NIST](http://www.nist.gov/) for creation or sponsoring creation of SHA2 and SHA3 algos 46 | * [Keccak](http://en.wikipedia.org/wiki/Keccak) - Guido Bertoni, Joan Daemen, Michaël Peeters, and Gilles Van Assche 47 | * [Skein](http://en.wikipedia.org/wiki/Skein_(hash_function)) - Bruce Schneier, Stefan Lucks, Niels Ferguson, Doug Whiting, Mihir Bellare, Tadayoshi Kohno, Jon Callas and Jesse Walker. 48 | * [BLAKE](http://en.wikipedia.org/wiki/BLAKE_(hash_function)) - Jean-Philippe Aumasson, Luca Henzen, Willi Meier, and Raphael C.-W. Phan 49 | * [Grøstl](http://en.wikipedia.org/wiki/Gr%C3%B8stl) - Praveen Gauravaram, Lars Knudsen, Krystian Matusiewicz, Florian Mendel, Christian Rechberger, Martin Schläffer, and Søren S. Thomsen 50 | * [JH](http://en.wikipedia.org/wiki/JH_(hash_function)) - Hongjun Wu 51 | * [Fugue](http://en.wikipedia.org/wiki/Fugue_(hash_function)) - Shai Halevi, William E. Hall, and Charanjit S. Jutla 52 | * [scrypt](http://en.wikipedia.org/wiki/Scrypt) - Colin Percival 53 | * [bcrypt](http://en.wikipedia.org/wiki/Bcrypt) - Niels Provos and David Mazières 54 | * [X11](http://www.darkcoin.io/), [Hefty1](http://heavycoin.github.io/about.html), [Quark](http://www.qrk.cc/) creators (they just mixed together a bunch of the above algos) 55 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2017 2 | platform: x64 3 | 4 | environment: 5 | matrix: 6 | - nodejs_version: "10" 7 | 8 | # Install scripts. 9 | install: 10 | # Get the latest stable version of Node.js or io.js 11 | - ps: Install-Product node $env:nodejs_version 12 | 13 | # install modules 14 | - npm install 15 | - npm run test 16 | 17 | # Post-install test scripts. 18 | test_script: 19 | # Output useful info for debugging. 20 | - node --version 21 | - npm --version 22 | 23 | # Don't actually build. 24 | build: off 25 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "multihashing", 5 | "sources": [ 6 | "src/multihashing.cc", 7 | "src/bcrypt.c", 8 | "src/blake.c", 9 | "src/boolberry.cc", 10 | "src/c11.c", 11 | "src/cryptonight.c", 12 | "src/cryptonight_fast.c", 13 | "src/fresh.c", 14 | "src/fugue.c", 15 | "src/groestl.c", 16 | "src/hefty1.c", 17 | "src/keccak.c", 18 | "src/lbry.c", 19 | "src/lyra2re.c", 20 | "src/lyra2z.c", 21 | "src/nist5.c", 22 | "src/quark.c", 23 | "src/qubit.c", 24 | "src/scryptjane.c", 25 | "src/scryptn.c", 26 | "src/sha1.c", 27 | "src/sha256d.c", 28 | "src/shavite3.c", 29 | "src/skein.c", 30 | "src/x11.c", 31 | "src/x13.c", 32 | "src/x15.c", 33 | "src/x16r.c", 34 | "src/x16rv2.c", 35 | "src/crypto/argon2/argon2.c", 36 | "src/crypto/argon2/core.c", 37 | "src/crypto/argon2/encoding.c", 38 | "src/crypto/argon2/opt.c", 39 | "src/crypto/argon2/thread.c", 40 | "src/crypto/argon2/blake2/blake2b.c", 41 | "src/sha3/sph_hefty1.c", 42 | "src/sha3/sph_fugue.c", 43 | "src/sha3/aes_helper.c", 44 | "src/sha3/sph_blake.c", 45 | "src/sha3/sph_bmw.c", 46 | "src/sha3/sph_cubehash.c", 47 | "src/sha3/sph_echo.c", 48 | "src/sha3/sph_groestl.c", 49 | "src/sha3/sph_jh.c", 50 | "src/sha3/sph_keccak.c", 51 | "src/sha3/sph_luffa.c", 52 | "src/sha3/sph_shavite.c", 53 | "src/sha3/sph_simd.c", 54 | "src/sha3/sph_skein.c", 55 | "src/sha3/sph_whirlpool.c", 56 | "src/sha3/sph_shabal.c", 57 | "src/sha3/sph_ripemd.c", 58 | "src/sha3/sph_sha1.c", 59 | "src/sha3/sph_sha2.c", 60 | "src/sha3/sph_sha2big.c", 61 | "src/sha3/sph_tiger.c", 62 | "src/sha3/hamsi.c", 63 | "src/crypto/lyra2.c", 64 | "src/crypto/sponge.c", 65 | "src/crypto/oaes_lib.c", 66 | "src/crypto/c_keccak.c", 67 | "src/crypto/c_groestl.c", 68 | "src/crypto/c_blake256.c", 69 | "src/crypto/c_jh.c", 70 | "src/crypto/c_skein.c", 71 | "src/crypto/hash.c", 72 | "src/crypto/aesb.c", 73 | "src/crypto/sha256.c", 74 | "src/crypto/wild_keccak.cpp", 75 | "src/neoscrypt.c", 76 | "src/crypto/yescrypt/yescrypt-best.c", 77 | "src/crypto/yescrypt/yescryptcommon.c", 78 | ], 79 | "include_dirs": [ 80 | "src/crypto", 81 | " 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | 9 | 10 | void blake_hash(const char* input, char* output, uint32_t len) 11 | { 12 | sph_blake256_context ctx_blake; 13 | sph_blake256_set_rounds(8); 14 | sph_blake256_init(&ctx_blake); 15 | sph_blake256(&ctx_blake, input, len); 16 | sph_blake256_close(&ctx_blake, output); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/blake.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE_H 2 | #define BLAKE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void blake_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/boolberry.cc: -------------------------------------------------------------------------------- 1 | #include "boolberry.h" 2 | #include "crypto/cryptonote_core/cryptonote_format_utils.h" 3 | 4 | #include 5 | 6 | void boolberry_hash(const char* input, uint32_t input_len, const char* scratchpad, uint64_t spad_length, char* output, uint64_t height) { 7 | crypto::hash* spad = (crypto::hash*) scratchpad; 8 | cryptonote::get_blob_longhash_bb(std::string(input, input_len), *((crypto::hash*)output), height, [&](uint64_t index) -> crypto::hash& { 9 | return spad[index%(spad_length / HASH_SIZE)]; 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /src/boolberry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | void boolberry_hash(const char* input, uint32_t input_len, const char* scratchpad, uint64_t spad_length, char* output, uint64_t height); 7 | -------------------------------------------------------------------------------- /src/c11.c: -------------------------------------------------------------------------------- 1 | #include "c11.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_bmw.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_jh.h" 11 | #include "sha3/sph_keccak.h" 12 | #include "sha3/sph_skein.h" 13 | #include "sha3/sph_luffa.h" 14 | #include "sha3/sph_cubehash.h" 15 | #include "sha3/sph_shavite.h" 16 | #include "sha3/sph_simd.h" 17 | #include "sha3/sph_echo.h" 18 | 19 | 20 | void c11_hash(const char* input, char* output, uint32_t len) 21 | { 22 | sph_blake512_context ctx_blake; 23 | sph_bmw512_context ctx_bmw; 24 | sph_groestl512_context ctx_groestl; 25 | sph_skein512_context ctx_skein; 26 | sph_jh512_context ctx_jh; 27 | sph_keccak512_context ctx_keccak; 28 | 29 | sph_luffa512_context ctx_luffa1; 30 | sph_cubehash512_context ctx_cubehash1; 31 | sph_shavite512_context ctx_shavite1; 32 | sph_simd512_context ctx_simd1; 33 | sph_echo512_context ctx_echo1; 34 | 35 | //these uint512 in the c++ source of the client are backed by an array of uint32 36 | uint32_t hashA[16], hashB[16]; 37 | 38 | sph_blake512_init(&ctx_blake); 39 | sph_blake512 (&ctx_blake, input, len); 40 | sph_blake512_close (&ctx_blake, hashA); 41 | 42 | sph_bmw512_init(&ctx_bmw); 43 | sph_bmw512 (&ctx_bmw, hashA, 64); 44 | sph_bmw512_close(&ctx_bmw, hashB); 45 | 46 | sph_groestl512_init(&ctx_groestl); 47 | sph_groestl512 (&ctx_groestl, hashB, 64); 48 | sph_groestl512_close(&ctx_groestl, hashA); 49 | 50 | sph_jh512_init(&ctx_jh); 51 | sph_jh512 (&ctx_jh, hashA, 64); 52 | sph_jh512_close(&ctx_jh, hashB); 53 | 54 | sph_keccak512_init(&ctx_keccak); 55 | sph_keccak512 (&ctx_keccak, hashB, 64); 56 | sph_keccak512_close(&ctx_keccak, hashA); 57 | 58 | sph_skein512_init(&ctx_skein); 59 | sph_skein512 (&ctx_skein, hashA, 64); 60 | sph_skein512_close (&ctx_skein, hashB); 61 | 62 | sph_luffa512_init (&ctx_luffa1); 63 | sph_luffa512 (&ctx_luffa1, hashB, 64); 64 | sph_luffa512_close (&ctx_luffa1, hashA); 65 | 66 | sph_cubehash512_init (&ctx_cubehash1); 67 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 68 | sph_cubehash512_close(&ctx_cubehash1, hashB); 69 | 70 | sph_shavite512_init (&ctx_shavite1); 71 | sph_shavite512 (&ctx_shavite1, hashB, 64); 72 | sph_shavite512_close(&ctx_shavite1, hashA); 73 | 74 | sph_simd512_init (&ctx_simd1); 75 | sph_simd512 (&ctx_simd1, hashA, 64); 76 | sph_simd512_close(&ctx_simd1, hashB); 77 | 78 | sph_echo512_init (&ctx_echo1); 79 | sph_echo512 (&ctx_echo1, hashB, 64); 80 | sph_echo512_close(&ctx_echo1, hashA); 81 | 82 | memcpy(output, hashA, 32); 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/c11.h: -------------------------------------------------------------------------------- 1 | #ifndef C11_H 2 | #define C11_H 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include 10 | 11 | void c11_hash(const char* input, char* output, uint32_t len); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif // C11_H 18 | -------------------------------------------------------------------------------- /src/crypto/argon2/blake2/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef PORTABLE_BLAKE2_IMPL_H 19 | #define PORTABLE_BLAKE2_IMPL_H 20 | 21 | #include 22 | #include 23 | 24 | #if defined(_MSC_VER) 25 | #define BLAKE2_INLINE __inline 26 | #elif defined(__GNUC__) || defined(__clang__) 27 | #define BLAKE2_INLINE __inline__ 28 | #else 29 | #define BLAKE2_INLINE 30 | #endif 31 | 32 | /* Argon2 Team - Begin Code */ 33 | /* 34 | Not an exhaustive list, but should cover the majority of modern platforms 35 | Additionally, the code will always be correct---this is only a performance 36 | tweak. 37 | */ 38 | #if (defined(__BYTE_ORDER__) && \ 39 | (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \ 40 | defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__MIPSEL__) || \ 41 | defined(__AARCH64EL__) || defined(__amd64__) || defined(__i386__) || \ 42 | defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \ 43 | defined(_M_ARM) 44 | #define NATIVE_LITTLE_ENDIAN 45 | #endif 46 | /* Argon2 Team - End Code */ 47 | 48 | static BLAKE2_INLINE uint32_t load32(const void *src) { 49 | #if defined(NATIVE_LITTLE_ENDIAN) 50 | uint32_t w; 51 | memcpy(&w, src, sizeof w); 52 | return w; 53 | #else 54 | const uint8_t *p = (const uint8_t *)src; 55 | uint32_t w = *p++; 56 | w |= (uint32_t)(*p++) << 8; 57 | w |= (uint32_t)(*p++) << 16; 58 | w |= (uint32_t)(*p++) << 24; 59 | return w; 60 | #endif 61 | } 62 | 63 | static BLAKE2_INLINE uint64_t load64(const void *src) { 64 | #if defined(NATIVE_LITTLE_ENDIAN) 65 | uint64_t w; 66 | memcpy(&w, src, sizeof w); 67 | return w; 68 | #else 69 | const uint8_t *p = (const uint8_t *)src; 70 | uint64_t w = *p++; 71 | w |= (uint64_t)(*p++) << 8; 72 | w |= (uint64_t)(*p++) << 16; 73 | w |= (uint64_t)(*p++) << 24; 74 | w |= (uint64_t)(*p++) << 32; 75 | w |= (uint64_t)(*p++) << 40; 76 | w |= (uint64_t)(*p++) << 48; 77 | w |= (uint64_t)(*p++) << 56; 78 | return w; 79 | #endif 80 | } 81 | 82 | static BLAKE2_INLINE void store32(void *dst, uint32_t w) { 83 | #if defined(NATIVE_LITTLE_ENDIAN) 84 | memcpy(dst, &w, sizeof w); 85 | #else 86 | uint8_t *p = (uint8_t *)dst; 87 | *p++ = (uint8_t)w; 88 | w >>= 8; 89 | *p++ = (uint8_t)w; 90 | w >>= 8; 91 | *p++ = (uint8_t)w; 92 | w >>= 8; 93 | *p++ = (uint8_t)w; 94 | #endif 95 | } 96 | 97 | static BLAKE2_INLINE void store64(void *dst, uint64_t w) { 98 | #if defined(NATIVE_LITTLE_ENDIAN) 99 | memcpy(dst, &w, sizeof w); 100 | #else 101 | uint8_t *p = (uint8_t *)dst; 102 | *p++ = (uint8_t)w; 103 | w >>= 8; 104 | *p++ = (uint8_t)w; 105 | w >>= 8; 106 | *p++ = (uint8_t)w; 107 | w >>= 8; 108 | *p++ = (uint8_t)w; 109 | w >>= 8; 110 | *p++ = (uint8_t)w; 111 | w >>= 8; 112 | *p++ = (uint8_t)w; 113 | w >>= 8; 114 | *p++ = (uint8_t)w; 115 | w >>= 8; 116 | *p++ = (uint8_t)w; 117 | #endif 118 | } 119 | 120 | static BLAKE2_INLINE uint64_t load48(const void *src) { 121 | const uint8_t *p = (const uint8_t *)src; 122 | uint64_t w = *p++; 123 | w |= (uint64_t)(*p++) << 8; 124 | w |= (uint64_t)(*p++) << 16; 125 | w |= (uint64_t)(*p++) << 24; 126 | w |= (uint64_t)(*p++) << 32; 127 | w |= (uint64_t)(*p++) << 40; 128 | return w; 129 | } 130 | 131 | static BLAKE2_INLINE void store48(void *dst, uint64_t w) { 132 | uint8_t *p = (uint8_t *)dst; 133 | *p++ = (uint8_t)w; 134 | w >>= 8; 135 | *p++ = (uint8_t)w; 136 | w >>= 8; 137 | *p++ = (uint8_t)w; 138 | w >>= 8; 139 | *p++ = (uint8_t)w; 140 | w >>= 8; 141 | *p++ = (uint8_t)w; 142 | w >>= 8; 143 | *p++ = (uint8_t)w; 144 | } 145 | 146 | static BLAKE2_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) { 147 | return (w >> c) | (w << (32 - c)); 148 | } 149 | 150 | static BLAKE2_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) { 151 | return (w >> c) | (w << (64 - c)); 152 | } 153 | 154 | void clear_internal_memory(void *v, size_t n); 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /src/crypto/argon2/blake2/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef PORTABLE_BLAKE2_H 19 | #define PORTABLE_BLAKE2_H 20 | 21 | #include "../argon2.h" 22 | 23 | #if defined(__cplusplus) 24 | extern "C" { 25 | #endif 26 | 27 | enum blake2b_constant { 28 | BLAKE2B_BLOCKBYTES = 128, 29 | BLAKE2B_OUTBYTES = 64, 30 | BLAKE2B_KEYBYTES = 64, 31 | BLAKE2B_SALTBYTES = 16, 32 | BLAKE2B_PERSONALBYTES = 16 33 | }; 34 | 35 | #pragma pack(push, 1) 36 | typedef struct __blake2b_param { 37 | uint8_t digest_length; /* 1 */ 38 | uint8_t key_length; /* 2 */ 39 | uint8_t fanout; /* 3 */ 40 | uint8_t depth; /* 4 */ 41 | uint32_t leaf_length; /* 8 */ 42 | uint64_t node_offset; /* 16 */ 43 | uint8_t node_depth; /* 17 */ 44 | uint8_t inner_length; /* 18 */ 45 | uint8_t reserved[14]; /* 32 */ 46 | uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */ 47 | uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */ 48 | } blake2b_param; 49 | #pragma pack(pop) 50 | 51 | typedef struct __blake2b_state { 52 | uint64_t h[8]; 53 | uint64_t t[2]; 54 | uint64_t f[2]; 55 | uint8_t buf[BLAKE2B_BLOCKBYTES]; 56 | unsigned buflen; 57 | unsigned outlen; 58 | uint8_t last_node; 59 | } blake2b_state; 60 | 61 | /* Ensure param structs have not been wrongly padded */ 62 | /* Poor man's static_assert */ 63 | enum { 64 | blake2_size_check_0 = 1 / !!(CHAR_BIT == 8), 65 | blake2_size_check_2 = 66 | 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT) 67 | }; 68 | 69 | /* Streaming API */ 70 | ARGON2_LOCAL int blake2b_init(blake2b_state *S, size_t outlen); 71 | ARGON2_LOCAL int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, 72 | size_t keylen); 73 | ARGON2_LOCAL int blake2b_init_param(blake2b_state *S, const blake2b_param *P); 74 | ARGON2_LOCAL int blake2b_update(blake2b_state *S, const void *in, size_t inlen); 75 | ARGON2_LOCAL int blake2b_final(blake2b_state *S, void *out, size_t outlen); 76 | 77 | /* Simple API */ 78 | ARGON2_LOCAL int blake2b(void *out, size_t outlen, const void *in, size_t inlen, 79 | const void *key, size_t keylen); 80 | 81 | /* Argon2 Team - Begin Code */ 82 | ARGON2_LOCAL int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); 83 | /* Argon2 Team - End Code */ 84 | 85 | #if defined(__cplusplus) 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/crypto/argon2/encoding.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef ENCODING_H 19 | #define ENCODING_H 20 | #include "argon2.h" 21 | 22 | #define ARGON2_MAX_DECODED_LANES UINT32_C(255) 23 | #define ARGON2_MIN_DECODED_SALT_LEN UINT32_C(8) 24 | #define ARGON2_MIN_DECODED_OUT_LEN UINT32_C(12) 25 | 26 | /* 27 | * encode an Argon2 hash string into the provided buffer. 'dst_len' 28 | * contains the size, in characters, of the 'dst' buffer; if 'dst_len' 29 | * is less than the number of required characters (including the 30 | * terminating 0), then this function returns ARGON2_ENCODING_ERROR. 31 | * 32 | * on success, ARGON2_OK is returned. 33 | */ 34 | int encode_string(char *dst, size_t dst_len, argon2_context *ctx, 35 | argon2_type type); 36 | 37 | /* 38 | * Decodes an Argon2 hash string into the provided structure 'ctx'. 39 | * The only fields that must be set prior to this call are ctx.saltlen and 40 | * ctx.outlen (which must be the maximal salt and out length values that are 41 | * allowed), ctx.salt and ctx.out (which must be buffers of the specified 42 | * length), and ctx.pwd and ctx.pwdlen which must hold a valid password. 43 | * 44 | * Invalid input string causes an error. On success, the ctx is valid and all 45 | * fields have been initialized. 46 | * 47 | * Returned value is ARGON2_OK on success, other ARGON2_ codes on error. 48 | */ 49 | int decode_string(argon2_context *ctx, const char *str, argon2_type type); 50 | 51 | /* Returns the length of the encoded byte stream with length len */ 52 | size_t b64len(uint32_t len); 53 | 54 | /* Returns the length of the encoded number num */ 55 | size_t numlen(uint32_t num); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/crypto/argon2/thread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #if !defined(ARGON2_NO_THREADS) 19 | 20 | #include "thread.h" 21 | #if defined(_WIN32) 22 | #include 23 | #endif 24 | 25 | int argon2_thread_create(argon2_thread_handle_t *handle, 26 | argon2_thread_func_t func, void *args) { 27 | if (NULL == handle || func == NULL) { 28 | return -1; 29 | } 30 | #if defined(_WIN32) 31 | *handle = _beginthreadex(NULL, 0, func, args, 0, NULL); 32 | return *handle != 0 ? 0 : -1; 33 | #else 34 | return pthread_create(handle, NULL, func, args); 35 | #endif 36 | } 37 | 38 | int argon2_thread_join(argon2_thread_handle_t handle) { 39 | #if defined(_WIN32) 40 | if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) { 41 | return CloseHandle((HANDLE)handle) != 0 ? 0 : -1; 42 | } 43 | return -1; 44 | #else 45 | return pthread_join(handle, NULL); 46 | #endif 47 | } 48 | 49 | void argon2_thread_exit(void) { 50 | #if defined(_WIN32) 51 | _endthreadex(0); 52 | #else 53 | pthread_exit(NULL); 54 | #endif 55 | } 56 | 57 | #endif /* ARGON2_NO_THREADS */ 58 | -------------------------------------------------------------------------------- /src/crypto/argon2/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef ARGON2_THREAD_H 19 | #define ARGON2_THREAD_H 20 | 21 | #if !defined(ARGON2_NO_THREADS) 22 | 23 | /* 24 | Here we implement an abstraction layer for the simpĺe requirements 25 | of the Argon2 code. We only require 3 primitives---thread creation, 26 | joining, and termination---so full emulation of the pthreads API 27 | is unwarranted. Currently we wrap pthreads and Win32 threads. 28 | 29 | The API defines 2 types: the function pointer type, 30 | argon2_thread_func_t, 31 | and the type of the thread handle---argon2_thread_handle_t. 32 | */ 33 | #if defined(_WIN32) 34 | #include 35 | typedef unsigned(__stdcall *argon2_thread_func_t)(void *); 36 | typedef uintptr_t argon2_thread_handle_t; 37 | #else 38 | #include 39 | typedef void *(*argon2_thread_func_t)(void *); 40 | typedef pthread_t argon2_thread_handle_t; 41 | #endif 42 | 43 | /* Creates a thread 44 | * @param handle pointer to a thread handle, which is the output of this 45 | * function. Must not be NULL. 46 | * @param func A function pointer for the thread's entry point. Must not be 47 | * NULL. 48 | * @param args Pointer that is passed as an argument to @func. May be NULL. 49 | * @return 0 if @handle and @func are valid pointers and a thread is successfully 50 | * created. 51 | */ 52 | int argon2_thread_create(argon2_thread_handle_t *handle, 53 | argon2_thread_func_t func, void *args); 54 | 55 | /* Waits for a thread to terminate 56 | * @param handle Handle to a thread created with argon2_thread_create. 57 | * @return 0 if @handle is a valid handle, and joining completed successfully. 58 | */ 59 | int argon2_thread_join(argon2_thread_handle_t handle); 60 | 61 | /* Terminate the current thread. Must be run inside a thread created by 62 | * argon2_thread_create. 63 | */ 64 | void argon2_thread_exit(void); 65 | 66 | #endif /* ARGON2_NO_THREADS */ 67 | #endif 68 | -------------------------------------------------------------------------------- /src/crypto/c_blake256.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLAKE256_H_ 2 | #define _BLAKE256_H_ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint32_t h[8], s[4], t[2]; 8 | int buflen, nullt; 9 | uint8_t buf[64]; 10 | } state; 11 | 12 | typedef struct { 13 | state inner; 14 | state outer; 15 | } hmac_state; 16 | 17 | void blake256_init(state *); 18 | void blake224_init(state *); 19 | 20 | void blake256_update(state *, const uint8_t *, uint64_t); 21 | void blake224_update(state *, const uint8_t *, uint64_t); 22 | 23 | void blake256_final(state *, uint8_t *); 24 | void blake224_final(state *, uint8_t *); 25 | 26 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 27 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 28 | 29 | /* HMAC functions: */ 30 | 31 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 32 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 33 | 34 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 35 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 36 | 37 | void hmac_blake256_final(hmac_state *, uint8_t *); 38 | void hmac_blake224_final(hmac_state *, uint8_t *); 39 | 40 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 41 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 42 | 43 | #endif /* _BLAKE256_H_ */ 44 | -------------------------------------------------------------------------------- /src/crypto/c_groestl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | #include "crypto_uint8.h" 4 | #include "crypto_uint32.h" 5 | #include "crypto_uint64.h" 6 | #include "crypto_hash.h" 7 | 8 | typedef crypto_uint8 uint8_t; 9 | typedef crypto_uint32 uint32_t; 10 | typedef crypto_uint64 uint64_t; 11 | */ 12 | #include 13 | #include "hash.h" 14 | 15 | /* some sizes (number of bytes) */ 16 | #define ROWS 8 17 | #define LENGTHFIELDLEN ROWS 18 | #define COLS512 8 19 | 20 | #define SIZE512 (ROWS*COLS512) 21 | 22 | #define ROUNDS512 10 23 | #define HASH_BIT_LEN 256 24 | 25 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 26 | 27 | 28 | #define li_32(h) 0x##h##u 29 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 30 | #define u32BIG(a) \ 31 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 32 | (ROTL32(a,24) & li_32(FF00FF00))) 33 | 34 | 35 | /* NIST API begin */ 36 | typedef struct { 37 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 38 | uint32_t block_counter1, 39 | block_counter2; /* message block counter(s) */ 40 | BitSequence buffer[SIZE512]; /* data buffer */ 41 | int buf_ptr; /* data buffer pointer */ 42 | int bits_in_last_byte; /* no. of message bits in last byte of 43 | data buffer */ 44 | } hashState; 45 | 46 | /*void Init(hashState*); 47 | void Update(hashState*, const BitSequence*, DataLength); 48 | void Final(hashState*, BitSequence*); */ 49 | void groestl(const BitSequence*, DataLength, BitSequence*); 50 | /* NIST API end */ 51 | 52 | /* 53 | int crypto_hash(unsigned char *out, 54 | const unsigned char *in, 55 | unsigned long long len); 56 | */ 57 | -------------------------------------------------------------------------------- /src/crypto/c_jh.h: -------------------------------------------------------------------------------- 1 | /*This program gives the 64-bit optimized bitslice implementation of JH using ANSI C 2 | 3 | -------------------------------- 4 | Performance 5 | 6 | Microprocessor: Intel CORE 2 processor (Core 2 Duo Mobile T6600 2.2GHz) 7 | Operating System: 64-bit Ubuntu 10.04 (Linux kernel 2.6.32-22-generic) 8 | Speed for long message: 9 | 1) 45.8 cycles/byte compiler: Intel C++ Compiler 11.1 compilation option: icc -O2 10 | 2) 56.8 cycles/byte compiler: gcc 4.4.3 compilation option: gcc -O3 11 | 12 | -------------------------------- 13 | Last Modified: January 16, 2011 14 | */ 15 | #pragma once 16 | #include "hash.h" 17 | 18 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 19 | 20 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 21 | -------------------------------------------------------------------------------- /src/crypto/c_keccak.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include "hash-ops.h" 6 | #include "c_keccak.h" 7 | 8 | const uint64_t keccakf_rndc[24] = 9 | { 10 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 11 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 12 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 13 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 14 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 15 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 16 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 17 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 18 | }; 19 | 20 | const int keccakf_rotc[24] = 21 | { 22 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 23 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 24 | }; 25 | 26 | const int keccakf_piln[24] = 27 | { 28 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 29 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 30 | }; 31 | 32 | // update the state with given number of rounds 33 | 34 | void keccakf(uint64_t st[25], int rounds) 35 | { 36 | int i, j, round; 37 | uint64_t t, bc[5]; 38 | 39 | for (round = 0; round < rounds; round++) { 40 | 41 | // Theta 42 | for (i = 0; i < 5; i++) 43 | bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; 44 | 45 | for (i = 0; i < 5; i++) { 46 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 47 | for (j = 0; j < 25; j += 5) 48 | st[j + i] ^= t; 49 | } 50 | 51 | // Rho Pi 52 | t = st[1]; 53 | for (i = 0; i < 24; i++) { 54 | j = keccakf_piln[i]; 55 | bc[0] = st[j]; 56 | st[j] = ROTL64(t, keccakf_rotc[i]); 57 | t = bc[0]; 58 | } 59 | 60 | // Chi 61 | for (j = 0; j < 25; j += 5) { 62 | for (i = 0; i < 5; i++) 63 | bc[i] = st[j + i]; 64 | for (i = 0; i < 5; i++) 65 | st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; 66 | } 67 | 68 | // Iota 69 | st[0] ^= keccakf_rndc[round]; 70 | } 71 | } 72 | 73 | // compute a keccak hash (md) of given byte length from "in" 74 | typedef uint64_t state_t[25]; 75 | 76 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) 77 | { 78 | state_t st; 79 | uint8_t temp[144]; 80 | int i, rsiz, rsizw; 81 | 82 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 83 | rsizw = rsiz / 8; 84 | 85 | memset(st, 0, sizeof(st)); 86 | 87 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 88 | for (i = 0; i < rsizw; i++) 89 | st[i] ^= ((uint64_t *) in)[i]; 90 | keccakf(st, KECCAK_ROUNDS); 91 | } 92 | 93 | // last block and padding 94 | memcpy(temp, in, inlen); 95 | temp[inlen++] = 1; 96 | memset(temp + inlen, 0, rsiz - inlen); 97 | temp[rsiz - 1] |= 0x80; 98 | 99 | for (i = 0; i < rsizw; i++) 100 | st[i] ^= ((uint64_t *) temp)[i]; 101 | 102 | keccakf(st, KECCAK_ROUNDS); 103 | 104 | memcpy(md, st, mdlen); 105 | 106 | return 0; 107 | } 108 | 109 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md) 110 | { 111 | keccak(in, inlen, md, sizeof(state_t)); 112 | } 113 | -------------------------------------------------------------------------------- /src/crypto/c_keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/crypto/c_skein.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_H_ 2 | #define _SKEIN_H_ 1 3 | /************************************************************************** 4 | ** 5 | ** Interface declarations and internal definitions for Skein hashing. 6 | ** 7 | ** Source code author: Doug Whiting, 2008. 8 | ** 9 | ** This algorithm and source code is released to the public domain. 10 | ** 11 | *************************************************************************** 12 | ** 13 | ** The following compile-time switches may be defined to control some 14 | ** tradeoffs between speed, code size, error checking, and security. 15 | ** 16 | ** The "default" note explains what happens when the switch is not defined. 17 | ** 18 | ** SKEIN_DEBUG -- make callouts from inside Skein code 19 | ** to examine/display intermediate values. 20 | ** [default: no callouts (no overhead)] 21 | ** 22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 23 | ** code. If not defined, most error checking 24 | ** is disabled (for performance). Otherwise, 25 | ** the switch value is interpreted as: 26 | ** 0: use assert() to flag errors 27 | ** 1: return SKEIN_FAIL to flag errors 28 | ** 29 | ***************************************************************************/ 30 | #include "skein_port.h" /* get platform-specific definitions */ 31 | #include "hash.h" 32 | 33 | typedef enum 34 | { 35 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */ 36 | SKEIN_FAIL = 1, 37 | SKEIN_BAD_HASHLEN = 2 38 | } 39 | SkeinHashReturn; 40 | 41 | /* "all-in-one" call */ 42 | SkeinHashReturn c_skein_hash(int hashbitlen, const BitSequence *data, 43 | DataLength databitlen, BitSequence *hashval); 44 | 45 | #endif /* ifndef _SKEIN_H_ */ 46 | -------------------------------------------------------------------------------- /src/crypto/cryptonote_core/account.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "include_base_utils.h" 10 | #include "account.h" 11 | #include "warnings.h" 12 | #include "crypto/crypto.h" 13 | #include "cryptonote_core/cryptonote_basic_impl.h" 14 | #include "cryptonote_core/cryptonote_format_utils.h" 15 | using namespace std; 16 | 17 | DISABLE_VS_WARNINGS(4244 4345) 18 | 19 | namespace cryptonote 20 | { 21 | //----------------------------------------------------------------- 22 | account_base::account_base() 23 | { 24 | set_null(); 25 | } 26 | //----------------------------------------------------------------- 27 | void account_base::set_null() 28 | { 29 | m_keys = account_keys(); 30 | } 31 | //----------------------------------------------------------------- 32 | void account_base::generate() 33 | { 34 | generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key); 35 | generate_keys(m_keys.m_account_address.m_view_public_key, m_keys.m_view_secret_key); 36 | m_creation_timestamp = time(NULL); 37 | } 38 | //----------------------------------------------------------------- 39 | const account_keys& account_base::get_keys() const 40 | { 41 | return m_keys; 42 | } 43 | //----------------------------------------------------------------- 44 | std::string account_base::get_public_address_str() 45 | { 46 | //TODO: change this code into base 58 47 | return get_account_address_as_str(m_keys.m_account_address); 48 | } 49 | //----------------------------------------------------------------- 50 | } 51 | -------------------------------------------------------------------------------- /src/crypto/cryptonote_core/account.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #include "cryptonote_core/cryptonote_basic.h" 8 | #include "crypto/crypto.h" 9 | #include "serialization/keyvalue_serialization.h" 10 | 11 | namespace cryptonote 12 | { 13 | 14 | struct account_keys 15 | { 16 | account_public_address m_account_address; 17 | crypto::secret_key m_spend_secret_key; 18 | crypto::secret_key m_view_secret_key; 19 | 20 | BEGIN_KV_SERIALIZE_MAP() 21 | KV_SERIALIZE(m_account_address) 22 | KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_secret_key) 23 | KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_secret_key) 24 | END_KV_SERIALIZE_MAP() 25 | }; 26 | 27 | /************************************************************************/ 28 | /* */ 29 | /************************************************************************/ 30 | class account_base 31 | { 32 | public: 33 | account_base(); 34 | void generate(); 35 | const account_keys& get_keys() const; 36 | std::string get_public_address_str(); 37 | 38 | uint64_t get_createtime() const { return m_creation_timestamp; } 39 | void set_createtime(uint64_t val) { m_creation_timestamp = val; } 40 | 41 | bool load(const std::string& file_path); 42 | bool store(const std::string& file_path); 43 | 44 | template 45 | inline void serialize(t_archive &a, const unsigned int /*ver*/) 46 | { 47 | a & m_keys; 48 | a & m_creation_timestamp; 49 | } 50 | 51 | BEGIN_KV_SERIALIZE_MAP() 52 | KV_SERIALIZE(m_keys) 53 | KV_SERIALIZE(m_creation_timestamp) 54 | END_KV_SERIALIZE_MAP() 55 | 56 | private: 57 | void set_null(); 58 | account_keys m_keys; 59 | uint64_t m_creation_timestamp; 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /src/crypto/cryptonote_core/cryptonote_basic_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #include "cryptonote_basic.h" 8 | #include "crypto/crypto.h" 9 | #include "crypto/hash.h" 10 | 11 | 12 | namespace cryptonote { 13 | /************************************************************************/ 14 | /* */ 15 | /************************************************************************/ 16 | template 17 | struct array_hasher: std::unary_function 18 | { 19 | std::size_t operator()(const t_array& val) const 20 | { 21 | return boost::hash_range(&val.data[0], &val.data[sizeof(val.data)]); 22 | } 23 | }; 24 | 25 | 26 | #pragma pack(push, 1) 27 | struct public_address_outer_blob 28 | { 29 | uint8_t m_ver; 30 | account_public_address m_address; 31 | uint8_t check_sum; 32 | }; 33 | #pragma pack (pop) 34 | 35 | 36 | /************************************************************************/ 37 | /* Cryptonote helper functions */ 38 | /************************************************************************/ 39 | size_t get_max_block_size(); 40 | size_t get_max_tx_size(); 41 | bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward); 42 | uint8_t get_account_address_checksum(const public_address_outer_blob& bl); 43 | std::string get_account_address_as_str(const account_public_address& adr); 44 | bool get_account_address_from_str(account_public_address& adr, const std::string& str); 45 | bool is_coinbase(const transaction& tx); 46 | 47 | bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b); 48 | bool operator ==(const cryptonote::block& a, const cryptonote::block& b); 49 | } 50 | 51 | template 52 | std::ostream &print256(std::ostream &o, const T &v) { 53 | return o << "<" << epee::string_tools::pod_to_hex(v) << ">"; 54 | } 55 | 56 | bool parse_hash256(const std::string str_hash, crypto::hash& hash); 57 | 58 | namespace crypto { 59 | inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { return print256(o, v); } 60 | inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) { return print256(o, v); } 61 | inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) { return print256(o, v); } 62 | inline std::ostream &operator <<(std::ostream &o, const crypto::key_image &v) { return print256(o, v); } 63 | inline std::ostream &operator <<(std::ostream &o, const crypto::signature &v) { return print256(o, v); } 64 | inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { return print256(o, v); } 65 | } 66 | -------------------------------------------------------------------------------- /src/crypto/cryptonote_core/cryptonote_format_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | #include "../hash.h" 7 | #include "../wild_keccak.h" 8 | 9 | 10 | namespace cryptonote 11 | { 12 | template 13 | bool get_blob_longhash_bb(const blobdata& bd, crypto::hash& res, uint64_t height, callback_t accessor) 14 | { 15 | crypto::wild_keccak_dbl(reinterpret_cast(bd.data()), bd.size(), reinterpret_cast(&res), sizeof(res), [&](crypto::state_t_m& st, crypto::mixin_t& mix) 16 | { 17 | if(!height) 18 | { 19 | memset(&mix, 0, sizeof(mix)); 20 | return; 21 | } 22 | #define GET_H(index) accessor(st[index]) 23 | for(size_t i = 0; i!=6; i++) 24 | { 25 | *(crypto::hash*)&mix[i*4] = XOR_4(GET_H(i*4), GET_H(i*4+1), GET_H(i*4+2), GET_H(i*4+3)); 26 | } 27 | }); 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/crypto/cryptonote_protocol/cryptonote_protocol_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "serialization/keyvalue_serialization.h" 9 | #include "cryptonote_core/cryptonote_basic.h" 10 | #include "cryptonote_protocol/blobdatatype.h" 11 | namespace cryptonote 12 | { 13 | 14 | 15 | #define BC_COMMANDS_POOL_BASE 2000 16 | 17 | 18 | /************************************************************************/ 19 | /* */ 20 | /************************************************************************/ 21 | struct block_complete_entry 22 | { 23 | blobdata block; 24 | std::list txs; 25 | BEGIN_KV_SERIALIZE_MAP() 26 | KV_SERIALIZE(block) 27 | KV_SERIALIZE(txs) 28 | END_KV_SERIALIZE_MAP() 29 | }; 30 | 31 | 32 | /************************************************************************/ 33 | /* */ 34 | /************************************************************************/ 35 | struct NOTIFY_NEW_BLOCK 36 | { 37 | const static int ID = BC_COMMANDS_POOL_BASE + 1; 38 | 39 | struct request 40 | { 41 | block_complete_entry b; 42 | uint64_t current_blockchain_height; 43 | uint32_t hop; 44 | 45 | BEGIN_KV_SERIALIZE_MAP() 46 | KV_SERIALIZE(b) 47 | KV_SERIALIZE(current_blockchain_height) 48 | KV_SERIALIZE(hop) 49 | END_KV_SERIALIZE_MAP() 50 | }; 51 | }; 52 | 53 | /************************************************************************/ 54 | /* */ 55 | /************************************************************************/ 56 | struct NOTIFY_NEW_TRANSACTIONS 57 | { 58 | const static int ID = BC_COMMANDS_POOL_BASE + 2; 59 | 60 | struct request 61 | { 62 | std::list txs; 63 | 64 | BEGIN_KV_SERIALIZE_MAP() 65 | KV_SERIALIZE(txs) 66 | END_KV_SERIALIZE_MAP() 67 | }; 68 | }; 69 | /************************************************************************/ 70 | /* */ 71 | /************************************************************************/ 72 | struct NOTIFY_REQUEST_GET_OBJECTS 73 | { 74 | const static int ID = BC_COMMANDS_POOL_BASE + 3; 75 | 76 | struct request 77 | { 78 | std::list txs; 79 | std::list blocks; 80 | 81 | BEGIN_KV_SERIALIZE_MAP() 82 | KV_SERIALIZE_CONTAINER_POD_AS_BLOB(txs) 83 | KV_SERIALIZE_CONTAINER_POD_AS_BLOB(blocks) 84 | END_KV_SERIALIZE_MAP() 85 | }; 86 | }; 87 | 88 | struct NOTIFY_RESPONSE_GET_OBJECTS 89 | { 90 | const static int ID = BC_COMMANDS_POOL_BASE + 4; 91 | 92 | struct request 93 | { 94 | std::list txs; 95 | std::list blocks; 96 | std::list missed_ids; 97 | uint64_t current_blockchain_height; 98 | 99 | BEGIN_KV_SERIALIZE_MAP() 100 | KV_SERIALIZE(txs) 101 | KV_SERIALIZE(blocks) 102 | KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missed_ids) 103 | KV_SERIALIZE(current_blockchain_height) 104 | END_KV_SERIALIZE_MAP() 105 | }; 106 | }; 107 | 108 | 109 | struct CORE_SYNC_DATA 110 | { 111 | uint64_t current_height; 112 | crypto::hash top_id; 113 | 114 | BEGIN_KV_SERIALIZE_MAP() 115 | KV_SERIALIZE(current_height) 116 | KV_SERIALIZE_VAL_POD_AS_BLOB(top_id) 117 | END_KV_SERIALIZE_MAP() 118 | }; 119 | 120 | struct NOTIFY_REQUEST_CHAIN 121 | { 122 | const static int ID = BC_COMMANDS_POOL_BASE + 6; 123 | 124 | struct request 125 | { 126 | std::list block_ids; /*IDs of the first 10 blocks are sequential, next goes with pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */ 127 | 128 | BEGIN_KV_SERIALIZE_MAP() 129 | KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids) 130 | END_KV_SERIALIZE_MAP() 131 | }; 132 | }; 133 | 134 | struct NOTIFY_RESPONSE_CHAIN_ENTRY 135 | { 136 | const static int ID = BC_COMMANDS_POOL_BASE + 7; 137 | 138 | struct request 139 | { 140 | uint64_t start_height; 141 | uint64_t total_height; 142 | std::list m_block_ids; 143 | 144 | BEGIN_KV_SERIALIZE_MAP() 145 | KV_SERIALIZE(start_height) 146 | KV_SERIALIZE(total_height) 147 | KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids) 148 | END_KV_SERIALIZE_MAP() 149 | }; 150 | }; 151 | 152 | } 153 | -------------------------------------------------------------------------------- /src/crypto/groestl_tables.h: -------------------------------------------------------------------------------- 1 | #ifndef __tables_h 2 | #define __tables_h 3 | 4 | 5 | const uint32_t T[512] = {0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0xd17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc 6 | , 0x50f09060, 0x6050c0f0, 0x3050702, 0x2030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5 7 | , 0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0xb1de6fb, 0xfb0bed1d 8 | , 0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded 9 | , 0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1 10 | , 0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441 11 | , 0xc141c08, 0x80c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0xf111b0a, 0xa0f1411, 0xb5c4eb2f, 0x2fb55ec4 12 | , 0x91b150e, 0xe091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba 13 | , 0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616 14 | , 0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2 15 | , 0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0x0, 0x0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c 16 | , 0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de 17 | , 0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7 18 | , 0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x60a0e04, 0x406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e 19 | , 0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x58a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x40cfdf1, 0xf104f90c 20 | , 0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0xe12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7 21 | , 0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b 22 | , 0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4 23 | , 0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e 24 | , 0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a 25 | , 0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0xa1e120c, 0xc0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37 26 | , 0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86 27 | , 0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x18c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b 28 | , 0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028 29 | , 0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3 30 | , 0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0xd861a91, 0x85949b0f, 0xf851e94 31 | , 0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x50f0906, 0x6050c0f, 0x103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836 32 | , 0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0 33 | , 0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x7890e80, 0xa7f2c133, 0x33a766f2 34 | , 0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e 35 | , 0x8f8a8903, 0x38f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3 36 | , 0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e}; 37 | 38 | #endif /* __tables_h */ 39 | -------------------------------------------------------------------------------- /src/crypto/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #if !defined(__cplusplus) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "int-util.h" 15 | 16 | static inline void *padd(void *p, size_t i) { 17 | return (char *) p + i; 18 | } 19 | 20 | static inline const void *cpadd(const void *p, size_t i) { 21 | return (const char *) p + i; 22 | } 23 | 24 | static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { 25 | if (sizeof(size_t) == 4) { 26 | *(uint32_t *) padd(buffer, bufsize - 4) = swap32be(length); 27 | } else { 28 | *(uint64_t *) padd(buffer, bufsize - 8) = swap64be(length); 29 | } 30 | } 31 | 32 | #pragma pack(push, 1) 33 | union hash_state { 34 | uint8_t b[200]; 35 | uint64_t w[25]; 36 | }; 37 | #pragma pack(pop) 38 | 39 | void hash_permutation(union hash_state *state); 40 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count); 41 | 42 | #endif 43 | 44 | enum { 45 | HASH_SIZE = 32, 46 | HASH_DATA_AREA = 136 47 | }; 48 | 49 | void cn_fast_hash(const void *data, size_t length, char *hash); 50 | void cn_slow_hash(const void *data, size_t length, char *hash); 51 | 52 | void hash_extra_blake(const void *data, size_t length, char *hash); 53 | void hash_extra_groestl(const void *data, size_t length, char *hash); 54 | void hash_extra_jh(const void *data, size_t length, char *hash); 55 | void hash_extra_skein(const void *data, size_t length, char *hash); 56 | 57 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash); 58 | -------------------------------------------------------------------------------- /src/crypto/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "hash-ops.h" 10 | #include "c_keccak.h" 11 | 12 | void hash_permutation(union hash_state *state) { 13 | keccakf((uint64_t*)state, 24); 14 | } 15 | 16 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { 17 | keccak1600(buf, count, (uint8_t*)state); 18 | } 19 | 20 | void cn_fast_hash(const void *data, size_t length, char *hash) { 21 | union hash_state state; 22 | hash_process(&state, data, length); 23 | memcpy(hash, &state, HASH_SIZE); 24 | } 25 | -------------------------------------------------------------------------------- /src/crypto/hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "hash-ops.h" 4 | 5 | typedef unsigned char BitSequence; 6 | typedef unsigned long long DataLength; 7 | 8 | #ifdef __cplusplus 9 | 10 | #include 11 | 12 | typedef std::string blobdata; 13 | 14 | namespace crypto { 15 | #pragma pack(push, 1) 16 | class hash { 17 | char data[HASH_SIZE]; 18 | }; 19 | #pragma pack(pop) 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/crypto/lyra2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Header file for the Lyra2 Password Hashing Scheme (PHS). 3 | * 4 | * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014. 5 | * 6 | * This software is hereby placed in the public domain. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 9 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 12 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 15 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 16 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 17 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 18 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | #ifndef LYRA2_H_ 21 | #define LYRA2_H_ 22 | 23 | #include 24 | 25 | typedef unsigned char byte; 26 | 27 | //Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED) 28 | #define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t) 29 | #define BLOCK_LEN_BLAKE2_SAFE_BYTES (BLOCK_LEN_BLAKE2_SAFE_INT64 * 8) //same as above, in bytes 30 | 31 | 32 | #ifdef BLOCK_LEN_BITS 33 | #define BLOCK_LEN_INT64 (BLOCK_LEN_BITS/64) //Block length: 768 bits (=96 bytes, =12 uint64_t) 34 | #define BLOCK_LEN_BYTES (BLOCK_LEN_BITS/8) //Block length, in bytes 35 | #else //default block lenght: 768 bits 36 | #define BLOCK_LEN_INT64 12 //Block length: 768 bits (=96 bytes, =12 uint64_t) 37 | #define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes 38 | #endif 39 | 40 | int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols); 41 | 42 | int LYRA2_3(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols); 43 | 44 | int LYRA2_old(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols); 45 | 46 | #endif /* LYRA2_H_ */ 47 | -------------------------------------------------------------------------------- /src/crypto/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /src/crypto/oaes_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_LIB_H 32 | #define _OAES_LIB_H 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #ifdef _WIN32 42 | # ifdef OAES_SHARED 43 | # ifdef oaes_lib_EXPORTS 44 | # define OAES_API __declspec(dllexport) 45 | # else 46 | # define OAES_API __declspec(dllimport) 47 | # endif 48 | # else 49 | # define OAES_API 50 | # endif 51 | #else 52 | # define OAES_API 53 | #endif // WIN32 54 | 55 | #define OAES_VERSION "0.8.1" 56 | #define OAES_BLOCK_SIZE 16 57 | 58 | typedef void OAES_CTX; 59 | 60 | typedef enum 61 | { 62 | OAES_RET_FIRST = 0, 63 | OAES_RET_SUCCESS = 0, 64 | OAES_RET_UNKNOWN, 65 | OAES_RET_ARG1, 66 | OAES_RET_ARG2, 67 | OAES_RET_ARG3, 68 | OAES_RET_ARG4, 69 | OAES_RET_ARG5, 70 | OAES_RET_NOKEY, 71 | OAES_RET_MEM, 72 | OAES_RET_BUF, 73 | OAES_RET_HEADER, 74 | OAES_RET_COUNT 75 | } OAES_RET; 76 | 77 | /* 78 | * oaes_set_option() takes one of these values for its [option] parameter 79 | * some options accept either an optional or a required [value] parameter 80 | */ 81 | // no option 82 | #define OAES_OPTION_NONE 0 83 | // enable ECB mode, disable CBC mode 84 | #define OAES_OPTION_ECB 1 85 | // enable CBC mode, disable ECB mode 86 | // value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify 87 | // the value of the initialization vector, iv 88 | #define OAES_OPTION_CBC 2 89 | 90 | #ifdef OAES_DEBUG 91 | typedef int ( * oaes_step_cb ) ( 92 | const uint8_t state[OAES_BLOCK_SIZE], 93 | const char * step_name, 94 | int step_count, 95 | void * user_data ); 96 | // enable state stepping mode 97 | // value is required, must pass oaes_step_cb to receive the state at each step 98 | #define OAES_OPTION_STEP_ON 4 99 | // disable state stepping mode 100 | #define OAES_OPTION_STEP_OFF 8 101 | #endif // OAES_DEBUG 102 | 103 | typedef uint16_t OAES_OPTION; 104 | 105 | typedef struct _oaes_key 106 | { 107 | size_t data_len; 108 | uint8_t *data; 109 | size_t exp_data_len; 110 | uint8_t *exp_data; 111 | size_t num_keys; 112 | size_t key_base; 113 | } oaes_key; 114 | 115 | typedef struct _oaes_ctx 116 | { 117 | #ifdef OAES_HAVE_ISAAC 118 | randctx * rctx; 119 | #endif // OAES_HAVE_ISAAC 120 | 121 | #ifdef OAES_DEBUG 122 | oaes_step_cb step_cb; 123 | #endif // OAES_DEBUG 124 | 125 | oaes_key * key; 126 | OAES_OPTION options; 127 | uint8_t iv[OAES_BLOCK_SIZE]; 128 | } oaes_ctx; 129 | /* 130 | * // usage: 131 | * 132 | * OAES_CTX * ctx = oaes_alloc(); 133 | * . 134 | * . 135 | * . 136 | * { 137 | * oaes_gen_key_xxx( ctx ); 138 | * { 139 | * oaes_key_export( ctx, _buf, &_buf_len ); 140 | * // or 141 | * oaes_key_export_data( ctx, _buf, &_buf_len );\ 142 | * } 143 | * } 144 | * // or 145 | * { 146 | * oaes_key_import( ctx, _buf, _buf_len ); 147 | * // or 148 | * oaes_key_import_data( ctx, _buf, _buf_len ); 149 | * } 150 | * . 151 | * . 152 | * . 153 | * oaes_encrypt( ctx, m, m_len, c, &c_len ); 154 | * . 155 | * . 156 | * . 157 | * oaes_decrypt( ctx, c, c_len, m, &m_len ); 158 | * . 159 | * . 160 | * . 161 | * oaes_free( &ctx ); 162 | */ 163 | 164 | OAES_API OAES_CTX * oaes_alloc(void); 165 | 166 | OAES_API OAES_RET oaes_free( OAES_CTX ** ctx ); 167 | 168 | OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx, 169 | OAES_OPTION option, const void * value ); 170 | 171 | OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx ); 172 | 173 | OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx ); 174 | 175 | OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx ); 176 | 177 | // export key with header information 178 | // set data == NULL to get the required data_len 179 | OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx, 180 | uint8_t * data, size_t * data_len ); 181 | 182 | // directly export the data from key 183 | // set data == NULL to get the required data_len 184 | OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx, 185 | uint8_t * data, size_t * data_len ); 186 | 187 | // import key with header information 188 | OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx, 189 | const uint8_t * data, size_t data_len ); 190 | 191 | // directly import data into key 192 | OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx, 193 | const uint8_t * data, size_t data_len ); 194 | 195 | // set c == NULL to get the required c_len 196 | OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx, 197 | const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ); 198 | 199 | // set m == NULL to get the required m_len 200 | OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx, 201 | const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ); 202 | 203 | // set buf == NULL to get the required buf_len 204 | OAES_API OAES_RET oaes_sprintf( 205 | char * buf, size_t * buf_len, const uint8_t * data, size_t data_len ); 206 | 207 | OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); 208 | 209 | OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); 210 | 211 | #ifdef __cplusplus 212 | } 213 | #endif 214 | 215 | #endif // _OAES_LIB_H 216 | -------------------------------------------------------------------------------- /src/crypto/sha256.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2005,2007,2009 Colin Percival 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef SHA256_H 29 | #define SHA256_H 30 | 31 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 32 | #include "stdint.h" 33 | #else 34 | #include 35 | #endif 36 | 37 | #include "../sha3/sph_types.h" 38 | #include 39 | 40 | static __inline uint32_t 41 | be32dec(const void *pp) 42 | { 43 | const uint8_t *p = (uint8_t const *)pp; 44 | 45 | return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + 46 | ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); 47 | } 48 | 49 | static __inline void 50 | be32enc(void *pp, uint32_t x) 51 | { 52 | uint8_t * p = (uint8_t *)pp; 53 | 54 | p[3] = x & 0xff; 55 | p[2] = (x >> 8) & 0xff; 56 | p[1] = (x >> 16) & 0xff; 57 | p[0] = (x >> 24) & 0xff; 58 | } 59 | 60 | static __inline uint32_t 61 | le32dec(const void *pp) 62 | { 63 | const uint8_t *p = (uint8_t const *)pp; 64 | 65 | return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + 66 | ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); 67 | } 68 | 69 | static __inline void 70 | le32enc(void *pp, uint32_t x) 71 | { 72 | uint8_t * p = (uint8_t *)pp; 73 | 74 | p[0] = x & 0xff; 75 | p[1] = (x >> 8) & 0xff; 76 | p[2] = (x >> 16) & 0xff; 77 | p[3] = (x >> 24) & 0xff; 78 | } 79 | 80 | 81 | typedef struct SHA256Context { 82 | uint32_t state[8]; 83 | uint32_t count[2]; 84 | unsigned char buf[64]; 85 | } sha256_ctx; 86 | 87 | typedef struct HMAC_SHA256Context { 88 | sha256_ctx ictx; 89 | sha256_ctx octx; 90 | } hmac_sha256_ctx; 91 | 92 | void sha256_init(sha256_ctx *); 93 | void sha256_update(sha256_ctx *, const void *, size_t); 94 | void sha256_final(unsigned char [32], sha256_ctx *); 95 | void hmac_sha256_init(hmac_sha256_ctx *, const void *, size_t); 96 | void hmac_sha256_update(hmac_sha256_ctx *, const void *, size_t); 97 | void hmac_sha256_final(unsigned char [32], hmac_sha256_ctx *); 98 | 99 | /** 100 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): 101 | * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and 102 | * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). 103 | */ 104 | void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, 105 | uint64_t, uint8_t *, size_t); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /src/crypto/sponge.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Header file for Blake2b's internal permutation in the form of a sponge. 3 | * This code is based on the original Blake2b's implementation provided by 4 | * Samuel Neves (https://blake2.net/) 5 | * 6 | * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014. 7 | * 8 | * This software is hereby placed in the public domain. 9 | * 10 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 11 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 14 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 16 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | #ifndef SPONGE_H_ 23 | #define SPONGE_H_ 24 | 25 | #include 26 | 27 | #if defined(__GNUC__) 28 | #define ALIGN __attribute__ ((aligned(32))) 29 | #elif defined(_MSC_VER) 30 | #define ALIGN __declspec(align(32)) 31 | #else 32 | #define ALIGN 33 | #endif 34 | 35 | 36 | /*Blake2b IV Array*/ 37 | static const uint64_t blake2b_IV[8] = 38 | { 39 | 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 40 | 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 41 | 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 42 | 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL 43 | }; 44 | 45 | /*Blake2b's rotation*/ 46 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ){ 47 | return ( w >> c ) | ( w << ( 64 - c ) ); 48 | } 49 | 50 | /*Blake2b's G function*/ 51 | #define G(r,i,a,b,c,d) \ 52 | do { \ 53 | a = a + b; \ 54 | d = rotr64(d ^ a, 32); \ 55 | c = c + d; \ 56 | b = rotr64(b ^ c, 24); \ 57 | a = a + b; \ 58 | d = rotr64(d ^ a, 16); \ 59 | c = c + d; \ 60 | b = rotr64(b ^ c, 63); \ 61 | } while(0) 62 | 63 | 64 | /*One Round of the Blake2b's compression function*/ 65 | #define ROUND_LYRA(r) \ 66 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ 67 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ 68 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \ 69 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \ 70 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \ 71 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \ 72 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ 73 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); 74 | 75 | 76 | //---- Housekeeping 77 | void initState(uint64_t state[/*16*/]); 78 | 79 | //---- Squeezes 80 | void squeeze(uint64_t *state, unsigned char *out, unsigned int len); 81 | void reducedSqueezeRow0(uint64_t* state, uint64_t* row, uint64_t nCols); 82 | 83 | //---- Absorbs 84 | void absorbBlock(uint64_t *state, const uint64_t *in); 85 | void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in); 86 | 87 | //---- Duplexes 88 | void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, uint64_t nCols); 89 | void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols); 90 | void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols); 91 | 92 | //---- Misc 93 | void printArray(unsigned char *array, unsigned int size, char *name); 94 | 95 | //////////////////////////////////////////////////////////////////////////////////////////////// 96 | 97 | 98 | ////TESTS//// 99 | //void reducedDuplexRowc(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut); 100 | //void reducedDuplexRowd(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut); 101 | //void reducedDuplexRowSetupv4(uint64_t *state, uint64_t *rowIn1, uint64_t *rowIn2, uint64_t *rowOut1, uint64_t *rowOut2); 102 | //void reducedDuplexRowSetupv5(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut); 103 | //void reducedDuplexRowSetupv5c(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut); 104 | //void reducedDuplexRowSetupv5d(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut); 105 | ///////////// 106 | 107 | 108 | #endif /* SPONGE_H_ */ 109 | -------------------------------------------------------------------------------- /src/crypto/wild_keccak.cpp: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | // Memory-hard extension of keccak for PoW 6 | // Copyright (c) 2014 The Boolberry developers 7 | // Distributed under the MIT/X11 software license, see the accompanying 8 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 9 | 10 | 11 | #include "wild_keccak.h" 12 | namespace crypto 13 | { 14 | 15 | const uint64_t keccakf_rndc[24] = 16 | { 17 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 18 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 19 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 20 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 21 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 22 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 23 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 24 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 25 | }; 26 | 27 | const int keccakf_rotc[24] = 28 | { 29 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 30 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 31 | }; 32 | 33 | const int keccakf_piln[24] = 34 | { 35 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 36 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 37 | }; 38 | 39 | // update the state with given number of rounds 40 | void regular_f::keccakf(uint64_t st[25], int rounds) 41 | { 42 | int i, j, round; 43 | uint64_t t, bc[5]; 44 | 45 | for (round = 0; round < rounds; round++) { 46 | 47 | // Theta 48 | for (i = 0; i < 5; i++) 49 | bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; 50 | 51 | for (i = 0; i < 5; i++) { 52 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 53 | for (j = 0; j < 25; j += 5) 54 | st[j + i] ^= t; 55 | } 56 | 57 | // Rho Pi 58 | t = st[1]; 59 | for (i = 0; i < 24; i++) { 60 | j = keccakf_piln[i]; 61 | bc[0] = st[j]; 62 | st[j] = ROTL64(t, keccakf_rotc[i]); 63 | t = bc[0]; 64 | } 65 | 66 | // Chi 67 | for (j = 0; j < 25; j += 5) { 68 | for (i = 0; i < 5; i++) 69 | bc[i] = st[j + i]; 70 | for (i = 0; i < 5; i++) 71 | st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; 72 | } 73 | 74 | // Iota 75 | st[0] ^= keccakf_rndc[round]; 76 | } 77 | } 78 | 79 | void mul_f::keccakf(uint64_t st[25], int rounds) 80 | { 81 | int i, j, round; 82 | uint64_t t, bc[5]; 83 | 84 | for (round = 0; round < rounds; round++) { 85 | 86 | // Theta 87 | for (i = 0; i < 5; i++) 88 | { 89 | bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] * st[i + 15] * st[i + 20];//surprise 90 | } 91 | 92 | for (i = 0; i < 5; i++) { 93 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 94 | for (j = 0; j < 25; j += 5) 95 | st[j + i] ^= t; 96 | } 97 | 98 | // Rho Pi 99 | t = st[1]; 100 | for (i = 0; i < 24; i++) { 101 | j = keccakf_piln[i]; 102 | bc[0] = st[j]; 103 | st[j] = ROTL64(t, keccakf_rotc[i]); 104 | t = bc[0]; 105 | } 106 | 107 | // Chi 108 | for (j = 0; j < 25; j += 5) { 109 | for (i = 0; i < 5; i++) 110 | bc[i] = st[j + i]; 111 | for (i = 0; i < 5; i++) 112 | st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; 113 | } 114 | 115 | // Iota 116 | st[0] ^= keccakf_rndc[round]; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/crypto/wild_keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | // Copyright (c) 2014 The Boolberry developers 5 | // Distributed under the MIT/X11 software license, see the accompanying 6 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 7 | 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include "hash.h" 14 | 15 | #ifndef KECCAK_ROUNDS 16 | #define KECCAK_ROUNDS 24 17 | #endif 18 | 19 | #ifndef ROTL64 20 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 21 | #endif 22 | 23 | // compute a keccak hash (md) of given byte length from "in" 24 | 25 | #define KK_MIXIN_SIZE 24 26 | 27 | namespace crypto 28 | { 29 | template 30 | pod_operand_a xor_pod(const pod_operand_a& a, const pod_operand_b& b) 31 | { 32 | static_assert(sizeof(pod_operand_a) == sizeof(pod_operand_b), "invalid xor_h usage: different sizes"); 33 | static_assert(sizeof(pod_operand_a)%8 == 0, "invalid xor_h usage: wrong size"); 34 | 35 | hash r; 36 | for(size_t i = 0; i != 4; i++) 37 | { 38 | ((uint64_t*)&r)[i] = ((const uint64_t*)&a)[i] ^ ((const uint64_t*)&b)[i]; 39 | } 40 | return r; 41 | } 42 | 43 | #define XOR_2(A, B) crypto::xor_pod(A, B) 44 | #define XOR_3(A, B, C) crypto::xor_pod(A, XOR_2(B, C)) 45 | #define XOR_4(A, B, C, D) crypto::xor_pod(A, XOR_3(B, C, D)) 46 | #define XOR_5(A, B, C, D, E) crypto::xor_pod(A, XOR_4(B, C, D, E)) 47 | #define XOR_8(A, B, C, D, F, G, H, I) crypto::xor_pod(XOR_4(A, B, C, D), XOR_4(F, G, H, I)) 48 | 49 | 50 | 51 | 52 | typedef uint64_t state_t_m[25]; 53 | typedef uint64_t mixin_t[KK_MIXIN_SIZE]; 54 | 55 | //with multiplication, for tests 56 | template 57 | int keccak_generic(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen) 58 | { 59 | state_t_m st; 60 | uint8_t temp[144]; 61 | size_t i, rsiz, rsizw; 62 | 63 | rsiz = sizeof(state_t_m) == mdlen ? (size_t)HASH_DATA_AREA : 200 - 2 * mdlen; 64 | rsizw = rsiz / 8; 65 | 66 | memset(st, 0, sizeof(st)); 67 | 68 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 69 | for (i = 0; i < rsizw; i++) 70 | st[i] ^= ((uint64_t *) in)[i]; 71 | f_traits::keccakf(st, KECCAK_ROUNDS); 72 | } 73 | 74 | 75 | // last block and padding 76 | memcpy(temp, in, inlen); 77 | temp[inlen++] = 1; 78 | memset(temp + inlen, 0, rsiz - inlen); 79 | temp[rsiz - 1] |= 0x80; 80 | 81 | for (i = 0; i < rsizw; i++) 82 | st[i] ^= ((uint64_t *) temp)[i]; 83 | 84 | f_traits::keccakf(st, KECCAK_ROUNDS); 85 | 86 | memcpy(md, st, mdlen); 87 | 88 | return 0; 89 | } 90 | 91 | template 92 | int wild_keccak(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) 93 | { 94 | state_t_m st; 95 | uint8_t temp[144]; 96 | size_t rsiz, rsizw; 97 | 98 | rsiz = sizeof(state_t_m) == mdlen ? (size_t)HASH_DATA_AREA : 200 - 2 * mdlen; 99 | rsizw = rsiz / 8; 100 | memset(&st[0], 0, 25*sizeof(st[0])); 101 | 102 | 103 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) 104 | { 105 | for (size_t i = 0; i < rsizw; i++) 106 | st[i] ^= ((uint64_t *) in)[i]; 107 | 108 | for(size_t ll = 0; ll != KECCAK_ROUNDS; ll++) 109 | { 110 | if(ll != 0) 111 | {//skip first round 112 | mixin_t mix_in; 113 | cb(st, mix_in); 114 | for (size_t k = 0; k < KK_MIXIN_SIZE; k++) 115 | st[k] ^= mix_in[k]; 116 | } 117 | f_traits::keccakf(st, 1); 118 | } 119 | } 120 | 121 | // last block and padding 122 | memcpy(temp, in, inlen); 123 | temp[inlen++] = 1; 124 | memset(temp + inlen, 0, rsiz - inlen); 125 | temp[rsiz - 1] |= 0x80; 126 | 127 | for (size_t i = 0; i < rsizw; i++) 128 | st[i] ^= ((uint64_t *) temp)[i]; 129 | 130 | for(size_t ll = 0; ll != KECCAK_ROUNDS; ll++) 131 | { 132 | if(ll != 0) 133 | {//skip first state with 134 | mixin_t mix_in; 135 | cb(st, mix_in); 136 | for (size_t k = 0; k < KK_MIXIN_SIZE; k++) 137 | st[k] ^= mix_in[k]; 138 | } 139 | f_traits::keccakf(st, 1); 140 | } 141 | 142 | memcpy(md, st, mdlen); 143 | 144 | return 0; 145 | } 146 | 147 | template 148 | int wild_keccak_dbl(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) 149 | { 150 | //Satoshi's classic 151 | wild_keccak(in, inlen, md, mdlen, cb); 152 | wild_keccak(md, mdlen, md, mdlen, cb); 153 | return 0; 154 | } 155 | 156 | class regular_f 157 | { 158 | public: 159 | static void keccakf(uint64_t st[25], int rounds); 160 | }; 161 | 162 | class mul_f 163 | { 164 | public: 165 | static void keccakf(uint64_t st[25], int rounds); 166 | }; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /src/crypto/yescrypt/yescrypt-best.c: -------------------------------------------------------------------------------- 1 | #ifdef __SSE2__ 2 | #include "yescrypt-simd.c" 3 | #else 4 | #include "yescrypt-opt.c" 5 | #endif 6 | -------------------------------------------------------------------------------- /src/crypto/yescrypt/yescrypt-platform.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2013,2014 Alexander Peslyak 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 9 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 12 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 13 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 14 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 16 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 17 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 18 | * SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef _WIN32 22 | #include 23 | #endif 24 | #include "yescrypt.h" 25 | #define HUGEPAGE_THRESHOLD (12 * 1024 * 1024) 26 | 27 | #ifdef __x86_64__ 28 | #define HUGEPAGE_SIZE (2 * 1024 * 1024) 29 | #else 30 | #undef HUGEPAGE_SIZE 31 | #endif 32 | 33 | static void * 34 | alloc_region(yescrypt_region_t * region, size_t size) 35 | { 36 | size_t base_size = size; 37 | uint8_t * base, * aligned; 38 | #ifdef MAP_ANON 39 | int flags = 40 | #ifdef MAP_NOCORE 41 | MAP_NOCORE | 42 | #endif 43 | MAP_ANON | MAP_PRIVATE; 44 | #if defined(MAP_HUGETLB) && defined(HUGEPAGE_SIZE) 45 | size_t new_size = size; 46 | const size_t hugepage_mask = (size_t)HUGEPAGE_SIZE - 1; 47 | if (size >= HUGEPAGE_THRESHOLD && size + hugepage_mask >= size) { 48 | flags |= MAP_HUGETLB; 49 | /* 50 | * Linux's munmap() fails on MAP_HUGETLB mappings if size is not a multiple of 51 | * huge page size, so let's round up to huge page size here. 52 | */ 53 | new_size = size + hugepage_mask; 54 | new_size &= ~hugepage_mask; 55 | } 56 | base = mmap(NULL, new_size, PROT_READ | PROT_WRITE, flags, -1, 0); 57 | if (base != MAP_FAILED) { 58 | base_size = new_size; 59 | } else 60 | if (flags & MAP_HUGETLB) { 61 | flags &= ~MAP_HUGETLB; 62 | base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); 63 | } 64 | 65 | #else 66 | base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); 67 | #endif 68 | if (base == MAP_FAILED) 69 | base = NULL; 70 | aligned = base; 71 | #elif defined(HAVE_POSIX_MEMALIGN) 72 | if ((errno = posix_memalign((void **)&base, 64, size)) != 0) 73 | base = NULL; 74 | aligned = base; 75 | #else 76 | base = aligned = NULL; 77 | if (size + 63 < size) { 78 | errno = ENOMEM; 79 | } else if ((base = malloc(size + 63)) != NULL) { 80 | aligned = base + 63; 81 | aligned -= (uintptr_t)aligned & 63; 82 | } 83 | #endif 84 | region->base = base; 85 | region->aligned = aligned; 86 | region->base_size = base ? base_size : 0; 87 | region->aligned_size = base ? size : 0; 88 | return aligned; 89 | } 90 | 91 | static inline void 92 | init_region(yescrypt_region_t * region) 93 | { 94 | region->base = region->aligned = NULL; 95 | region->base_size = region->aligned_size = 0; 96 | } 97 | 98 | static int 99 | free_region(yescrypt_region_t * region) 100 | { 101 | if (region->base) { 102 | #ifdef MAP_ANON 103 | if (munmap(region->base, region->base_size)) 104 | return -1; 105 | #else 106 | free(region->base); 107 | #endif 108 | } 109 | init_region(region); 110 | return 0; 111 | } 112 | 113 | int 114 | yescrypt_init_shared(yescrypt_shared_t * shared, 115 | const uint8_t * param, size_t paramlen, 116 | uint64_t N, uint32_t r, uint32_t p, 117 | yescrypt_init_shared_flags_t flags, uint32_t mask, 118 | uint8_t * buf, size_t buflen) 119 | { 120 | yescrypt_shared1_t * shared1 = &shared->shared1; 121 | yescrypt_shared_t dummy, half1, half2; 122 | uint8_t salt[32]; 123 | 124 | if (flags & YESCRYPT_SHARED_PREALLOCATED) { 125 | if (!shared1->aligned || !shared1->aligned_size) 126 | return -1; 127 | } else { 128 | init_region(shared1); 129 | } 130 | shared->mask1 = 1; 131 | if (!param && !paramlen && !N && !r && !p && !buf && !buflen) 132 | return 0; 133 | 134 | init_region(&dummy.shared1); 135 | dummy.mask1 = 1; 136 | if (yescrypt_kdf(&dummy, shared1, 137 | param, paramlen, NULL, 0, N, r, p, 0, 138 | YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, 139 | salt, sizeof(salt))) 140 | goto out; 141 | 142 | half1 = half2 = *shared; 143 | half1.shared1.aligned_size /= 2; 144 | half2.shared1.aligned = (char *)half2.shared1.aligned + half1.shared1.aligned_size; 145 | half2.shared1.aligned_size = half1.shared1.aligned_size; 146 | N /= 2; 147 | 148 | if (p > 1 && yescrypt_kdf(&half1, &half2.shared1, 149 | param, paramlen, salt, sizeof(salt), N, r, p, 0, 150 | YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_2, 151 | salt, sizeof(salt))) 152 | goto out; 153 | 154 | if (yescrypt_kdf(&half2, &half1.shared1, 155 | param, paramlen, salt, sizeof(salt), N, r, p, 0, 156 | YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, 157 | salt, sizeof(salt))) 158 | goto out; 159 | 160 | if (yescrypt_kdf(&half1, &half2.shared1, 161 | param, paramlen, salt, sizeof(salt), N, r, p, 0, 162 | YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, 163 | buf, buflen)) 164 | goto out; 165 | 166 | shared->mask1 = mask; 167 | 168 | return 0; 169 | 170 | out: 171 | if (!(flags & YESCRYPT_SHARED_PREALLOCATED)) 172 | free_region(shared1); 173 | return -1; 174 | } 175 | 176 | int 177 | yescrypt_free_shared(yescrypt_shared_t * shared) 178 | { 179 | return free_region(&shared->shared1); 180 | } 181 | 182 | int 183 | yescrypt_init_local(yescrypt_local_t * local) 184 | { 185 | init_region(local); 186 | return 0; 187 | } 188 | 189 | int 190 | yescrypt_free_local(yescrypt_local_t * local) 191 | { 192 | return free_region(local); 193 | } 194 | -------------------------------------------------------------------------------- /src/cryptonight.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTONIGHT_H 2 | #define CRYPTONIGHT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void cryptonight_hash(const char* input, char* output, uint32_t len, int variant, uint64_t height); 11 | void cryptonight_fast_hash(const char* input, char* output, uint32_t len); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/cryptonight_fast.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTONIGHTFAST_H 2 | #define CRYPTONIGHTFAST_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void cryptonightfast_hash(const char* input, char* output, uint32_t len, int variant); 11 | void cryptonightfast_fast_hash(const char* input, char* output, uint32_t len); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/fresh.c: -------------------------------------------------------------------------------- 1 | #include "fresh.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_shavite.h" 8 | #include "sha3/sph_simd.h" 9 | #include "sha3/sph_echo.h" 10 | 11 | void fresh_hash(const char* input, char* output, uint32_t len) 12 | { 13 | sph_shavite512_context ctx_shavite1; 14 | sph_simd512_context ctx_simd1; 15 | sph_echo512_context ctx_echo1; 16 | 17 | //these uint512 in the c++ source of the client are backed by an array of uint32 18 | uint32_t hashA[16], hashB[16]; 19 | 20 | sph_shavite512_init (&ctx_shavite1); 21 | sph_shavite512 (&ctx_shavite1, input, len); 22 | sph_shavite512_close(&ctx_shavite1, hashA); 23 | 24 | sph_simd512_init (&ctx_simd1); 25 | sph_simd512 (&ctx_simd1, hashA, 64); 26 | sph_simd512_close(&ctx_simd1, hashB); 27 | 28 | sph_shavite512_init (&ctx_shavite1); 29 | sph_shavite512 (&ctx_shavite1, hashB, 64); 30 | sph_shavite512_close(&ctx_shavite1, hashA); 31 | 32 | sph_simd512_init (&ctx_simd1); 33 | sph_simd512 (&ctx_simd1, hashA, 64); 34 | sph_simd512_close(&ctx_simd1, hashB); 35 | 36 | sph_echo512_init (&ctx_echo1); 37 | sph_echo512 (&ctx_echo1, hashB, 64); 38 | sph_echo512_close(&ctx_echo1, hashA); 39 | 40 | memcpy(output, hashA, 32); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/fresh.h: -------------------------------------------------------------------------------- 1 | #ifndef FRESH_H 2 | #define FRESH_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void fresh_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/fugue.c: -------------------------------------------------------------------------------- 1 | #include "fugue.h" 2 | 3 | #include "sha3/sph_fugue.h" 4 | 5 | void fugue_hash(const char* input, char* output, uint32_t len) 6 | { 7 | sph_fugue256_context ctx_fugue; 8 | sph_fugue256_init(&ctx_fugue); 9 | sph_fugue256(&ctx_fugue, input, len); 10 | sph_fugue256_close(&ctx_fugue, output); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/fugue.h: -------------------------------------------------------------------------------- 1 | #ifndef FUGUE_H 2 | #define FUGUE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void fugue_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/groestl.c: -------------------------------------------------------------------------------- 1 | #include "groestl.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_groestl.h" 8 | #include "sha256.h" 9 | 10 | void groestl_hash(const char* input, char* output, uint32_t len) 11 | { 12 | char hash1[64]; 13 | char hash2[64]; 14 | 15 | sph_groestl512_context ctx_groestl; 16 | sph_groestl512_init(&ctx_groestl); 17 | sph_groestl512(&ctx_groestl, input, len); 18 | sph_groestl512_close(&ctx_groestl, &hash1); 19 | 20 | sph_groestl512(&ctx_groestl, hash1, 64); 21 | sph_groestl512_close(&ctx_groestl, &hash2); 22 | 23 | memcpy(output, &hash2, 32); 24 | } 25 | 26 | void groestlmyriad_hash(const char* input, char* output, uint32_t len) 27 | { 28 | char temp[64]; 29 | 30 | sph_groestl512_context ctx_groestl; 31 | sph_groestl512_init(&ctx_groestl); 32 | sph_groestl512(&ctx_groestl, input, len); 33 | sph_groestl512_close(&ctx_groestl, &temp); 34 | 35 | sha256_ctx ctx_sha256; 36 | sha256_init(&ctx_sha256); 37 | sha256_update(&ctx_sha256, &temp, 64); 38 | sha256_final((unsigned char*) output, &ctx_sha256); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/groestl.h: -------------------------------------------------------------------------------- 1 | #ifndef GROESTL_H 2 | #define GROESTL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void groestl_hash(const char* input, char* output, uint32_t len); 11 | void groestlmyriad_hash(const char* input, char* output, uint32_t len); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/hefty1.c: -------------------------------------------------------------------------------- 1 | #include "hefty1.h" 2 | 3 | #include "sha3/sph_hefty1.h" 4 | #include "sha3/sph_keccak.h" 5 | #include "sha3/sph_groestl.h" 6 | #include "sha3/sph_blake.h" 7 | #include "sha256.h" 8 | 9 | void hefty1_hash(const char* input, char* output, uint32_t len) 10 | { 11 | HEFTY1_CTX ctx_hefty1; 12 | sha256_ctx ctx_sha256; 13 | sph_keccak512_context ctx_keccak; 14 | sph_groestl512_context ctx_groestl; 15 | sph_blake512_context ctx_blake; 16 | 17 | char hash32_1[32]; 18 | char hash32_2[32]; 19 | char hash64_3[64]; 20 | char hash64_4[64]; 21 | char hash64_5[64]; 22 | 23 | HEFTY1_Init(&ctx_hefty1); 24 | HEFTY1_Update(&ctx_hefty1, (const void*) input, len); 25 | HEFTY1_Final((unsigned char*) &hash32_1, &ctx_hefty1); // 1 26 | 27 | sha256_init(&ctx_sha256); 28 | sha256_update(&ctx_sha256, (const void*) input, len); 29 | sha256_update(&ctx_sha256, (unsigned char*) &hash32_1, 32); // 1 30 | sha256_final((unsigned char*) &hash32_2, &ctx_sha256); // 2 31 | 32 | sph_keccak512_init(&ctx_keccak); 33 | sph_keccak512(&ctx_keccak, (const void*) input, len); 34 | sph_keccak512(&ctx_keccak, (unsigned char*) &hash32_1, 32); //1 35 | sph_keccak512_close(&ctx_keccak, (void*) &hash64_3); // 3 36 | 37 | sph_groestl512_init(&ctx_groestl); 38 | sph_groestl512(&ctx_groestl, (const void*) input, len); 39 | sph_groestl512(&ctx_groestl, (unsigned char*) &hash32_1, 32); // 1 40 | sph_groestl512_close(&ctx_groestl, (void*) &hash64_4); // 4 41 | 42 | sph_blake512_init(&ctx_blake); 43 | sph_blake512(&ctx_blake, (const void*) input, len); 44 | sph_blake512(&ctx_blake, (unsigned char*) &hash32_1, 32); // 1 45 | sph_blake512_close(&ctx_blake, (void*) &hash64_5); // 5 46 | 47 | memset(output, 0, 32); 48 | 49 | char* hash[4] = { hash32_2, hash64_3, hash64_4, hash64_5 }; 50 | 51 | uint32_t i; 52 | uint32_t j; 53 | 54 | #define OUTPUT_BIT (i * 4 + j) 55 | 56 | for(i = 0; i < 64; i++) { 57 | for(j = 0; j < 4; j++) { 58 | if((*(hash[j] + (i / 8)) & (0x80 >> (i % 8))) != 0) 59 | *(output + (OUTPUT_BIT / 8)) |= 0x80 >> (OUTPUT_BIT % 8); 60 | } 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/hefty1.h: -------------------------------------------------------------------------------- 1 | #ifndef HEFTY1_H 2 | #define HEFTY1_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void hefty1_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/keccak.c: -------------------------------------------------------------------------------- 1 | #include "keccak.h" 2 | 3 | #include "sha3/sph_types.h" 4 | #include "sha3/sph_keccak.h" 5 | 6 | 7 | void keccak_hash(const char* input, char* output, uint32_t size) 8 | { 9 | sph_keccak256_context ctx_keccak; 10 | sph_keccak256_init(&ctx_keccak); 11 | sph_keccak256 (&ctx_keccak, input, size);//80); 12 | sph_keccak256_close(&ctx_keccak, output); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/keccak.h: -------------------------------------------------------------------------------- 1 | #ifndef KECCAK_H 2 | #define KECCAK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void keccak_hash(const char* input, char* output, uint32_t size); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/lbry.c: -------------------------------------------------------------------------------- 1 | #include "lbry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_sha2.h" 8 | #include "sha3/sph_ripemd.h" 9 | 10 | void lbry_hash(const char* input, char* output, uint32_t len) 11 | { 12 | uint32_t hashA[16] = { 0 }, hashB[8], hashC[8]; 13 | 14 | //lbry hash is designed to hash exactly 112 bytes (block header size) 15 | //so only calculate a hash if 112 bytes are available 16 | if(len >= 112) { 17 | sph_sha256_context ctx_sha256; 18 | sph_sha512_context ctx_sha512; 19 | sph_ripemd160_context ctx_ripemd; 20 | 21 | sph_sha256_init(&ctx_sha256); 22 | sph_sha512_init(&ctx_sha512); 23 | sph_ripemd160_init(&ctx_ripemd); 24 | 25 | sph_sha256(&ctx_sha256, input, len); 26 | sph_sha256_close(&ctx_sha256, hashA); 27 | 28 | sph_sha256(&ctx_sha256, hashA, 32); 29 | sph_sha256_close(&ctx_sha256, hashA); 30 | 31 | sph_sha512(&ctx_sha512, hashA, 32); 32 | sph_sha512_close(&ctx_sha512, hashA); 33 | 34 | sph_ripemd160(&ctx_ripemd, hashA, 32); 35 | sph_ripemd160_close(&ctx_ripemd, hashB); 36 | 37 | sph_ripemd160(&ctx_ripemd, &hashA[8], 32); 38 | sph_ripemd160_close(&ctx_ripemd, hashC); 39 | 40 | sph_sha256(&ctx_sha256, hashB, 20); 41 | sph_sha256(&ctx_sha256, hashC, 20); 42 | sph_sha256_close(&ctx_sha256, hashA); 43 | 44 | sph_sha256(&ctx_sha256, hashA, 32); 45 | sph_sha256_close(&ctx_sha256, hashA); 46 | } 47 | 48 | memcpy(output, hashA, 32); 49 | } 50 | -------------------------------------------------------------------------------- /src/lbry.h: -------------------------------------------------------------------------------- 1 | #ifndef LBRY_H 2 | #define LBRY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | void lbry_hash(const char* input, char* output, uint32_t len); 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/lyra2re.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar, 2014 James Lovejoy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "lyra2re.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "sha3/sph_blake.h" 36 | #include "sha3/sph_groestl.h" 37 | #include "sha3/sph_cubehash.h" 38 | #include "sha3/sph_bmw.h" 39 | #include "sha3/sph_keccak.h" 40 | #include "sha3/sph_skein.h" 41 | #include "crypto/lyra2.h" 42 | 43 | void lyra2re_hash(const char* input, char* output, uint32_t len) 44 | { 45 | sph_blake256_context ctx_blake; 46 | sph_groestl256_context ctx_groestl; 47 | sph_keccak256_context ctx_keccak; 48 | sph_skein256_context ctx_skein; 49 | 50 | uint32_t hashA[8], hashB[8]; 51 | 52 | sph_blake256_set_rounds(14); 53 | sph_blake256_init(&ctx_blake); 54 | sph_blake256 (&ctx_blake, input, len); 55 | sph_blake256_close (&ctx_blake, hashA); 56 | 57 | sph_keccak256_init(&ctx_keccak); 58 | sph_keccak256 (&ctx_keccak,hashA, 32); 59 | sph_keccak256_close(&ctx_keccak, hashB); 60 | 61 | LYRA2_old(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 62 | 63 | sph_skein256_init(&ctx_skein); 64 | sph_skein256 (&ctx_skein, hashA, 32); 65 | sph_skein256_close(&ctx_skein, hashB); 66 | 67 | sph_groestl256_init(&ctx_groestl); 68 | sph_groestl256 (&ctx_groestl, hashB, 32); 69 | sph_groestl256_close(&ctx_groestl, hashA); 70 | 71 | memcpy(output, hashA, 32); 72 | } 73 | 74 | void lyra2rev2_hash(const char* input, char* output, uint32_t len) 75 | { 76 | sph_blake256_context ctx_blake; 77 | sph_cubehash256_context ctx_cubehash; 78 | sph_keccak256_context ctx_keccak; 79 | sph_skein256_context ctx_skein; 80 | sph_bmw256_context ctx_bmw; 81 | 82 | uint32_t hashA[8], hashB[8]; 83 | 84 | sph_blake256_set_rounds(14); 85 | sph_blake256_init(&ctx_blake); 86 | sph_blake256(&ctx_blake, input, len); 87 | sph_blake256_close (&ctx_blake, hashA); 88 | 89 | sph_keccak256_init(&ctx_keccak); 90 | sph_keccak256(&ctx_keccak, hashA, 32); 91 | sph_keccak256_close(&ctx_keccak, hashB); 92 | 93 | sph_cubehash256_init(&ctx_cubehash); 94 | sph_cubehash256(&ctx_cubehash, hashB, 32); 95 | sph_cubehash256_close(&ctx_cubehash, hashA); 96 | 97 | LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); 98 | 99 | sph_skein256_init(&ctx_skein); 100 | sph_skein256(&ctx_skein, hashB, 32); 101 | sph_skein256_close(&ctx_skein, hashA); 102 | 103 | sph_cubehash256_init(&ctx_cubehash); 104 | sph_cubehash256(&ctx_cubehash, hashA, 32); 105 | sph_cubehash256_close(&ctx_cubehash, hashB); 106 | 107 | sph_bmw256_init(&ctx_bmw); 108 | sph_bmw256(&ctx_bmw, hashB, 32); 109 | sph_bmw256_close(&ctx_bmw, hashA); 110 | 111 | memcpy(output, hashA, 32); 112 | } 113 | 114 | void lyra2rev3_hash(const char* input, char* output, uint32_t len) 115 | { 116 | sph_blake256_context ctx_blake; 117 | sph_cubehash256_context ctx_cubehash; 118 | 119 | sph_bmw256_context ctx_bmw; 120 | 121 | uint32_t hashA[8], hashB[8]; 122 | 123 | sph_blake256_set_rounds(14); 124 | sph_blake256_init(&ctx_blake); 125 | sph_blake256(&ctx_blake, input, len); 126 | sph_blake256_close (&ctx_blake, hashA); 127 | 128 | LYRA2_3(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); 129 | 130 | sph_cubehash256_init(&ctx_cubehash); 131 | sph_cubehash256(&ctx_cubehash, hashB, 32); 132 | sph_cubehash256_close(&ctx_cubehash, hashA); 133 | 134 | LYRA2_3(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); 135 | 136 | sph_bmw256_init(&ctx_bmw); 137 | sph_bmw256(&ctx_bmw, hashB, 32); 138 | sph_bmw256_close(&ctx_bmw, hashA); 139 | 140 | memcpy(output, hashA, 32); 141 | } 142 | -------------------------------------------------------------------------------- /src/lyra2re.h: -------------------------------------------------------------------------------- 1 | #ifndef LYRA2RE_H 2 | #define LYRA2RE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void lyra2re_hash(const char* input, char* output, uint32_t _len); 11 | void lyra2rev2_hash(const char* input, char* output, uint32_t _len); 12 | void lyra2rev3_hash(const char* input, char* output, uint32_t _len); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/lyra2z.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar, 2017 Zcoin Developers 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "lyra2z.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "sha3/sph_blake.h" 36 | #include "lyra2.h" 37 | 38 | void lyra2z_hash(const char* input, char* output, uint32_t len) 39 | { 40 | sph_blake256_context ctx_blake; 41 | 42 | uint32_t hashA[8], hashB[8]; 43 | 44 | sph_blake256_set_rounds(14); 45 | sph_blake256_init(&ctx_blake); 46 | sph_blake256 (&ctx_blake, input, len); 47 | sph_blake256_close (&ctx_blake, hashA); 48 | 49 | LYRA2(hashB, 32, hashA, 32, hashA, 32, 8, 8, 8); 50 | 51 | memcpy(output, hashB, 32); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/lyra2z.h: -------------------------------------------------------------------------------- 1 | #ifndef LYRA2Z_H 2 | #define LYRA2Z_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void lyra2z_hash(const char* input, char* output, uint32_t _len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/neoscrypt.h: -------------------------------------------------------------------------------- 1 | #if (__cplusplus) 2 | extern "C" { 3 | #endif 4 | 5 | void neoscrypt(const char *input, char *output, int profile); 6 | 7 | //void neoscrypt(const unsigned char *password, unsigned char *output, 8 | // unsigned int profile); 9 | 10 | void neoscrypt_blake2s(const void *input, const unsigned int input_size, 11 | const void *key, const unsigned char key_size, 12 | void *output, const unsigned char output_size); 13 | 14 | void neoscrypt_copy(void *dstp, const void *srcp, unsigned int len); 15 | void neoscrypt_erase(void *dstp, unsigned int len); 16 | void neoscrypt_xor(void *dstp, const void *srcp, unsigned int len); 17 | 18 | #if defined(NEOSCRYPT_ASM) && defined(NEOSCRYPT_MINER_4WAY) 19 | void neoscrypt_4way(const unsigned char *password, unsigned char *output, 20 | unsigned char *scratchpad); 21 | 22 | #ifdef NEOSCRYPT_SHA256 23 | void scrypt_4way(const unsigned char *password, unsigned char *output, 24 | unsigned char *scratchpad); 25 | #endif 26 | 27 | void neoscrypt_blake2s_4way(const unsigned char *input, 28 | const unsigned char *key, unsigned char *output); 29 | 30 | void neoscrypt_fastkdf_4way(const unsigned char *password, 31 | const unsigned char *salt, unsigned char *output, unsigned char *scratchpad, 32 | const unsigned int mode); 33 | #endif 34 | 35 | unsigned int cpu_vec_exts(void); 36 | 37 | #if (__cplusplus) 38 | } 39 | #else 40 | 41 | typedef unsigned long long ullong; 42 | typedef signed long long llong; 43 | typedef unsigned int uint; 44 | typedef unsigned char uchar; 45 | 46 | #ifndef MIN 47 | #define MIN(a, b) ((a) < (b) ? a : b) 48 | #endif 49 | 50 | #ifndef MAX 51 | #define MAX(a, b) ((a) > (b) ? a : b) 52 | #endif 53 | 54 | #define BLOCK_SIZE 64 55 | #define DIGEST_SIZE 32 56 | 57 | typedef uchar hash_digest[DIGEST_SIZE]; 58 | 59 | #define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b))) 60 | #define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b))) 61 | 62 | #define U8TO32_BE(p) \ 63 | (((uint)((p)[0]) << 24) | ((uint)((p)[1]) << 16) | \ 64 | ((uint)((p)[2]) << 8) | ((uint)((p)[3]))) 65 | 66 | #define U32TO8_BE(p, v) \ 67 | (p)[0] = (uchar)((v) >> 24); (p)[1] = (uchar)((v) >> 16); \ 68 | (p)[2] = (uchar)((v) >> 8); (p)[3] = (uchar)((v) ); 69 | 70 | #define U64TO8_BE(p, v) \ 71 | U32TO8_BE((p), (uint)((v) >> 32)); \ 72 | U32TO8_BE((p) + 4, (uint)((v) )); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/nist5.c: -------------------------------------------------------------------------------- 1 | #include "nist5.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_jh.h" 10 | #include "sha3/sph_keccak.h" 11 | #include "sha3/sph_skein.h" 12 | 13 | 14 | void nist5_hash(const char* input, char* output, uint32_t len) 15 | { 16 | sph_blake512_context ctx_blake; 17 | sph_groestl512_context ctx_groestl; 18 | sph_skein512_context ctx_skein; 19 | sph_jh512_context ctx_jh; 20 | sph_keccak512_context ctx_keccak; 21 | 22 | //these uint512 in the c++ source of the client are backed by an array of uint32 23 | uint32_t hash[16]; 24 | 25 | sph_blake512_init(&ctx_blake); 26 | sph_blake512 (&ctx_blake, input, len); 27 | sph_blake512_close (&ctx_blake, hash); 28 | 29 | sph_groestl512_init(&ctx_groestl); 30 | sph_groestl512 (&ctx_groestl, hash, 64); 31 | sph_groestl512_close(&ctx_groestl, hash); 32 | 33 | sph_jh512_init(&ctx_jh); 34 | sph_jh512 (&ctx_jh, hash, 64); 35 | sph_jh512_close(&ctx_jh, hash); 36 | 37 | sph_keccak512_init(&ctx_keccak); 38 | sph_keccak512 (&ctx_keccak, hash, 64); 39 | sph_keccak512_close(&ctx_keccak, hash); 40 | 41 | sph_skein512_init(&ctx_skein); 42 | sph_skein512 (&ctx_skein, hash, 64); 43 | sph_skein512_close (&ctx_skein, hash); 44 | 45 | memcpy(output, hash, 32); 46 | } -------------------------------------------------------------------------------- /src/nist5.h: -------------------------------------------------------------------------------- 1 | #ifndef NIST5_H 2 | #define NIST5_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void nist5_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /src/quark.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar, 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "quark.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "sha3/sph_blake.h" 36 | #include "sha3/sph_bmw.h" 37 | #include "sha3/sph_groestl.h" 38 | #include "sha3/sph_jh.h" 39 | #include "sha3/sph_keccak.h" 40 | #include "sha3/sph_skein.h" 41 | 42 | void quark_hash(const char* input, char* output, uint32_t len) 43 | { 44 | sph_blake512_context ctx_blake; 45 | sph_bmw512_context ctx_bmw; 46 | sph_groestl512_context ctx_groestl; 47 | sph_jh512_context ctx_jh; 48 | sph_keccak512_context ctx_keccak; 49 | sph_skein512_context ctx_skein; 50 | 51 | uint32_t mask = 8; 52 | uint32_t zero = 0; 53 | 54 | uint32_t hashA[16], hashB[16]; 55 | 56 | 57 | 58 | sph_blake512_init(&ctx_blake); 59 | sph_blake512 (&ctx_blake, input, len); 60 | sph_blake512_close (&ctx_blake, hashA); //0 61 | 62 | 63 | sph_bmw512_init(&ctx_bmw); 64 | sph_bmw512 (&ctx_bmw, hashA, 64); //0 65 | sph_bmw512_close(&ctx_bmw, hashB); //1 66 | 67 | 68 | if ((hashB[0] & mask) != zero) //1 69 | { 70 | sph_groestl512_init(&ctx_groestl); 71 | sph_groestl512 (&ctx_groestl, hashB, 64); //1 72 | sph_groestl512_close(&ctx_groestl, hashA); //2 73 | } 74 | else 75 | { 76 | sph_skein512_init(&ctx_skein); 77 | sph_skein512 (&ctx_skein, hashB, 64); //1 78 | sph_skein512_close(&ctx_skein, hashA); //2 79 | } 80 | 81 | 82 | sph_groestl512_init(&ctx_groestl); 83 | sph_groestl512 (&ctx_groestl, hashA, 64); //2 84 | sph_groestl512_close(&ctx_groestl, hashB); //3 85 | 86 | sph_jh512_init(&ctx_jh); 87 | sph_jh512 (&ctx_jh, hashB, 64); //3 88 | sph_jh512_close(&ctx_jh, hashA); //4 89 | 90 | if ((hashA[0] & mask) != zero) //4 91 | { 92 | sph_blake512_init(&ctx_blake); 93 | sph_blake512 (&ctx_blake, hashA, 64); // 94 | sph_blake512_close(&ctx_blake, hashB); //5 95 | } 96 | else 97 | { 98 | sph_bmw512_init(&ctx_bmw); 99 | sph_bmw512 (&ctx_bmw, hashA, 64); //4 100 | sph_bmw512_close(&ctx_bmw, hashB); //5 101 | } 102 | 103 | sph_keccak512_init(&ctx_keccak); 104 | sph_keccak512 (&ctx_keccak,hashB, 64); //5 105 | sph_keccak512_close(&ctx_keccak, hashA); //6 106 | 107 | sph_skein512_init(&ctx_skein); 108 | sph_skein512 (&ctx_skein, hashA, 64); //6 109 | sph_skein512_close(&ctx_skein, hashB); //7 110 | 111 | if ((hashB[0] & mask) != zero) //7 112 | { 113 | sph_keccak512_init(&ctx_keccak); 114 | sph_keccak512 (&ctx_keccak, hashB, 64); // 115 | sph_keccak512_close(&ctx_keccak, hashA); //8 116 | } 117 | else 118 | { 119 | sph_jh512_init(&ctx_jh); 120 | sph_jh512 (&ctx_jh, hashB, 64); //7 121 | sph_jh512_close(&ctx_jh, hashA); //8 122 | } 123 | 124 | 125 | 126 | memcpy(output, hashA, 32); 127 | 128 | 129 | /* 130 | printf("result: "); 131 | for (ii=0; ii < 32; ii++) 132 | { 133 | printf ("%.2x",((uint8_t*)output)[ii]); 134 | } 135 | printf ("\n"); 136 | */ 137 | 138 | 139 | 140 | 141 | } 142 | 143 | 144 | -------------------------------------------------------------------------------- /src/quark.h: -------------------------------------------------------------------------------- 1 | #ifndef QUARK_H 2 | #define QUARK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void quark_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/qubit.c: -------------------------------------------------------------------------------- 1 | #include "qubit.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_cubehash.h" 7 | #include "sha3/sph_luffa.h" 8 | #include "sha3/sph_shavite.h" 9 | #include "sha3/sph_simd.h" 10 | #include "sha3/sph_echo.h" 11 | 12 | void qubit_hash(const char* input, char* output, uint32_t len) 13 | { 14 | sph_luffa512_context ctx_luffa; 15 | sph_cubehash512_context ctx_cubehash; 16 | sph_shavite512_context ctx_shavite; 17 | sph_simd512_context ctx_simd; 18 | sph_echo512_context ctx_echo; 19 | 20 | char hash1[64]; 21 | char hash2[64]; 22 | 23 | sph_luffa512_init(&ctx_luffa); 24 | sph_luffa512(&ctx_luffa, (const void*) input, len); 25 | sph_luffa512_close(&ctx_luffa, (void*) &hash1); // 1 26 | 27 | sph_cubehash512_init(&ctx_cubehash); 28 | sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64); // 1 29 | sph_cubehash512_close(&ctx_cubehash, (void*) &hash2); // 2 30 | 31 | sph_shavite512_init(&ctx_shavite); 32 | sph_shavite512(&ctx_shavite, (const void*) &hash2, 64); // 3 33 | sph_shavite512_close(&ctx_shavite, (void*) &hash1); // 4 34 | 35 | sph_simd512_init(&ctx_simd); 36 | sph_simd512(&ctx_simd, (const void*) &hash1, 64); // 4 37 | sph_simd512_close(&ctx_simd, (void*) &hash2); // 5 38 | 39 | sph_echo512_init(&ctx_echo); 40 | sph_echo512(&ctx_echo, (const void*) &hash2, 64); // 5 41 | sph_echo512_close(&ctx_echo, (void*) &hash1); // 6 42 | 43 | memcpy(output, &hash1, 32); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/qubit.h: -------------------------------------------------------------------------------- 1 | #ifndef QUBIT_H 2 | #define QUBIT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void qubit_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/scryptjane.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRYPT_JANE_H 2 | #define SCRYPT_JANE_H 3 | 4 | #include 5 | 6 | #define SCRYPT_KECCAK512 7 | #define SCRYPT_CHACHA 8 | #define SCRYPT_CHOOSE_COMPILETIME 9 | 10 | /* 11 | Nfactor: Increases CPU & Memory Hardness 12 | N = (1 << (Nfactor + 1)): How many times to mix a chunk and how many temporary chunks are used 13 | 14 | rfactor: Increases Memory Hardness 15 | r = (1 << rfactor): How large a chunk is 16 | 17 | pfactor: Increases CPU Hardness 18 | p = (1 << pfactor): Number of times to mix the main chunk 19 | 20 | A block is the basic mixing unit (salsa/chacha block = 64 bytes) 21 | A chunk is (2 * r) blocks 22 | 23 | ~Memory used = (N + 2) * ((2 * r) * block size) 24 | */ 25 | 26 | #include 27 | 28 | typedef void (*scrypt_fatal_errorfn)(const char *msg); 29 | void scrypt_set_fatal_error(scrypt_fatal_errorfn fn); 30 | 31 | void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char Nfactor, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes); 32 | 33 | unsigned char GetNfactorJane(int nTimestamp, int nChainStartTime, int nMin, int nMax); 34 | void scryptjane_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char Nfactor); 35 | 36 | #endif /* SCRYPT_JANE_H */ 37 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-chacha.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "ChaCha20/8" 2 | 3 | typedef uint32_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U32TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 64 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_chacha-avx.h" 15 | #include "scrypt-jane-mix_chacha-ssse3.h" 16 | #include "scrypt-jane-mix_chacha-sse2.h" 17 | #include "scrypt-jane-mix_chacha.h" 18 | 19 | #if defined(SCRYPT_CHACHA_AVX) 20 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 21 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 22 | #define SCRYPT_MIX_FN chacha_core_avx 23 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 24 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 25 | #include "scrypt-jane-romix-template.h" 26 | #endif 27 | 28 | #if defined(SCRYPT_CHACHA_SSSE3) 29 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3 30 | #define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3 31 | #define SCRYPT_MIX_FN chacha_core_ssse3 32 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 33 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 34 | #include "scrypt-jane-romix-template.h" 35 | #endif 36 | 37 | #if defined(SCRYPT_CHACHA_SSE2) 38 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 39 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 40 | #define SCRYPT_MIX_FN chacha_core_sse2 41 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 42 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 43 | #include "scrypt-jane-romix-template.h" 44 | #endif 45 | 46 | /* cpu agnostic */ 47 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 48 | #define SCRYPT_MIX_FN chacha_core_basic 49 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 50 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 51 | #include "scrypt-jane-romix-template.h" 52 | 53 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 54 | static scrypt_ROMixfn 55 | scrypt_getROMix() { 56 | size_t cpuflags = detect_cpu(); 57 | 58 | #if defined(SCRYPT_CHACHA_AVX) 59 | if (cpuflags & cpu_avx) 60 | return scrypt_ROMix_avx; 61 | else 62 | #endif 63 | 64 | #if defined(SCRYPT_CHACHA_SSSE3) 65 | if (cpuflags & cpu_ssse3) 66 | return scrypt_ROMix_ssse3; 67 | else 68 | #endif 69 | 70 | #if defined(SCRYPT_CHACHA_SSE2) 71 | if (cpuflags & cpu_sse2) 72 | return scrypt_ROMix_sse2; 73 | else 74 | #endif 75 | 76 | return scrypt_ROMix_basic; 77 | } 78 | #endif 79 | 80 | 81 | #if defined(SCRYPT_TEST_SPEED) 82 | static size_t 83 | available_implementations() { 84 | size_t flags = 0; 85 | 86 | #if defined(SCRYPT_CHACHA_AVX) 87 | flags |= cpu_avx; 88 | #endif 89 | 90 | #if defined(SCRYPT_CHACHA_SSSE3) 91 | flags |= cpu_ssse3; 92 | #endif 93 | 94 | #if defined(SCRYPT_CHACHA_SSE2) 95 | flags |= cpu_sse2; 96 | #endif 97 | 98 | return flags; 99 | } 100 | #endif 101 | 102 | static int 103 | scrypt_test_mix() { 104 | static const uint8_t expected[16] = { 105 | 0x48,0x2b,0x2d,0xb8,0xa1,0x33,0x22,0x73,0xcd,0x16,0xc4,0xb4,0xb0,0x7f,0xb1,0x8a, 106 | }; 107 | 108 | int ret = 1; 109 | size_t cpuflags = detect_cpu(); 110 | 111 | #if defined(SCRYPT_CHACHA_AVX) 112 | if (cpuflags & cpu_avx) 113 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, scrypt_romix_nop, scrypt_romix_nop, expected); 114 | #endif 115 | 116 | #if defined(SCRYPT_CHACHA_SSSE3) 117 | if (cpuflags & cpu_ssse3) 118 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, scrypt_romix_nop, scrypt_romix_nop, expected); 119 | #endif 120 | 121 | #if defined(SCRYPT_CHACHA_SSE2) 122 | if (cpuflags & cpu_sse2) 123 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, scrypt_romix_nop, scrypt_romix_nop, expected); 124 | #endif 125 | 126 | #if defined(SCRYPT_CHACHA_BASIC) 127 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 128 | #endif 129 | 130 | return ret; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-hash.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_BLAKE512) 2 | #include "scrypt-jane-hash_blake512.h" 3 | #elif defined(SCRYPT_BLAKE256) 4 | #include "scrypt-jane-hash_blake256.h" 5 | #elif defined(SCRYPT_SHA512) 6 | #include "scrypt-jane-hash_sha512.h" 7 | #elif defined(SCRYPT_SHA256) 8 | #include "scrypt-jane-hash_sha256.h" 9 | #elif defined(SCRYPT_SKEIN512) 10 | #include "scrypt-jane-hash_skein512.h" 11 | #elif defined(SCRYPT_KECCAK512) || defined(SCRYPT_KECCAK256) 12 | #include "scrypt-jane-hash_keccak.h" 13 | #else 14 | #define SCRYPT_HASH "ERROR" 15 | #define SCRYPT_HASH_BLOCK_SIZE 64 16 | #define SCRYPT_HASH_DIGEST_SIZE 64 17 | typedef struct scrypt_hash_state_t { size_t dummy; } scrypt_hash_state; 18 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 19 | static void scrypt_hash_init(scrypt_hash_state *S) {} 20 | static void scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) {} 21 | static void scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) {} 22 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = {0}; 23 | #error must define a hash function! 24 | #endif 25 | 26 | #include "scrypt-jane-pbkdf2.h" 27 | 28 | #define SCRYPT_TEST_HASH_LEN 257 /* (2 * largest block size) + 1 */ 29 | 30 | static int 31 | scrypt_test_hash() { 32 | scrypt_hash_state st; 33 | scrypt_hash_digest hash, final; 34 | uint8_t msg[SCRYPT_TEST_HASH_LEN]; 35 | size_t i; 36 | 37 | for (i = 0; i < SCRYPT_TEST_HASH_LEN; i++) 38 | msg[i] = (uint8_t)i; 39 | 40 | scrypt_hash_init(&st); 41 | for (i = 0; i < SCRYPT_TEST_HASH_LEN + 1; i++) { 42 | scrypt_hash(hash, msg, i); 43 | scrypt_hash_update(&st, hash, sizeof(hash)); 44 | } 45 | scrypt_hash_finish(&st, final); 46 | return scrypt_verify(final, scrypt_test_hash_expected, SCRYPT_HASH_DIGEST_SIZE); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-hash_keccak.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_KECCAK256) 2 | #define SCRYPT_HASH "Keccak-256" 3 | #define SCRYPT_HASH_DIGEST_SIZE 32 4 | #else 5 | #define SCRYPT_HASH "Keccak-512" 6 | #define SCRYPT_HASH_DIGEST_SIZE 64 7 | #endif 8 | #define SCRYPT_KECCAK_F 1600 9 | #define SCRYPT_KECCAK_C (SCRYPT_HASH_DIGEST_SIZE * 8 * 2) /* 256=512, 512=1024 */ 10 | #define SCRYPT_KECCAK_R (SCRYPT_KECCAK_F - SCRYPT_KECCAK_C) /* 256=1088, 512=576 */ 11 | #define SCRYPT_HASH_BLOCK_SIZE (SCRYPT_KECCAK_R / 8) 12 | 13 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 14 | 15 | typedef struct scrypt_hash_state_t { 16 | uint64_t state[SCRYPT_KECCAK_F / 64]; 17 | uint32_t leftover; 18 | uint8_t buffer[SCRYPT_HASH_BLOCK_SIZE]; 19 | } scrypt_hash_state; 20 | 21 | static const uint64_t keccak_round_constants[24] = { 22 | 0x0000000000000001ull, 0x0000000000008082ull, 23 | 0x800000000000808aull, 0x8000000080008000ull, 24 | 0x000000000000808bull, 0x0000000080000001ull, 25 | 0x8000000080008081ull, 0x8000000000008009ull, 26 | 0x000000000000008aull, 0x0000000000000088ull, 27 | 0x0000000080008009ull, 0x000000008000000aull, 28 | 0x000000008000808bull, 0x800000000000008bull, 29 | 0x8000000000008089ull, 0x8000000000008003ull, 30 | 0x8000000000008002ull, 0x8000000000000080ull, 31 | 0x000000000000800aull, 0x800000008000000aull, 32 | 0x8000000080008081ull, 0x8000000000008080ull, 33 | 0x0000000080000001ull, 0x8000000080008008ull 34 | }; 35 | 36 | static void 37 | keccak_block(scrypt_hash_state *S, const uint8_t *in) { 38 | size_t i; 39 | uint64_t *s = S->state, t[5], u[5], v, w; 40 | 41 | /* absorb input */ 42 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE / 8; i++, in += 8) 43 | s[i] ^= U8TO64_LE(in); 44 | 45 | for (i = 0; i < 24; i++) { 46 | /* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */ 47 | t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20]; 48 | t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21]; 49 | t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22]; 50 | t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23]; 51 | t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24]; 52 | 53 | /* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */ 54 | u[0] = t[4] ^ ROTL64(t[1], 1); 55 | u[1] = t[0] ^ ROTL64(t[2], 1); 56 | u[2] = t[1] ^ ROTL64(t[3], 1); 57 | u[3] = t[2] ^ ROTL64(t[4], 1); 58 | u[4] = t[3] ^ ROTL64(t[0], 1); 59 | 60 | /* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */ 61 | s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0]; 62 | s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1]; 63 | s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2]; 64 | s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3]; 65 | s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4]; 66 | 67 | /* rho pi: b[..] = rotl(a[..], ..) */ 68 | v = s[ 1]; 69 | s[ 1] = ROTL64(s[ 6], 44); 70 | s[ 6] = ROTL64(s[ 9], 20); 71 | s[ 9] = ROTL64(s[22], 61); 72 | s[22] = ROTL64(s[14], 39); 73 | s[14] = ROTL64(s[20], 18); 74 | s[20] = ROTL64(s[ 2], 62); 75 | s[ 2] = ROTL64(s[12], 43); 76 | s[12] = ROTL64(s[13], 25); 77 | s[13] = ROTL64(s[19], 8); 78 | s[19] = ROTL64(s[23], 56); 79 | s[23] = ROTL64(s[15], 41); 80 | s[15] = ROTL64(s[ 4], 27); 81 | s[ 4] = ROTL64(s[24], 14); 82 | s[24] = ROTL64(s[21], 2); 83 | s[21] = ROTL64(s[ 8], 55); 84 | s[ 8] = ROTL64(s[16], 45); 85 | s[16] = ROTL64(s[ 5], 36); 86 | s[ 5] = ROTL64(s[ 3], 28); 87 | s[ 3] = ROTL64(s[18], 21); 88 | s[18] = ROTL64(s[17], 15); 89 | s[17] = ROTL64(s[11], 10); 90 | s[11] = ROTL64(s[ 7], 6); 91 | s[ 7] = ROTL64(s[10], 3); 92 | s[10] = ROTL64( v, 1); 93 | 94 | /* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */ 95 | v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w; 96 | v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w; 97 | v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w; 98 | v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w; 99 | v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w; 100 | 101 | /* iota: a[0,0] ^= round constant */ 102 | s[0] ^= keccak_round_constants[i]; 103 | } 104 | } 105 | 106 | static void 107 | scrypt_hash_init(scrypt_hash_state *S) { 108 | memset(S, 0, sizeof(*S)); 109 | } 110 | 111 | static void 112 | scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) { 113 | size_t want; 114 | 115 | /* handle the previous data */ 116 | if (S->leftover) { 117 | want = (SCRYPT_HASH_BLOCK_SIZE - S->leftover); 118 | want = (want < inlen) ? want : inlen; 119 | memcpy(S->buffer + S->leftover, in, want); 120 | S->leftover += (uint32_t)want; 121 | if (S->leftover < SCRYPT_HASH_BLOCK_SIZE) 122 | return; 123 | in += want; 124 | inlen -= want; 125 | keccak_block(S, S->buffer); 126 | } 127 | 128 | /* handle the current data */ 129 | while (inlen >= SCRYPT_HASH_BLOCK_SIZE) { 130 | keccak_block(S, in); 131 | in += SCRYPT_HASH_BLOCK_SIZE; 132 | inlen -= SCRYPT_HASH_BLOCK_SIZE; 133 | } 134 | 135 | /* handle leftover data */ 136 | S->leftover = (uint32_t)inlen; 137 | if (S->leftover) 138 | memcpy(S->buffer, in, S->leftover); 139 | } 140 | 141 | static void 142 | scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) { 143 | size_t i; 144 | 145 | S->buffer[S->leftover] = 0x01; 146 | memset(S->buffer + (S->leftover + 1), 0, SCRYPT_HASH_BLOCK_SIZE - (S->leftover + 1)); 147 | S->buffer[SCRYPT_HASH_BLOCK_SIZE - 1] |= 0x80; 148 | keccak_block(S, S->buffer); 149 | 150 | for (i = 0; i < SCRYPT_HASH_DIGEST_SIZE; i += 8) { 151 | U64TO8_LE(&hash[i], S->state[i / 8]); 152 | } 153 | } 154 | 155 | #if defined(SCRYPT_KECCAK256) 156 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 157 | 0x26,0xb7,0x10,0xb3,0x66,0xb1,0xd1,0xb1,0x25,0xfc,0x3e,0xe3,0x1e,0x33,0x1d,0x19, 158 | 0x94,0xaa,0x63,0x7a,0xd5,0x77,0x29,0xb4,0x27,0xe9,0xe0,0xf4,0x19,0xba,0x68,0xea, 159 | }; 160 | #else 161 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 162 | 0x17,0xc7,0x8c,0xa0,0xd9,0x08,0x1d,0xba,0x8a,0xc8,0x3e,0x07,0x90,0xda,0x91,0x88, 163 | 0x25,0xbd,0xd3,0xf8,0x78,0x4a,0x8d,0x5e,0xe4,0x96,0x9c,0x01,0xf3,0xeb,0xdc,0x12, 164 | 0xea,0x35,0x57,0xba,0x94,0xb8,0xe9,0xb9,0x27,0x45,0x0a,0x48,0x5c,0x3d,0x69,0xf0, 165 | 0xdb,0x22,0x38,0xb5,0x52,0x22,0x29,0xea,0x7a,0xb2,0xe6,0x07,0xaa,0x37,0x4d,0xe6, 166 | }; 167 | #endif 168 | 169 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-hash_sha256.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_HASH "SHA-2-256" 2 | #define SCRYPT_HASH_BLOCK_SIZE 64 3 | #define SCRYPT_HASH_DIGEST_SIZE 32 4 | 5 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 6 | 7 | typedef struct scrypt_hash_state_t { 8 | uint32_t H[8]; 9 | uint64_t T; 10 | uint32_t leftover; 11 | uint8_t buffer[SCRYPT_HASH_BLOCK_SIZE]; 12 | } scrypt_hash_state; 13 | 14 | static const uint32_t sha256_constants[64] = { 15 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 16 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 17 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 18 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 19 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 20 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 21 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 22 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 23 | }; 24 | 25 | #define Ch(x,y,z) (z ^ (x & (y ^ z))) 26 | #define Maj(x,y,z) (((x | y) & z) | (x & y)) 27 | #define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22)) 28 | #define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25)) 29 | #define G0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ (x >> 3)) 30 | #define G1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ (x >> 10)) 31 | #define W0(in,i) (U8TO32_BE(&in[i * 4])) 32 | #define W1(i) (G1(w[i - 2]) + w[i - 7] + G0(w[i - 15]) + w[i - 16]) 33 | #define STEP(i) \ 34 | t1 = S0(r[0]) + Maj(r[0], r[1], r[2]); \ 35 | t0 = r[7] + S1(r[4]) + Ch(r[4], r[5], r[6]) + sha256_constants[i] + w[i]; \ 36 | r[7] = r[6]; \ 37 | r[6] = r[5]; \ 38 | r[5] = r[4]; \ 39 | r[4] = r[3] + t0; \ 40 | r[3] = r[2]; \ 41 | r[2] = r[1]; \ 42 | r[1] = r[0]; \ 43 | r[0] = t0 + t1; 44 | 45 | static void 46 | sha256_blocks(scrypt_hash_state *S, const uint8_t *in, size_t blocks) { 47 | uint32_t r[8], w[64], t0, t1; 48 | size_t i; 49 | 50 | for (i = 0; i < 8; i++) r[i] = S->H[i]; 51 | 52 | while (blocks--) { 53 | for (i = 0; i < 16; i++) { w[i] = W0(in, i); } 54 | for (i = 16; i < 64; i++) { w[i] = W1(i); } 55 | for (i = 0; i < 64; i++) { STEP(i); } 56 | for (i = 0; i < 8; i++) { r[i] += S->H[i]; S->H[i] = r[i]; } 57 | S->T += SCRYPT_HASH_BLOCK_SIZE * 8; 58 | in += SCRYPT_HASH_BLOCK_SIZE; 59 | } 60 | } 61 | 62 | static void 63 | scrypt_hash_init(scrypt_hash_state *S) { 64 | S->H[0] = 0x6a09e667; 65 | S->H[1] = 0xbb67ae85; 66 | S->H[2] = 0x3c6ef372; 67 | S->H[3] = 0xa54ff53a; 68 | S->H[4] = 0x510e527f; 69 | S->H[5] = 0x9b05688c; 70 | S->H[6] = 0x1f83d9ab; 71 | S->H[7] = 0x5be0cd19; 72 | S->T = 0; 73 | S->leftover = 0; 74 | } 75 | 76 | static void 77 | scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) { 78 | size_t blocks, want; 79 | 80 | /* handle the previous data */ 81 | if (S->leftover) { 82 | want = (SCRYPT_HASH_BLOCK_SIZE - S->leftover); 83 | want = (want < inlen) ? want : inlen; 84 | memcpy(S->buffer + S->leftover, in, want); 85 | S->leftover += (uint32_t)want; 86 | if (S->leftover < SCRYPT_HASH_BLOCK_SIZE) 87 | return; 88 | in += want; 89 | inlen -= want; 90 | sha256_blocks(S, S->buffer, 1); 91 | } 92 | 93 | /* handle the current data */ 94 | blocks = (inlen & ~(SCRYPT_HASH_BLOCK_SIZE - 1)); 95 | S->leftover = (uint32_t)(inlen - blocks); 96 | if (blocks) { 97 | sha256_blocks(S, in, blocks / SCRYPT_HASH_BLOCK_SIZE); 98 | in += blocks; 99 | } 100 | 101 | /* handle leftover data */ 102 | if (S->leftover) 103 | memcpy(S->buffer, in, S->leftover); 104 | } 105 | 106 | static void 107 | scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) { 108 | uint64_t t = S->T + (S->leftover * 8); 109 | 110 | S->buffer[S->leftover] = 0x80; 111 | if (S->leftover <= 55) { 112 | memset(S->buffer + S->leftover + 1, 0, 55 - S->leftover); 113 | } else { 114 | memset(S->buffer + S->leftover + 1, 0, 63 - S->leftover); 115 | sha256_blocks(S, S->buffer, 1); 116 | memset(S->buffer, 0, 56); 117 | } 118 | 119 | U64TO8_BE(S->buffer + 56, t); 120 | sha256_blocks(S, S->buffer, 1); 121 | 122 | U32TO8_BE(&hash[ 0], S->H[0]); 123 | U32TO8_BE(&hash[ 4], S->H[1]); 124 | U32TO8_BE(&hash[ 8], S->H[2]); 125 | U32TO8_BE(&hash[12], S->H[3]); 126 | U32TO8_BE(&hash[16], S->H[4]); 127 | U32TO8_BE(&hash[20], S->H[5]); 128 | U32TO8_BE(&hash[24], S->H[6]); 129 | U32TO8_BE(&hash[28], S->H[7]); 130 | } 131 | 132 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 133 | 0xee,0x36,0xae,0xa6,0x65,0xf0,0x28,0x7d,0xc9,0xde,0xd8,0xad,0x48,0x33,0x7d,0xbf, 134 | 0xcb,0xc0,0x48,0xfa,0x5f,0x92,0xfd,0x0a,0x95,0x6f,0x34,0x8e,0x8c,0x1e,0x73,0xad, 135 | }; 136 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-mix_chacha.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_CHACHA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "ChaCha20/8 Ref" 5 | 6 | #undef SCRYPT_CHACHA_INCLUDED 7 | #define SCRYPT_CHACHA_INCLUDED 8 | #define SCRYPT_CHACHA_BASIC 9 | 10 | static void 11 | chacha_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | a += b; t = d^a; d = ROTL32(t,16); \ 34 | c += d; t = b^c; b = ROTL32(t,12); \ 35 | a += b; t = d^a; d = ROTL32(t, 8); \ 36 | c += d; t = b^c; b = ROTL32(t, 7); 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x1, x5, x9,x13) 41 | quarter( x2, x6,x10,x14) 42 | quarter( x3, x7,x11,x15) 43 | quarter( x0, x5,x10,x15) 44 | quarter( x1, x6,x11,x12) 45 | quarter( x2, x7, x8,x13) 46 | quarter( x3, x4, x9,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-mix_salsa.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "Salsa20/8 Ref" 5 | 6 | #undef SCRYPT_SALSA_INCLUDED 7 | #define SCRYPT_SALSA_INCLUDED 8 | #define SCRYPT_SALSA_BASIC 9 | 10 | static void 11 | salsa_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | t = a+d; t = ROTL32(t, 7); b ^= t; \ 34 | t = b+a; t = ROTL32(t, 9); c ^= t; \ 35 | t = c+b; t = ROTL32(t, 13); d ^= t; \ 36 | t = d+c; t = ROTL32(t, 18); a ^= t; \ 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x5, x9,x13, x1) 41 | quarter(x10,x14, x2, x6) 42 | quarter(x15, x3, x7,x11) 43 | quarter( x0, x1, x2, x3) 44 | quarter( x5, x6, x7, x4) 45 | quarter(x10,x11, x8, x9) 46 | quarter(x15,x12,x13,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-mix_salsa64.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA64_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "Salsa64/8 Ref" 5 | 6 | #undef SCRYPT_SALSA64_INCLUDED 7 | #define SCRYPT_SALSA64_INCLUDED 8 | #define SCRYPT_SALSA64_BASIC 9 | 10 | static void 11 | salsa64_core_basic(uint64_t state[16]) { 12 | const size_t rounds = 8; 13 | uint64_t v[16], t; 14 | size_t i; 15 | 16 | for (i = 0; i < 16; i++) v[i] = state[i]; 17 | 18 | #define G(a,b,c,d) \ 19 | t = v[a]+v[d]; t = ROTL64(t, 32); v[b] ^= t; \ 20 | t = v[b]+v[a]; t = ROTL64(t, 13); v[c] ^= t; \ 21 | t = v[c]+v[b]; t = ROTL64(t, 39); v[d] ^= t; \ 22 | t = v[d]+v[c]; t = ROTL64(t, 32); v[a] ^= t; \ 23 | 24 | for (i = 0; i < rounds; i += 2) { 25 | G( 0, 4, 8,12); 26 | G( 5, 9,13, 1); 27 | G(10,14, 2, 6); 28 | G(15, 3, 7,11); 29 | G( 0, 1, 2, 3); 30 | G( 5, 6, 7, 4); 31 | G(10,11, 8, 9); 32 | G(15,12,13,14); 33 | } 34 | 35 | for (i = 0; i < 16; i++) state[i] += v[i]; 36 | 37 | #undef G 38 | } 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-pbkdf2.h: -------------------------------------------------------------------------------- 1 | typedef struct scrypt_hmac_state_t { 2 | scrypt_hash_state inner, outer; 3 | } scrypt_hmac_state; 4 | 5 | 6 | static void 7 | scrypt_hash(scrypt_hash_digest hash, const uint8_t *m, size_t mlen) { 8 | scrypt_hash_state st; 9 | scrypt_hash_init(&st); 10 | scrypt_hash_update(&st, m, mlen); 11 | scrypt_hash_finish(&st, hash); 12 | } 13 | 14 | /* hmac */ 15 | static void 16 | scrypt_hmac_init(scrypt_hmac_state *st, const uint8_t *key, size_t keylen) { 17 | uint8_t pad[SCRYPT_HASH_BLOCK_SIZE] = {0}; 18 | size_t i; 19 | 20 | scrypt_hash_init(&st->inner); 21 | scrypt_hash_init(&st->outer); 22 | 23 | if (keylen <= SCRYPT_HASH_BLOCK_SIZE) { 24 | /* use the key directly if it's <= blocksize bytes */ 25 | memcpy(pad, key, keylen); 26 | } else { 27 | /* if it's > blocksize bytes, hash it */ 28 | scrypt_hash(pad, key, keylen); 29 | } 30 | 31 | /* inner = (key ^ 0x36) */ 32 | /* h(inner || ...) */ 33 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) 34 | pad[i] ^= 0x36; 35 | scrypt_hash_update(&st->inner, pad, SCRYPT_HASH_BLOCK_SIZE); 36 | 37 | /* outer = (key ^ 0x5c) */ 38 | /* h(outer || ...) */ 39 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) 40 | pad[i] ^= (0x5c ^ 0x36); 41 | scrypt_hash_update(&st->outer, pad, SCRYPT_HASH_BLOCK_SIZE); 42 | 43 | scrypt_ensure_zero(pad, sizeof(pad)); 44 | } 45 | 46 | static void 47 | scrypt_hmac_update(scrypt_hmac_state *st, const uint8_t *m, size_t mlen) { 48 | /* h(inner || m...) */ 49 | scrypt_hash_update(&st->inner, m, mlen); 50 | } 51 | 52 | static void 53 | scrypt_hmac_finish(scrypt_hmac_state *st, scrypt_hash_digest mac) { 54 | /* h(inner || m) */ 55 | scrypt_hash_digest innerhash; 56 | scrypt_hash_finish(&st->inner, innerhash); 57 | 58 | /* h(outer || h(inner || m)) */ 59 | scrypt_hash_update(&st->outer, innerhash, sizeof(innerhash)); 60 | scrypt_hash_finish(&st->outer, mac); 61 | 62 | scrypt_ensure_zero(st, sizeof(*st)); 63 | } 64 | 65 | static void 66 | scrypt_pbkdf2(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint64_t N, uint8_t *out, size_t bytes) { 67 | scrypt_hmac_state hmac_pw, hmac_pw_salt, work; 68 | scrypt_hash_digest ti, u; 69 | uint8_t be[4]; 70 | uint32_t i, j, blocks; 71 | uint64_t c; 72 | 73 | /* bytes must be <= (0xffffffff - (SCRYPT_HASH_DIGEST_SIZE - 1)), which they will always be under scrypt */ 74 | 75 | /* hmac(password, ...) */ 76 | scrypt_hmac_init(&hmac_pw, password, password_len); 77 | 78 | /* hmac(password, salt...) */ 79 | hmac_pw_salt = hmac_pw; 80 | scrypt_hmac_update(&hmac_pw_salt, salt, salt_len); 81 | 82 | blocks = ((uint32_t)bytes + (SCRYPT_HASH_DIGEST_SIZE - 1)) / SCRYPT_HASH_DIGEST_SIZE; 83 | for (i = 1; i <= blocks; i++) { 84 | /* U1 = hmac(password, salt || be(i)) */ 85 | U32TO8_BE(be, i); 86 | work = hmac_pw_salt; 87 | scrypt_hmac_update(&work, be, 4); 88 | scrypt_hmac_finish(&work, ti); 89 | memcpy(u, ti, sizeof(u)); 90 | 91 | /* T[i] = U1 ^ U2 ^ U3... */ 92 | for (c = 0; c < N - 1; c++) { 93 | /* UX = hmac(password, U{X-1}) */ 94 | work = hmac_pw; 95 | scrypt_hmac_update(&work, u, SCRYPT_HASH_DIGEST_SIZE); 96 | scrypt_hmac_finish(&work, u); 97 | 98 | /* T[i] ^= UX */ 99 | for (j = 0; j < sizeof(u); j++) 100 | ti[j] ^= u[j]; 101 | } 102 | 103 | memcpy(out, ti, (bytes > SCRYPT_HASH_DIGEST_SIZE) ? SCRYPT_HASH_DIGEST_SIZE : bytes); 104 | out += SCRYPT_HASH_DIGEST_SIZE; 105 | bytes -= SCRYPT_HASH_DIGEST_SIZE; 106 | } 107 | 108 | scrypt_ensure_zero(ti, sizeof(ti)); 109 | scrypt_ensure_zero(u, sizeof(u)); 110 | scrypt_ensure_zero(&hmac_pw, sizeof(hmac_pw)); 111 | scrypt_ensure_zero(&hmac_pw_salt, sizeof(hmac_pw_salt)); 112 | } 113 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-romix-basic.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 2 | /* function type returned by scrypt_getROMix, used with cpu detection */ 3 | typedef void (FASTCALL *scrypt_ROMixfn)(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r); 4 | #endif 5 | 6 | /* romix pre/post nop function */ 7 | static void asm_calling_convention 8 | scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) { 9 | (void)blocks; (void)nblocks; 10 | } 11 | 12 | /* romix pre/post endian conversion function */ 13 | static void asm_calling_convention 14 | scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) { 15 | #if !defined(CPU_LE) 16 | static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}}; 17 | size_t i; 18 | if (endian_test.w == 0x100) { 19 | nblocks *= SCRYPT_BLOCK_WORDS; 20 | for (i = 0; i < nblocks; i++) { 21 | SCRYPT_WORD_ENDIAN_SWAP(blocks[i]); 22 | } 23 | } 24 | #else 25 | (void)blocks; (void)nblocks; 26 | #endif 27 | } 28 | 29 | /* chunkmix test function */ 30 | typedef void (asm_calling_convention *chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r); 31 | typedef void (asm_calling_convention *blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks); 32 | 33 | static int 34 | scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) { 35 | /* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */ 36 | const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS; 37 | #if (defined(X86ASM_AVX2) || defined(X86_64ASM_AVX2) || defined(X86_INTRINSIC_AVX2)) 38 | scrypt_mix_word_t ALIGN(32) chunk[2][4 * SCRYPT_BLOCK_WORDS], v; 39 | #else 40 | scrypt_mix_word_t ALIGN(16) chunk[2][4 * SCRYPT_BLOCK_WORDS], v; 41 | #endif 42 | uint8_t final[16]; 43 | size_t i; 44 | 45 | for (i = 0; i < words; i++) { 46 | v = (scrypt_mix_word_t)i; 47 | v = (v << 8) | v; 48 | v = (v << 16) | v; 49 | chunk[0][i] = v; 50 | } 51 | 52 | prefn(chunk[0], blocks); 53 | mixfn(chunk[1], chunk[0], NULL, r); 54 | postfn(chunk[1], blocks); 55 | 56 | /* grab the last 16 bytes of the final block */ 57 | for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) { 58 | SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]); 59 | } 60 | 61 | return scrypt_verify(expected, final, 16); 62 | } 63 | 64 | /* returns a pointer to item i, where item is len scrypt_mix_word_t's long */ 65 | static scrypt_mix_word_t * 66 | scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) { 67 | return base + (i * len); 68 | } 69 | 70 | /* returns a pointer to block i */ 71 | static scrypt_mix_word_t * 72 | scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) { 73 | return base + (i * SCRYPT_BLOCK_WORDS); 74 | } 75 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-romix-template.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_HAVE_ROMIX) 2 | 3 | #if defined(SCRYPT_CHOOSE_COMPILETIME) 4 | #undef SCRYPT_ROMIX_FN 5 | #define SCRYPT_ROMIX_FN scrypt_ROMix 6 | #endif 7 | 8 | #undef SCRYPT_HAVE_ROMIX 9 | #define SCRYPT_HAVE_ROMIX 10 | 11 | #if !defined(SCRYPT_CHUNKMIX_FN) 12 | 13 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_basic 14 | 15 | /* 16 | Bout = ChunkMix(Bin) 17 | 18 | 2*r: number of blocks in the chunk 19 | */ 20 | static void asm_calling_convention 21 | SCRYPT_CHUNKMIX_FN(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r) { 22 | #if (defined(X86ASM_AVX2) || defined(X86_64ASM_AVX2) || defined(X86_INTRINSIC_AVX2)) 23 | scrypt_mix_word_t ALIGN(32) X[SCRYPT_BLOCK_WORDS], *block; 24 | #else 25 | scrypt_mix_word_t ALIGN(16) X[SCRYPT_BLOCK_WORDS], *block; 26 | #endif 27 | uint32_t i, j, blocksPerChunk = r * 2, half = 0; 28 | 29 | /* 1: X = B_{2r - 1} */ 30 | block = scrypt_block(Bin, blocksPerChunk - 1); 31 | for (i = 0; i < SCRYPT_BLOCK_WORDS; i++) 32 | X[i] = block[i]; 33 | 34 | if (Bxor) { 35 | block = scrypt_block(Bxor, blocksPerChunk - 1); 36 | for (i = 0; i < SCRYPT_BLOCK_WORDS; i++) 37 | X[i] ^= block[i]; 38 | } 39 | 40 | /* 2: for i = 0 to 2r - 1 do */ 41 | for (i = 0; i < blocksPerChunk; i++, half ^= r) { 42 | /* 3: X = H(X ^ B_i) */ 43 | block = scrypt_block(Bin, i); 44 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 45 | X[j] ^= block[j]; 46 | 47 | if (Bxor) { 48 | block = scrypt_block(Bxor, i); 49 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 50 | X[j] ^= block[j]; 51 | } 52 | SCRYPT_MIX_FN(X); 53 | 54 | /* 4: Y_i = X */ 55 | /* 6: B'[0..r-1] = Y_even */ 56 | /* 6: B'[r..2r-1] = Y_odd */ 57 | block = scrypt_block(Bout, (i / 2) + half); 58 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 59 | block[j] = X[j]; 60 | } 61 | } 62 | #endif 63 | 64 | /* 65 | X = ROMix(X) 66 | 67 | X: chunk to mix 68 | Y: scratch chunk 69 | N: number of rounds 70 | V[N]: array of chunks to randomly index in to 71 | 2*r: number of blocks in a chunk 72 | */ 73 | 74 | static void NOINLINE FASTCALL 75 | SCRYPT_ROMIX_FN(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[N * chunkWords]*/, uint32_t N, uint32_t r) { 76 | uint32_t i, j, chunkWords = (uint32_t)(SCRYPT_BLOCK_WORDS * r * 2); 77 | scrypt_mix_word_t *block = V; 78 | 79 | SCRYPT_ROMIX_TANGLE_FN(X, r * 2); 80 | 81 | /* 1: X = B */ 82 | /* implicit */ 83 | 84 | /* 2: for i = 0 to N - 1 do */ 85 | memcpy(block, X, chunkWords * sizeof(scrypt_mix_word_t)); 86 | for (i = 0; i < N - 1; i++, block += chunkWords) { 87 | /* 3: V_i = X */ 88 | /* 4: X = H(X) */ 89 | SCRYPT_CHUNKMIX_FN(block + chunkWords, block, NULL, r); 90 | } 91 | SCRYPT_CHUNKMIX_FN(X, block, NULL, r); 92 | 93 | /* 6: for i = 0 to N - 1 do */ 94 | for (i = 0; i < N; i += 2) { 95 | /* 7: j = Integerify(X) % N */ 96 | j = X[chunkWords - SCRYPT_BLOCK_WORDS] & (N - 1); 97 | 98 | /* 8: X = H(Y ^ V_j) */ 99 | SCRYPT_CHUNKMIX_FN(Y, X, scrypt_item(V, j, chunkWords), r); 100 | 101 | /* 7: j = Integerify(Y) % N */ 102 | j = Y[chunkWords - SCRYPT_BLOCK_WORDS] & (N - 1); 103 | 104 | /* 8: X = H(Y ^ V_j) */ 105 | SCRYPT_CHUNKMIX_FN(X, Y, scrypt_item(V, j, chunkWords), r); 106 | } 107 | 108 | /* 10: B' = X */ 109 | /* implicit */ 110 | 111 | SCRYPT_ROMIX_UNTANGLE_FN(X, r * 2); 112 | } 113 | 114 | #endif /* !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_HAVE_ROMIX) */ 115 | 116 | 117 | #undef SCRYPT_CHUNKMIX_FN 118 | #undef SCRYPT_ROMIX_FN 119 | #undef SCRYPT_MIX_FN 120 | #undef SCRYPT_ROMIX_TANGLE_FN 121 | #undef SCRYPT_ROMIX_UNTANGLE_FN 122 | 123 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-romix.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_CHACHA) 2 | #include "scrypt-jane-chacha.h" 3 | #elif defined(SCRYPT_SALSA) 4 | #include "scrypt-jane-salsa.h" 5 | #elif defined(SCRYPT_SALSA64) 6 | #include "scrypt-jane-salsa64.h" 7 | #else 8 | #define SCRYPT_MIX_BASE "ERROR" 9 | typedef uint32_t scrypt_mix_word_t; 10 | #define SCRYPT_WORDTO8_LE U32TO8_LE 11 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 12 | #define SCRYPT_BLOCK_BYTES 64 13 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 14 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 15 | static void FASTCALL scrypt_ROMix_error(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r) {} 16 | static scrypt_ROMixfn scrypt_getROMix() { return scrypt_ROMix_error; } 17 | #else 18 | static void FASTCALL scrypt_ROMix(scrypt_mix_word_t *X, scrypt_mix_word_t *Y, scrypt_mix_word_t *V, uint32_t N, uint32_t r) {} 19 | #endif 20 | static int scrypt_test_mix() { return 0; } 21 | #error must define a mix function! 22 | #endif 23 | 24 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 25 | #undef SCRYPT_MIX 26 | #define SCRYPT_MIX SCRYPT_MIX_BASE 27 | #endif 28 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-salsa.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "Salsa20/8" 2 | 3 | typedef uint32_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U32TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 64 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_salsa-avx.h" 15 | #include "scrypt-jane-mix_salsa-sse2.h" 16 | #include "scrypt-jane-mix_salsa.h" 17 | 18 | #if defined(SCRYPT_SALSA_AVX) 19 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 20 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 21 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 22 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 23 | #include "scrypt-jane-romix-template.h" 24 | #endif 25 | 26 | #if defined(SCRYPT_SALSA_SSE2) 27 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 28 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 29 | #define SCRYPT_MIX_FN salsa_core_sse2 30 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 31 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 32 | #include "scrypt-jane-romix-template.h" 33 | #endif 34 | 35 | /* cpu agnostic */ 36 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 37 | #define SCRYPT_MIX_FN salsa_core_basic 38 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 39 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 40 | #include "scrypt-jane-romix-template.h" 41 | 42 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 43 | static scrypt_ROMixfn 44 | scrypt_getROMix() { 45 | size_t cpuflags = detect_cpu(); 46 | 47 | #if defined(SCRYPT_SALSA_AVX) 48 | if (cpuflags & cpu_avx) 49 | return scrypt_ROMix_avx; 50 | else 51 | #endif 52 | 53 | #if defined(SCRYPT_SALSA_SSE2) 54 | if (cpuflags & cpu_sse2) 55 | return scrypt_ROMix_sse2; 56 | else 57 | #endif 58 | 59 | return scrypt_ROMix_basic; 60 | } 61 | #endif 62 | 63 | 64 | #if defined(SCRYPT_TEST_SPEED) 65 | static size_t 66 | available_implementations() { 67 | size_t flags = 0; 68 | 69 | #if defined(SCRYPT_SALSA_AVX) 70 | flags |= cpu_avx; 71 | #endif 72 | 73 | #if defined(SCRYPT_SALSA_SSE2) 74 | flags |= cpu_sse2; 75 | #endif 76 | 77 | return flags; 78 | } 79 | #endif 80 | 81 | 82 | static int 83 | scrypt_test_mix() { 84 | static const uint8_t expected[16] = { 85 | 0x41,0x1f,0x2e,0xa3,0xab,0xa3,0x1a,0x34,0x87,0x1d,0x8a,0x1c,0x76,0xa0,0x27,0x66, 86 | }; 87 | 88 | int ret = 1; 89 | size_t cpuflags = detect_cpu(); 90 | 91 | #if defined(SCRYPT_SALSA_AVX) 92 | if (cpuflags & cpu_avx) 93 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 94 | #endif 95 | 96 | #if defined(SCRYPT_SALSA_SSE2) 97 | if (cpuflags & cpu_sse2) 98 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 99 | #endif 100 | 101 | #if defined(SCRYPT_SALSA_BASIC) 102 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 103 | #endif 104 | 105 | return ret; 106 | } 107 | -------------------------------------------------------------------------------- /src/scryptjane/scrypt-jane-salsa64.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "Salsa64/8" 2 | 3 | typedef uint64_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U64TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U64_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 128 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_salsa64-avx.h" 15 | #include "scrypt-jane-mix_salsa64-ssse3.h" 16 | #include "scrypt-jane-mix_salsa64-sse2.h" 17 | #include "scrypt-jane-mix_salsa64.h" 18 | 19 | #if defined(SCRYPT_SALSA64_AVX) 20 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 21 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 22 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 23 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 24 | #include "scrypt-jane-romix-template.h" 25 | #endif 26 | 27 | #if defined(SCRYPT_SALSA64_SSSE3) 28 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3 29 | #define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3 30 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 31 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 32 | #include "scrypt-jane-romix-template.h" 33 | #endif 34 | 35 | #if defined(SCRYPT_SALSA64_SSE2) 36 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 37 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 38 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 39 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 40 | #include "scrypt-jane-romix-template.h" 41 | #endif 42 | 43 | /* cpu agnostic */ 44 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 45 | #define SCRYPT_MIX_FN salsa64_core_basic 46 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 47 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 48 | #include "scrypt-jane-romix-template.h" 49 | 50 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 51 | static scrypt_ROMixfn 52 | scrypt_getROMix() { 53 | size_t cpuflags = detect_cpu(); 54 | 55 | #if defined(SCRYPT_SALSA64_AVX) 56 | if (cpuflags & cpu_avx) 57 | return scrypt_ROMix_avx; 58 | else 59 | #endif 60 | 61 | #if defined(SCRYPT_SALSA64_SSSE3) 62 | if (cpuflags & cpu_ssse3) 63 | return scrypt_ROMix_ssse3; 64 | else 65 | #endif 66 | 67 | #if defined(SCRYPT_SALSA64_SSE2) 68 | if (cpuflags & cpu_sse2) 69 | return scrypt_ROMix_sse2; 70 | else 71 | #endif 72 | 73 | return scrypt_ROMix_basic; 74 | } 75 | #endif 76 | 77 | 78 | #if defined(SCRYPT_TEST_SPEED) 79 | static size_t 80 | available_implementations() { 81 | size_t flags = 0; 82 | 83 | #if defined(SCRYPT_SALSA64_AVX) 84 | flags |= cpu_avx; 85 | #endif 86 | 87 | #if defined(SCRYPT_SALSA64_SSSE3) 88 | flags |= cpu_ssse3; 89 | #endif 90 | 91 | #if defined(SCRYPT_SALSA64_SSE2) 92 | flags |= cpu_sse2; 93 | #endif 94 | 95 | return flags; 96 | } 97 | #endif 98 | 99 | static int 100 | scrypt_test_mix() { 101 | static const uint8_t expected[16] = { 102 | 0xf8,0x92,0x9b,0xf8,0xcc,0x1d,0xce,0x2e,0x13,0x82,0xac,0x96,0xb2,0x6c,0xee,0x2c, 103 | }; 104 | 105 | int ret = 1; 106 | size_t cpuflags = detect_cpu(); 107 | 108 | #if defined(SCRYPT_SALSA64_AVX) 109 | if (cpuflags & cpu_avx) 110 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 111 | #endif 112 | 113 | #if defined(SCRYPT_SALSA64_SSSE3) 114 | if (cpuflags & cpu_ssse3) 115 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 116 | #endif 117 | 118 | #if defined(SCRYPT_SALSA64_SSE2) 119 | if (cpuflags & cpu_sse2) 120 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 121 | #endif 122 | 123 | #if defined(SCRYPT_SALSA64_BASIC) 124 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 125 | #endif 126 | 127 | return ret; 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/scryptn.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRYPTN_H 2 | #define SCRYPTN_H 3 | #include 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len); 9 | void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len); 10 | //const int scrypt_scratchpad_size = 131583; 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/sha1.c: -------------------------------------------------------------------------------- 1 | #include "sha1.h" 2 | 3 | #include 4 | #include "sha3/sph_sha1.h" 5 | 6 | #if defined(__GNUC__) 7 | #define ALIGN32(x) x __attribute__((aligned(32))) 8 | #elif defined(_MSC_VER) 9 | #define ALIGN32(x) __declspec(align(32)) x 10 | #else 11 | #define ALIGN32(x) x 12 | #endif 13 | 14 | static inline void encodeb64(const unsigned char* pch, char* buff) 15 | { 16 | const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 17 | int mode = 0, left = 0; 18 | const int len = 20; 19 | const unsigned char *pchEnd = pch + len; 20 | while (pch < pchEnd) { 21 | int enc = *(pch++); 22 | if (mode == 0) { 23 | *buff++ = pbase64[enc >> 2]; 24 | left = (enc & 3) << 4; 25 | mode = 1; 26 | } 27 | else if (mode == 1) { 28 | *buff++ = pbase64[left | (enc >> 4)]; 29 | left = (enc & 15) << 2; 30 | mode = 2; 31 | } 32 | else { 33 | *buff++ = pbase64[left | (enc >> 6)]; 34 | *buff++ = pbase64[enc & 63]; 35 | mode = 0; 36 | } 37 | } 38 | *buff = pbase64[left]; 39 | *(buff + 1) = 0; 40 | } 41 | 42 | void sha1_hash(const char* input, char* output, uint32_t len) 43 | { 44 | ALIGN32(char str[38]); // 26 + 11 + 1 45 | ALIGN32(uint32_t prehash[5]); 46 | ALIGN32(uint32_t hash[5]) = { 0 }; 47 | int i = 0; 48 | sph_sha1_context ctx; 49 | sph_sha1_init(&ctx); 50 | sph_sha1(&ctx, (void *)input, len); 51 | sph_sha1_close(&ctx, (void *)prehash); 52 | encodeb64((const unsigned char *)prehash, str); 53 | memcpy(&str[26], str, 11); 54 | str[37] = 0; 55 | for (i = 0; i < 26; i++) { 56 | sph_sha1_init(&ctx); 57 | sph_sha1(&ctx, (void *)&str[i], 12); 58 | sph_sha1_close(&ctx, (void *)prehash); 59 | hash[0] ^= prehash[0]; 60 | hash[1] ^= prehash[1]; 61 | hash[2] ^= prehash[2]; 62 | hash[3] ^= prehash[3]; 63 | hash[4] ^= prehash[4]; 64 | } 65 | memset(output, 0, 32 - 20); 66 | memcpy(&output[32 - 20], hash, 20); 67 | } 68 | -------------------------------------------------------------------------------- /src/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void sha1_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/sha256d.c: -------------------------------------------------------------------------------- 1 | #include "sha256d.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_sha2.h" 8 | 9 | void sha256d_hash(const char* input, char* output, uint32_t len) 10 | { 11 | uint32_t hashA[32], hashB[32]; 12 | 13 | sph_sha256_context ctx_sha2; 14 | 15 | sph_sha256_init(&ctx_sha2); 16 | 17 | sph_sha256(&ctx_sha2, input, len); 18 | sph_sha256_close(&ctx_sha2, hashA); 19 | 20 | sph_sha256(&ctx_sha2, hashA, 32); 21 | sph_sha256_close(&ctx_sha2, hashB); 22 | 23 | memcpy(output, hashB, 32); 24 | } 25 | -------------------------------------------------------------------------------- /src/sha256d.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256D_H 2 | #define SHA256D_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | void sha256d_hash(const char* input, char* output, uint32_t len); 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/sha3/sph_fugue.h: -------------------------------------------------------------------------------- 1 | #ifndef SPH_FUGUE_H__ 2 | #define SPH_FUGUE_H__ 3 | 4 | #include 5 | #include "sph_types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif 10 | 11 | #define SPH_SIZE_fugue224 224 12 | 13 | #define SPH_SIZE_fugue256 256 14 | 15 | #define SPH_SIZE_fugue384 384 16 | 17 | #define SPH_SIZE_fugue512 512 18 | 19 | typedef struct { 20 | #ifndef DOXYGEN_IGNORE 21 | sph_u32 partial; 22 | unsigned partial_len; 23 | unsigned round_shift; 24 | sph_u32 S[36]; 25 | #if SPH_64 26 | sph_u64 bit_count; 27 | #else 28 | sph_u32 bit_count_high, bit_count_low; 29 | #endif 30 | #endif 31 | } sph_fugue_context; 32 | 33 | typedef sph_fugue_context sph_fugue224_context; 34 | 35 | typedef sph_fugue_context sph_fugue256_context; 36 | 37 | typedef sph_fugue_context sph_fugue384_context; 38 | 39 | typedef sph_fugue_context sph_fugue512_context; 40 | 41 | void sph_fugue224_init(void *cc); 42 | 43 | void sph_fugue224(void *cc, const void *data, size_t len); 44 | 45 | void sph_fugue224_close(void *cc, void *dst); 46 | 47 | void sph_fugue224_addbits_and_close( 48 | void *cc, unsigned ub, unsigned n, void *dst); 49 | 50 | void sph_fugue256_init(void *cc); 51 | 52 | void sph_fugue256(void *cc, const void *data, size_t len); 53 | 54 | void sph_fugue256_close(void *cc, void *dst); 55 | 56 | void sph_fugue256_addbits_and_close( 57 | void *cc, unsigned ub, unsigned n, void *dst); 58 | 59 | void sph_fugue384_init(void *cc); 60 | 61 | void sph_fugue384(void *cc, const void *data, size_t len); 62 | 63 | void sph_fugue384_close(void *cc, void *dst); 64 | 65 | void sph_fugue384_addbits_and_close( 66 | void *cc, unsigned ub, unsigned n, void *dst); 67 | 68 | void sph_fugue512_init(void *cc); 69 | 70 | void sph_fugue512(void *cc, const void *data, size_t len); 71 | 72 | void sph_fugue512_close(void *cc, void *dst); 73 | 74 | void sph_fugue512_addbits_and_close( 75 | void *cc, unsigned ub, unsigned n, void *dst); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif -------------------------------------------------------------------------------- /src/sha3/sph_hefty1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HEFTY1 cryptographic hash function 3 | * 4 | * Copyright (c) 2014, dbcc14 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | * 27 | * The views and conclusions contained in the software and documentation are those 28 | * of the authors and should not be interpreted as representing official policies, 29 | * either expressed or implied, of the FreeBSD Project. 30 | */ 31 | 32 | #ifndef __HEFTY1_H__ 33 | #define __HEFTY1_H__ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef WIN32 40 | #include 41 | #endif 42 | 43 | #include 44 | 45 | #define HEFTY1_DIGEST_BYTES 32 46 | #define HEFTY1_BLOCK_BYTES 64 47 | #define HEFTY1_STATE_WORDS 8 48 | #define HEFTY1_SPONGE_WORDS 4 49 | 50 | typedef struct HEFTY1_CTX { 51 | uint32_t h[HEFTY1_STATE_WORDS]; 52 | uint8_t block[HEFTY1_BLOCK_BYTES]; 53 | uint64_t written; 54 | uint32_t sponge[HEFTY1_SPONGE_WORDS]; 55 | } HEFTY1_CTX; 56 | 57 | void HEFTY1_Init(HEFTY1_CTX *cxt); 58 | void HEFTY1_Update(HEFTY1_CTX *cxt, const void *data, size_t len); 59 | void HEFTY1_Final(unsigned char *digest, HEFTY1_CTX *cxt); 60 | unsigned char* HEFTY1(const unsigned char *data, size_t len, unsigned char *digest); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __HEFTY1_H__ */ -------------------------------------------------------------------------------- /src/sha3/sph_sha1.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_sha1.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * SHA-1 interface. 4 | * 5 | * SHA-1 is described in FIPS 180-1 (now superseded by FIPS 180-2, but the 6 | * description of SHA-1 is still included and has not changed). FIPS 7 | * standards can be found at: http://csrc.nist.gov/publications/fips/ 8 | * 9 | * @warning A theoretical collision attack against SHA-1, with work 10 | * factor 2^63, has been published. SHA-1 should not be used in new 11 | * protocol designs. 12 | * 13 | * ==========================(LICENSE BEGIN)============================ 14 | * 15 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining 18 | * a copy of this software and associated documentation files (the 19 | * "Software"), to deal in the Software without restriction, including 20 | * without limitation the rights to use, copy, modify, merge, publish, 21 | * distribute, sublicense, and/or sell copies of the Software, and to 22 | * permit persons to whom the Software is furnished to do so, subject to 23 | * the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be 26 | * included in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 31 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 32 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 33 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 34 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | * 36 | * ===========================(LICENSE END)============================= 37 | * 38 | * @file sph_sha1.h 39 | * @author Thomas Pornin 40 | */ 41 | 42 | #ifndef SPH_SHA1_H__ 43 | #define SPH_SHA1_H__ 44 | 45 | #include 46 | #include "sph_types.h" 47 | 48 | /** 49 | * Output size (in bits) for SHA-1. 50 | */ 51 | #define SPH_SIZE_sha1 160 52 | 53 | /** 54 | * This structure is a context for SHA-1 computations: it contains the 55 | * intermediate values and some data from the last entered block. Once 56 | * a SHA-1 computation has been performed, the context can be reused for 57 | * another computation. 58 | * 59 | * The contents of this structure are private. A running SHA-1 computation 60 | * can be cloned by copying the context (e.g. with a simple 61 | * memcpy()). 62 | */ 63 | typedef struct { 64 | #ifndef DOXYGEN_IGNORE 65 | unsigned char buf[64]; /* first field, for alignment */ 66 | sph_u32 val[5]; 67 | #if SPH_64 68 | sph_u64 count; 69 | #else 70 | sph_u32 count_high, count_low; 71 | #endif 72 | #endif 73 | } sph_sha1_context; 74 | 75 | /** 76 | * Initialize a SHA-1 context. This process performs no memory allocation. 77 | * 78 | * @param cc the SHA-1 context (pointer to a sph_sha1_context) 79 | */ 80 | void sph_sha1_init(void *cc); 81 | 82 | /** 83 | * Process some data bytes. It is acceptable that len is zero 84 | * (in which case this function does nothing). 85 | * 86 | * @param cc the SHA-1 context 87 | * @param data the input data 88 | * @param len the input data length (in bytes) 89 | */ 90 | void sph_sha1(void *cc, const void *data, size_t len); 91 | 92 | /** 93 | * Terminate the current SHA-1 computation and output the result into the 94 | * provided buffer. The destination buffer must be wide enough to 95 | * accomodate the result (20 bytes). The context is automatically 96 | * reinitialized. 97 | * 98 | * @param cc the SHA-1 context 99 | * @param dst the destination buffer 100 | */ 101 | void sph_sha1_close(void *cc, void *dst); 102 | 103 | /** 104 | * Add a few additional bits (0 to 7) to the current computation, then 105 | * terminate it and output the result in the provided buffer, which must 106 | * be wide enough to accomodate the result (20 bytes). If bit number i 107 | * in ub has value 2^i, then the extra bits are those 108 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 109 | * level). The context is automatically reinitialized. 110 | * 111 | * @param cc the SHA-1 context 112 | * @param ub the extra bits 113 | * @param n the number of extra bits (0 to 7) 114 | * @param dst the destination buffer 115 | */ 116 | void sph_sha1_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst); 117 | 118 | /** 119 | * Apply the SHA-1 compression function on the provided data. The 120 | * msg parameter contains the 16 32-bit input blocks, 121 | * as numerical values (hence after the big-endian decoding). The 122 | * val parameter contains the 5 32-bit input blocks for 123 | * the compression function; the output is written in place in this 124 | * array. 125 | * 126 | * @param msg the message block (16 values) 127 | * @param val the function 160-bit input and output 128 | */ 129 | void sph_sha1_comp(const sph_u32 msg[16], sph_u32 val[5]); 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /src/shavite3.c: -------------------------------------------------------------------------------- 1 | #include "shavite3.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_shavite.h" 7 | 8 | void shavite3_hash(const char* input, char* output, uint32_t len) 9 | { 10 | char hash1[64]; 11 | char hash2[64]; 12 | 13 | sph_shavite512_context ctx_shavite; 14 | 15 | sph_shavite512_init(&ctx_shavite); 16 | sph_shavite512(&ctx_shavite, (const void*) input, len); 17 | sph_shavite512_close(&ctx_shavite, (void*) &hash1); 18 | 19 | sph_shavite512(&ctx_shavite, (const void*) &hash1, 64); 20 | sph_shavite512_close(&ctx_shavite, (void*) &hash2); 21 | 22 | memcpy(output, &hash2, 32); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/shavite3.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAVITE_H 2 | #define SHAVITE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void shavite3_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/skein.c: -------------------------------------------------------------------------------- 1 | #include "skein.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_skein.h" 8 | #include "sha256.h" 9 | 10 | #include 11 | 12 | void skein_hash(const char* input, char* output, uint32_t len) 13 | { 14 | char temp[64]; 15 | 16 | sph_skein512_context ctx_skien; 17 | sph_skein512_init(&ctx_skien); 18 | sph_skein512(&ctx_skien, input, len); 19 | sph_skein512_close(&ctx_skien, &temp); 20 | 21 | sha256_ctx ctx_sha256; 22 | sha256_init(&ctx_sha256); 23 | sha256_update(&ctx_sha256, &temp, 64); 24 | sha256_final((unsigned char*) output, &ctx_sha256); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/skein.h: -------------------------------------------------------------------------------- 1 | #ifndef SKEIN_H 2 | #define SKEIN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void skein_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/x11.c: -------------------------------------------------------------------------------- 1 | #include "x11.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_bmw.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_jh.h" 11 | #include "sha3/sph_keccak.h" 12 | #include "sha3/sph_skein.h" 13 | #include "sha3/sph_luffa.h" 14 | #include "sha3/sph_cubehash.h" 15 | #include "sha3/sph_shavite.h" 16 | #include "sha3/sph_simd.h" 17 | #include "sha3/sph_echo.h" 18 | 19 | 20 | void x11_hash(const char* input, char* output, uint32_t len) 21 | { 22 | sph_blake512_context ctx_blake; 23 | sph_bmw512_context ctx_bmw; 24 | sph_groestl512_context ctx_groestl; 25 | sph_skein512_context ctx_skein; 26 | sph_jh512_context ctx_jh; 27 | sph_keccak512_context ctx_keccak; 28 | 29 | sph_luffa512_context ctx_luffa1; 30 | sph_cubehash512_context ctx_cubehash1; 31 | sph_shavite512_context ctx_shavite1; 32 | sph_simd512_context ctx_simd1; 33 | sph_echo512_context ctx_echo1; 34 | 35 | //these uint512 in the c++ source of the client are backed by an array of uint32 36 | uint32_t hashA[16], hashB[16]; 37 | 38 | sph_blake512_init(&ctx_blake); 39 | sph_blake512 (&ctx_blake, input, len); 40 | sph_blake512_close (&ctx_blake, hashA); 41 | 42 | sph_bmw512_init(&ctx_bmw); 43 | sph_bmw512 (&ctx_bmw, hashA, 64); 44 | sph_bmw512_close(&ctx_bmw, hashB); 45 | 46 | sph_groestl512_init(&ctx_groestl); 47 | sph_groestl512 (&ctx_groestl, hashB, 64); 48 | sph_groestl512_close(&ctx_groestl, hashA); 49 | 50 | sph_skein512_init(&ctx_skein); 51 | sph_skein512 (&ctx_skein, hashA, 64); 52 | sph_skein512_close (&ctx_skein, hashB); 53 | 54 | sph_jh512_init(&ctx_jh); 55 | sph_jh512 (&ctx_jh, hashB, 64); 56 | sph_jh512_close(&ctx_jh, hashA); 57 | 58 | sph_keccak512_init(&ctx_keccak); 59 | sph_keccak512 (&ctx_keccak, hashA, 64); 60 | sph_keccak512_close(&ctx_keccak, hashB); 61 | 62 | sph_luffa512_init (&ctx_luffa1); 63 | sph_luffa512 (&ctx_luffa1, hashB, 64); 64 | sph_luffa512_close (&ctx_luffa1, hashA); 65 | 66 | sph_cubehash512_init (&ctx_cubehash1); 67 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 68 | sph_cubehash512_close(&ctx_cubehash1, hashB); 69 | 70 | sph_shavite512_init (&ctx_shavite1); 71 | sph_shavite512 (&ctx_shavite1, hashB, 64); 72 | sph_shavite512_close(&ctx_shavite1, hashA); 73 | 74 | sph_simd512_init (&ctx_simd1); 75 | sph_simd512 (&ctx_simd1, hashA, 64); 76 | sph_simd512_close(&ctx_simd1, hashB); 77 | 78 | sph_echo512_init (&ctx_echo1); 79 | sph_echo512 (&ctx_echo1, hashB, 64); 80 | sph_echo512_close(&ctx_echo1, hashA); 81 | 82 | memcpy(output, hashA, 32); 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/x11.h: -------------------------------------------------------------------------------- 1 | #ifndef X11_H 2 | #define X11_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void x11_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/x13.c: -------------------------------------------------------------------------------- 1 | #include "x13.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_bmw.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_jh.h" 11 | #include "sha3/sph_keccak.h" 12 | #include "sha3/sph_skein.h" 13 | #include "sha3/sph_luffa.h" 14 | #include "sha3/sph_cubehash.h" 15 | #include "sha3/sph_shavite.h" 16 | #include "sha3/sph_simd.h" 17 | #include "sha3/sph_echo.h" 18 | #include "sha3/sph_hamsi.h" 19 | #include "sha3/sph_fugue.h" 20 | 21 | 22 | void x13_hash(const char* input, char* output, uint32_t len) 23 | { 24 | sph_blake512_context ctx_blake; 25 | sph_bmw512_context ctx_bmw; 26 | sph_groestl512_context ctx_groestl; 27 | sph_skein512_context ctx_skein; 28 | sph_jh512_context ctx_jh; 29 | sph_keccak512_context ctx_keccak; 30 | sph_luffa512_context ctx_luffa1; 31 | sph_cubehash512_context ctx_cubehash1; 32 | sph_shavite512_context ctx_shavite1; 33 | sph_simd512_context ctx_simd1; 34 | sph_echo512_context ctx_echo1; 35 | sph_hamsi512_context ctx_hamsi1; 36 | sph_fugue512_context ctx_fugue1; 37 | 38 | //these uint512 in the c++ source of the client are backed by an array of uint32 39 | uint32_t hashA[16], hashB[16]; 40 | 41 | sph_blake512_init(&ctx_blake); 42 | sph_blake512 (&ctx_blake, input, len); 43 | sph_blake512_close (&ctx_blake, hashA); 44 | 45 | sph_bmw512_init(&ctx_bmw); 46 | sph_bmw512 (&ctx_bmw, hashA, 64); 47 | sph_bmw512_close(&ctx_bmw, hashB); 48 | 49 | sph_groestl512_init(&ctx_groestl); 50 | sph_groestl512 (&ctx_groestl, hashB, 64); 51 | sph_groestl512_close(&ctx_groestl, hashA); 52 | 53 | sph_skein512_init(&ctx_skein); 54 | sph_skein512 (&ctx_skein, hashA, 64); 55 | sph_skein512_close (&ctx_skein, hashB); 56 | 57 | sph_jh512_init(&ctx_jh); 58 | sph_jh512 (&ctx_jh, hashB, 64); 59 | sph_jh512_close(&ctx_jh, hashA); 60 | 61 | sph_keccak512_init(&ctx_keccak); 62 | sph_keccak512 (&ctx_keccak, hashA, 64); 63 | sph_keccak512_close(&ctx_keccak, hashB); 64 | 65 | sph_luffa512_init (&ctx_luffa1); 66 | sph_luffa512 (&ctx_luffa1, hashB, 64); 67 | sph_luffa512_close (&ctx_luffa1, hashA); 68 | 69 | sph_cubehash512_init (&ctx_cubehash1); 70 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 71 | sph_cubehash512_close(&ctx_cubehash1, hashB); 72 | 73 | sph_shavite512_init (&ctx_shavite1); 74 | sph_shavite512 (&ctx_shavite1, hashB, 64); 75 | sph_shavite512_close(&ctx_shavite1, hashA); 76 | 77 | sph_simd512_init (&ctx_simd1); 78 | sph_simd512 (&ctx_simd1, hashA, 64); 79 | sph_simd512_close(&ctx_simd1, hashB); 80 | 81 | sph_echo512_init (&ctx_echo1); 82 | sph_echo512 (&ctx_echo1, hashB, 64); 83 | sph_echo512_close(&ctx_echo1, hashA); 84 | 85 | sph_hamsi512_init (&ctx_hamsi1); 86 | sph_hamsi512 (&ctx_hamsi1, hashA, 64); 87 | sph_hamsi512_close(&ctx_hamsi1, hashB); 88 | 89 | sph_fugue512_init (&ctx_fugue1); 90 | sph_fugue512 (&ctx_fugue1, hashB, 64); 91 | sph_fugue512_close(&ctx_fugue1, hashA); 92 | 93 | 94 | 95 | memcpy(output, hashA, 32); 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/x13.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void x13_hash(const char* input, char* output, uint32_t len); 6 | -------------------------------------------------------------------------------- /src/x15.c: -------------------------------------------------------------------------------- 1 | #include "x15.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_bmw.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_jh.h" 11 | #include "sha3/sph_keccak.h" 12 | #include "sha3/sph_skein.h" 13 | #include "sha3/sph_luffa.h" 14 | #include "sha3/sph_cubehash.h" 15 | #include "sha3/sph_shavite.h" 16 | #include "sha3/sph_simd.h" 17 | #include "sha3/sph_echo.h" 18 | #include "sha3/sph_hamsi.h" 19 | #include "sha3/sph_fugue.h" 20 | #include "sha3/sph_shabal.h" 21 | #include "sha3/sph_whirlpool.h" 22 | 23 | void x15_hash(const char* input, char* output, uint32_t len) 24 | { 25 | sph_blake512_context ctx_blake; 26 | sph_bmw512_context ctx_bmw; 27 | sph_groestl512_context ctx_groestl; 28 | sph_skein512_context ctx_skein; 29 | sph_jh512_context ctx_jh; 30 | sph_keccak512_context ctx_keccak; 31 | sph_luffa512_context ctx_luffa1; 32 | sph_cubehash512_context ctx_cubehash1; 33 | sph_shavite512_context ctx_shavite1; 34 | sph_simd512_context ctx_simd1; 35 | sph_echo512_context ctx_echo1; 36 | sph_hamsi512_context ctx_hamsi1; 37 | sph_fugue512_context ctx_fugue1; 38 | sph_shabal512_context ctx_shabal1; 39 | sph_whirlpool_context ctx_whirlpool1; 40 | 41 | //these uint512 in the c++ source of the client are backed by an array of uint32 42 | uint32_t hashA[16], hashB[16]; 43 | 44 | sph_blake512_init(&ctx_blake); 45 | sph_blake512 (&ctx_blake, input, len); 46 | sph_blake512_close (&ctx_blake, hashA); 47 | 48 | sph_bmw512_init(&ctx_bmw); 49 | sph_bmw512 (&ctx_bmw, hashA, 64); 50 | sph_bmw512_close(&ctx_bmw, hashB); 51 | 52 | sph_groestl512_init(&ctx_groestl); 53 | sph_groestl512 (&ctx_groestl, hashB, 64); 54 | sph_groestl512_close(&ctx_groestl, hashA); 55 | 56 | sph_skein512_init(&ctx_skein); 57 | sph_skein512 (&ctx_skein, hashA, 64); 58 | sph_skein512_close (&ctx_skein, hashB); 59 | 60 | sph_jh512_init(&ctx_jh); 61 | sph_jh512 (&ctx_jh, hashB, 64); 62 | sph_jh512_close(&ctx_jh, hashA); 63 | 64 | sph_keccak512_init(&ctx_keccak); 65 | sph_keccak512 (&ctx_keccak, hashA, 64); 66 | sph_keccak512_close(&ctx_keccak, hashB); 67 | 68 | sph_luffa512_init (&ctx_luffa1); 69 | sph_luffa512 (&ctx_luffa1, hashB, 64); 70 | sph_luffa512_close (&ctx_luffa1, hashA); 71 | 72 | sph_cubehash512_init (&ctx_cubehash1); 73 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 74 | sph_cubehash512_close(&ctx_cubehash1, hashB); 75 | 76 | sph_shavite512_init (&ctx_shavite1); 77 | sph_shavite512 (&ctx_shavite1, hashB, 64); 78 | sph_shavite512_close(&ctx_shavite1, hashA); 79 | 80 | sph_simd512_init (&ctx_simd1); 81 | sph_simd512 (&ctx_simd1, hashA, 64); 82 | sph_simd512_close(&ctx_simd1, hashB); 83 | 84 | sph_echo512_init (&ctx_echo1); 85 | sph_echo512 (&ctx_echo1, hashB, 64); 86 | sph_echo512_close(&ctx_echo1, hashA); 87 | 88 | sph_hamsi512_init (&ctx_hamsi1); 89 | sph_hamsi512 (&ctx_hamsi1, hashA, 64); 90 | sph_hamsi512_close(&ctx_hamsi1, hashB); 91 | 92 | sph_fugue512_init (&ctx_fugue1); 93 | sph_fugue512 (&ctx_fugue1, hashB, 64); 94 | sph_fugue512_close(&ctx_fugue1, hashA); 95 | 96 | sph_shabal512_init (&ctx_shabal1); 97 | sph_shabal512 (&ctx_shabal1, hashA, 64); 98 | sph_shabal512_close(&ctx_shabal1, hashB); 99 | 100 | sph_whirlpool_init (&ctx_whirlpool1); 101 | sph_whirlpool (&ctx_whirlpool1, hashB, 64); 102 | sph_whirlpool_close(&ctx_whirlpool1, hashA); 103 | 104 | memcpy(output, hashA, 32); 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/x15.h: -------------------------------------------------------------------------------- 1 | #ifndef X15_H 2 | #define X15_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void x15_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/x16r.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_blake.h" 7 | #include "sha3/sph_bmw.h" 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_jh.h" 10 | #include "sha3/sph_keccak.h" 11 | #include "sha3/sph_skein.h" 12 | #include "sha3/sph_luffa.h" 13 | #include "sha3/sph_cubehash.h" 14 | #include "sha3/sph_shavite.h" 15 | #include "sha3/sph_simd.h" 16 | #include "sha3/sph_echo.h" 17 | #include "sha3/sph_hamsi.h" 18 | #include "sha3/sph_fugue.h" 19 | #include "sha3/sph_shabal.h" 20 | #include "sha3/sph_whirlpool.h" 21 | #include "sha3/sph_sha2.h" 22 | 23 | //#include "common.h" 24 | 25 | enum Algo { 26 | BLAKE = 0, 27 | BMW, 28 | GROESTL, 29 | JH, 30 | KECCAK, 31 | SKEIN, 32 | LUFFA, 33 | CUBEHASH, 34 | SHAVITE, 35 | SIMD, 36 | ECHO, 37 | HAMSI, 38 | FUGUE, 39 | SHABAL, 40 | WHIRLPOOL, 41 | SHA512, 42 | HASH_FUNC_COUNT 43 | }; 44 | 45 | static void getAlgoString(const uint8_t* prevblock, char *output) 46 | { 47 | char *sptr = output; 48 | int j; 49 | 50 | for (j = 0; j < HASH_FUNC_COUNT; j++) { 51 | uint8_t b = (15 - j) >> 1; // 16 ascii hex chars, reversed 52 | uint8_t algoDigit = (j & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; 53 | if (algoDigit >= 10) 54 | sprintf(sptr, "%c", 'A' + (algoDigit - 10)); 55 | else 56 | sprintf(sptr, "%u", (uint32_t) algoDigit); 57 | sptr++; 58 | } 59 | *sptr = '\0'; 60 | } 61 | 62 | void x16r_hash(const char* input, char* output, uint32_t len) 63 | { 64 | uint32_t hash[64/4]; 65 | char hashOrder[HASH_FUNC_COUNT + 1] = { 0 }; 66 | 67 | sph_blake512_context ctx_blake; 68 | sph_bmw512_context ctx_bmw; 69 | sph_groestl512_context ctx_groestl; 70 | sph_skein512_context ctx_skein; 71 | sph_jh512_context ctx_jh; 72 | sph_keccak512_context ctx_keccak; 73 | sph_luffa512_context ctx_luffa; 74 | sph_cubehash512_context ctx_cubehash; 75 | sph_shavite512_context ctx_shavite; 76 | sph_simd512_context ctx_simd; 77 | sph_echo512_context ctx_echo; 78 | sph_hamsi512_context ctx_hamsi; 79 | sph_fugue512_context ctx_fugue; 80 | sph_shabal512_context ctx_shabal; 81 | sph_whirlpool_context ctx_whirlpool; 82 | sph_sha512_context ctx_sha512; 83 | 84 | void *in = (void*) input; 85 | int size = len; 86 | int i; 87 | 88 | getAlgoString((uint8_t*)&input[4], hashOrder); 89 | 90 | for (i = 0; i < 16; i++) 91 | { 92 | const char elem = hashOrder[i]; 93 | const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; 94 | 95 | switch (algo) { 96 | case BLAKE: 97 | sph_blake512_init(&ctx_blake); 98 | sph_blake512(&ctx_blake, in, size); 99 | sph_blake512_close(&ctx_blake, hash); 100 | break; 101 | case BMW: 102 | sph_bmw512_init(&ctx_bmw); 103 | sph_bmw512(&ctx_bmw, in, size); 104 | sph_bmw512_close(&ctx_bmw, hash); 105 | break; 106 | case GROESTL: 107 | sph_groestl512_init(&ctx_groestl); 108 | sph_groestl512(&ctx_groestl, in, size); 109 | sph_groestl512_close(&ctx_groestl, hash); 110 | break; 111 | case SKEIN: 112 | sph_skein512_init(&ctx_skein); 113 | sph_skein512(&ctx_skein, in, size); 114 | sph_skein512_close(&ctx_skein, hash); 115 | break; 116 | case JH: 117 | sph_jh512_init(&ctx_jh); 118 | sph_jh512(&ctx_jh, in, size); 119 | sph_jh512_close(&ctx_jh, hash); 120 | break; 121 | case KECCAK: 122 | sph_keccak512_init(&ctx_keccak); 123 | sph_keccak512(&ctx_keccak, in, size); 124 | sph_keccak512_close(&ctx_keccak, hash); 125 | break; 126 | case LUFFA: 127 | sph_luffa512_init(&ctx_luffa); 128 | sph_luffa512(&ctx_luffa, in, size); 129 | sph_luffa512_close(&ctx_luffa, hash); 130 | break; 131 | case CUBEHASH: 132 | sph_cubehash512_init(&ctx_cubehash); 133 | sph_cubehash512(&ctx_cubehash, in, size); 134 | sph_cubehash512_close(&ctx_cubehash, hash); 135 | break; 136 | case SHAVITE: 137 | sph_shavite512_init(&ctx_shavite); 138 | sph_shavite512(&ctx_shavite, in, size); 139 | sph_shavite512_close(&ctx_shavite, hash); 140 | break; 141 | case SIMD: 142 | sph_simd512_init(&ctx_simd); 143 | sph_simd512(&ctx_simd, in, size); 144 | sph_simd512_close(&ctx_simd, hash); 145 | break; 146 | case ECHO: 147 | sph_echo512_init(&ctx_echo); 148 | sph_echo512(&ctx_echo, in, size); 149 | sph_echo512_close(&ctx_echo, hash); 150 | break; 151 | case HAMSI: 152 | sph_hamsi512_init(&ctx_hamsi); 153 | sph_hamsi512(&ctx_hamsi, in, size); 154 | sph_hamsi512_close(&ctx_hamsi, hash); 155 | break; 156 | case FUGUE: 157 | sph_fugue512_init(&ctx_fugue); 158 | sph_fugue512(&ctx_fugue, in, size); 159 | sph_fugue512_close(&ctx_fugue, hash); 160 | break; 161 | case SHABAL: 162 | sph_shabal512_init(&ctx_shabal); 163 | sph_shabal512(&ctx_shabal, in, size); 164 | sph_shabal512_close(&ctx_shabal, hash); 165 | break; 166 | case WHIRLPOOL: 167 | sph_whirlpool_init(&ctx_whirlpool); 168 | sph_whirlpool(&ctx_whirlpool, in, size); 169 | sph_whirlpool_close(&ctx_whirlpool, hash); 170 | break; 171 | case SHA512: 172 | sph_sha512_init(&ctx_sha512); 173 | sph_sha512(&ctx_sha512,(const void*) in, size); 174 | sph_sha512_close(&ctx_sha512,(void*) hash); 175 | break; 176 | } 177 | in = (void*) hash; 178 | size = 64; 179 | } 180 | memcpy(output, hash, 32); 181 | } -------------------------------------------------------------------------------- /src/x16r.h: -------------------------------------------------------------------------------- 1 | #ifndef X16R_H 2 | #define X16R_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void x16r_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /src/x16rv2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_blake.h" 7 | #include "sha3/sph_bmw.h" 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_jh.h" 10 | #include "sha3/sph_keccak.h" 11 | #include "sha3/sph_skein.h" 12 | #include "sha3/sph_luffa.h" 13 | #include "sha3/sph_cubehash.h" 14 | #include "sha3/sph_shavite.h" 15 | #include "sha3/sph_simd.h" 16 | #include "sha3/sph_echo.h" 17 | #include "sha3/sph_hamsi.h" 18 | #include "sha3/sph_fugue.h" 19 | #include "sha3/sph_shabal.h" 20 | #include "sha3/sph_whirlpool.h" 21 | #include "sha3/sph_sha2.h" 22 | #include "sha3/sph_tiger.h" 23 | 24 | enum Algo { 25 | BLAKE = 0, 26 | BMW, 27 | GROESTL, 28 | JH, 29 | KECCAK, 30 | SKEIN, 31 | LUFFA, 32 | CUBEHASH, 33 | SHAVITE, 34 | SIMD, 35 | ECHO, 36 | HAMSI, 37 | FUGUE, 38 | SHABAL, 39 | WHIRLPOOL, 40 | SHA512, 41 | HASH_FUNC_COUNT 42 | }; 43 | 44 | static void getAlgoString(const uint8_t* prevblock, char *output) 45 | { 46 | char *sptr = output; 47 | 48 | for (int j = 0; j < HASH_FUNC_COUNT; j++) { 49 | uint8_t b = (15 - j) >> 1; // 16 ascii hex chars, reversed 50 | uint8_t algoDigit = (j & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; 51 | if (algoDigit >= 10) 52 | sprintf(sptr, "%c", 'A' + (algoDigit - 10)); 53 | else 54 | sprintf(sptr, "%u", (uint32_t) algoDigit); 55 | sptr++; 56 | } 57 | *sptr = '\0'; 58 | } 59 | 60 | void x16rv2_hash(const char* input, char* output, uint32_t len) 61 | { 62 | uint32_t hash[64/4]; 63 | char hashOrder[HASH_FUNC_COUNT + 1] = { 0 }; 64 | 65 | sph_blake512_context ctx_blake; 66 | sph_bmw512_context ctx_bmw; 67 | sph_groestl512_context ctx_groestl; 68 | sph_skein512_context ctx_skein; 69 | sph_jh512_context ctx_jh; 70 | sph_keccak512_context ctx_keccak; 71 | sph_luffa512_context ctx_luffa; 72 | sph_cubehash512_context ctx_cubehash; 73 | sph_shavite512_context ctx_shavite; 74 | sph_simd512_context ctx_simd; 75 | sph_echo512_context ctx_echo; 76 | sph_hamsi512_context ctx_hamsi; 77 | sph_fugue512_context ctx_fugue; 78 | sph_shabal512_context ctx_shabal; 79 | sph_whirlpool_context ctx_whirlpool; 80 | sph_sha512_context ctx_sha512; 81 | sph_tiger_context ctx_tiger; 82 | 83 | void *in = (void*) input; 84 | int size = len; 85 | 86 | getAlgoString((uint8_t*)&input[4], hashOrder); 87 | 88 | for (int i = 0; i < 16; i++) 89 | { 90 | const char elem = hashOrder[i]; 91 | const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; 92 | 93 | switch (algo) { 94 | case BLAKE: 95 | sph_blake512_init(&ctx_blake); 96 | sph_blake512(&ctx_blake, in, size); 97 | sph_blake512_close(&ctx_blake, hash); 98 | break; 99 | case BMW: 100 | sph_bmw512_init(&ctx_bmw); 101 | sph_bmw512(&ctx_bmw, in, size); 102 | sph_bmw512_close(&ctx_bmw, hash); 103 | break; 104 | case GROESTL: 105 | sph_groestl512_init(&ctx_groestl); 106 | sph_groestl512(&ctx_groestl, in, size); 107 | sph_groestl512_close(&ctx_groestl, hash); 108 | break; 109 | case SKEIN: 110 | sph_skein512_init(&ctx_skein); 111 | sph_skein512(&ctx_skein, in, size); 112 | sph_skein512_close(&ctx_skein, hash); 113 | break; 114 | case JH: 115 | sph_jh512_init(&ctx_jh); 116 | sph_jh512(&ctx_jh, in, size); 117 | sph_jh512_close(&ctx_jh, hash); 118 | break; 119 | case KECCAK: 120 | sph_tiger_init(&ctx_tiger); 121 | sph_tiger(&ctx_tiger, (const void*) in, size); 122 | sph_tiger_close(&ctx_tiger, (void*) hash); 123 | for (int j = 24; j < 64; ++j) ((uint8_t*)hash)[j] = 0; // Pad the 24 bytes to bring it to 64 bytes 124 | 125 | sph_keccak512_init(&ctx_keccak); 126 | sph_keccak512(&ctx_keccak, hash, 64); 127 | sph_keccak512_close(&ctx_keccak, hash); 128 | break; 129 | case LUFFA: 130 | sph_tiger_init(&ctx_tiger); 131 | sph_tiger(&ctx_tiger, (const void*) in, size); 132 | sph_tiger_close(&ctx_tiger, (void*) hash); 133 | for (int j = 24; j < 64; ++j) ((uint8_t*)hash)[j] = 0; // Pad the 24 bytes to bring it to 64 bytes 134 | 135 | sph_luffa512_init(&ctx_luffa); 136 | sph_luffa512(&ctx_luffa, hash, 64); 137 | sph_luffa512_close(&ctx_luffa, hash); 138 | break; 139 | case CUBEHASH: 140 | sph_cubehash512_init(&ctx_cubehash); 141 | sph_cubehash512(&ctx_cubehash, in, size); 142 | sph_cubehash512_close(&ctx_cubehash, hash); 143 | break; 144 | case SHAVITE: 145 | sph_shavite512_init(&ctx_shavite); 146 | sph_shavite512(&ctx_shavite, in, size); 147 | sph_shavite512_close(&ctx_shavite, hash); 148 | break; 149 | case SIMD: 150 | sph_simd512_init(&ctx_simd); 151 | sph_simd512(&ctx_simd, in, size); 152 | sph_simd512_close(&ctx_simd, hash); 153 | break; 154 | case ECHO: 155 | sph_echo512_init(&ctx_echo); 156 | sph_echo512(&ctx_echo, in, size); 157 | sph_echo512_close(&ctx_echo, hash); 158 | break; 159 | case HAMSI: 160 | sph_hamsi512_init(&ctx_hamsi); 161 | sph_hamsi512(&ctx_hamsi, in, size); 162 | sph_hamsi512_close(&ctx_hamsi, hash); 163 | break; 164 | case FUGUE: 165 | sph_fugue512_init(&ctx_fugue); 166 | sph_fugue512(&ctx_fugue, in, size); 167 | sph_fugue512_close(&ctx_fugue, hash); 168 | break; 169 | case SHABAL: 170 | sph_shabal512_init(&ctx_shabal); 171 | sph_shabal512(&ctx_shabal, in, size); 172 | sph_shabal512_close(&ctx_shabal, hash); 173 | break; 174 | case WHIRLPOOL: 175 | sph_whirlpool_init(&ctx_whirlpool); 176 | sph_whirlpool(&ctx_whirlpool, in, size); 177 | sph_whirlpool_close(&ctx_whirlpool, hash); 178 | break; 179 | case SHA512: 180 | sph_tiger_init(&ctx_tiger); 181 | sph_tiger(&ctx_tiger, (const void*) in, size); 182 | sph_tiger_close(&ctx_tiger, (void*) hash); 183 | for (int j = 24; j < 64; ++j) ((uint8_t*)hash)[j] = 0; // Pad the 24 bytes to bring it to 64 bytes 184 | 185 | sph_sha512_init(&ctx_sha512); 186 | sph_sha512(&ctx_sha512,(const void*) hash, 64); 187 | sph_sha512_close(&ctx_sha512,(void*) hash); 188 | break; 189 | } 190 | in = (void*) hash; 191 | size = 64; 192 | } 193 | memcpy(output, hash, 32); 194 | } -------------------------------------------------------------------------------- /src/x16rv2.h: -------------------------------------------------------------------------------- 1 | #ifndef X16RV2_H 2 | #define X16RV2_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | void x16rv2_hash(const char* input, char* output, uint32_t len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /tests/cryptonight_monero.js: -------------------------------------------------------------------------------- 1 | const Buffer = require('safe-buffer').Buffer 2 | const multiHashing = require('../build/Release/multihashing') 3 | const assert = require('assert') 4 | 5 | var tests = [ 6 | new Buffer('This is a test This is a test This is a test'), 7 | new Buffer('74d15836e33d14e164c2494648996eb5ed71a3ec2c72c2be225eda1b8a857aba', 'hex'), 8 | new Buffer('0157c5ee188bbec8975285a3064ee92065217672fd69a1aebd0766c7b56ee0bd', 'hex'), 9 | new Buffer('353fdc068fd47b03c04b9431e005e00b68c2168a3cc7335c8b9b308156591a4f', 'hex'), 10 | new Buffer('353fdc068fd47b03c04b9431e005e00b68c2168a3cc7335c8b9b308156591a4f', 'hex'), 11 | new Buffer('f759588ad57e758467295443a9bd71490abff8e9dad1b95b6bf2f5d0d78387bc', 'hex'), 12 | new Buffer('Lorem ipsum dolor sit amet, consectetur adipiscing'), 13 | new Buffer('22ec483997cba20105378af3ec647ee5d20401d7df21c0bf4bf866bc55383e92', 'hex'), 14 | new Buffer('755d58e48e53f795a0ed6b27c794018372922e5d1a256cdbf9fc442f59f284c9', 'hex'), 15 | new Buffer('72f134fc50880c330fe65a2cb7896d59b2e708a0221c6a9da3f69b3a702d8682', 'hex'), 16 | new Buffer('72f134fc50880c330fe65a2cb7896d59b2e708a0221c6a9da3f69b3a702d8682', 'hex'), 17 | new Buffer('5bb833deca2bdd7252a9ccd7b4ce0b6a4854515794b56c207262f7a5b9bdb566', 'hex'), 18 | new Buffer('elit, sed do eiusmod tempor incididunt ut labore'), 19 | new Buffer('c5efc04bf88b450e86537dc046339b16d35133c4d905ec7fa16bd28a67c4f2fe', 'hex'), 20 | new Buffer('7158c9c0d5082df7f2ee236b994f385bd96fd09eda30e21643cb7351fd7301ce', 'hex'), 21 | new Buffer('410919660ec540fc49d8695ff01f974226a2a28dbbac82949c12f541b9a62d2f', 'hex'), 22 | new Buffer('410919660ec540fc49d8695ff01f974226a2a28dbbac82949c12f541b9a62d2f', 'hex'), 23 | new Buffer('1ee6728da60fbd8d7d55b2b1ade487a3cf52a2c3ac6f520db12c27d8921f6cab', 'hex'), 24 | new Buffer('et dolore magna aliqua. Ut enim ad minim veniam,'), 25 | new Buffer('628c400e4712cecb44d88572e9e8bb9be9a1221da1cb52ff8eefaf4adcc172eb', 'hex'), 26 | new Buffer('7329cde3fbf98bec02578fcdcfeaf2cf11e2a1f105324f89c36470708bd6db16', 'hex'), 27 | new Buffer('4472fecfeb371e8b7942ce0378c0ba5e6d0c6361b669c587807365c787ae652d', 'hex'), 28 | new Buffer('4472fecfeb371e8b7942ce0378c0ba5e6d0c6361b669c587807365c787ae652d', 'hex'), 29 | new Buffer('6969fe2ddfb758438d48049f302fc2108a4fcc93e37669170e6db4b0b9b4c4cb', 'hex'), 30 | new Buffer('quis nostrud exercitation ullamco laboris nisi'), 31 | new Buffer('a0351d7aa54c2e7c774695af86f8bbb859a0ef9b0d4f0031dd1df5ea7ccc752d', 'hex'), 32 | new Buffer('05066660ea3bc0568269cd95c212ad2bf2f2ced4e4cdb1f2bc5f766e88e4862b', 'hex'), 33 | new Buffer('577568395203f1f1225f2982b637f7d5e61b47a0f546ba16d46020b471b74076', 'hex'), 34 | new Buffer('577568395203f1f1225f2982b637f7d5e61b47a0f546ba16d46020b471b74076', 'hex'), 35 | new Buffer('7f3048b4e90d0cbe7a57c0394f37338a01fae3adfdc0e5126d863a895eb04e02', 'hex'), 36 | new Buffer('ut aliquip ex ea commodo consequat. Duis aute'), 37 | new Buffer('677b3a14c1875eda0ca0c3d6c340413848b1ab0bf9d448dddd5714cbc6d170b9', 'hex'), 38 | new Buffer('edc9f99dfd626ddc5604f8b387c7a88cc6fcb17cef46a3b917c2f8ffbd449982', 'hex'), 39 | new Buffer('f6fd7efe95a5c6c4bb46d9b429e3faf65b1ce439e116742d42b928e61de52385', 'hex'), 40 | new Buffer('f6fd7efe95a5c6c4bb46d9b429e3faf65b1ce439e116742d42b928e61de52385', 'hex'), 41 | new Buffer('1d290443a4b542af04a82f6b2494a6ee7f20f2754c58e0849032483a56e8e2ef', 'hex'), 42 | new Buffer('irure dolor in reprehenderit in voluptate velit'), 43 | new Buffer('8a73c33ebfd11d78db984486a298149d034051c61cdaf6ff7e783e46a6763edf', 'hex'), 44 | new Buffer('44df1cbd33439b82f901bcad232f3908331330edad0c9b9af35d62f524fd92b4', 'hex'), 45 | new Buffer('422f8cfe8060cf6c3d9fd66f68e3c9977adb683aea2788029308bbe9bc50d728', 'hex'), 46 | new Buffer('422f8cfe8060cf6c3d9fd66f68e3c9977adb683aea2788029308bbe9bc50d728', 'hex'), 47 | new Buffer('c43cc6567436a86afbd6aa9eaa7c276e9806830334b614b2bee23cc76634f6fd', 'hex'), 48 | new Buffer('esse cillum dolore eu fugiat nulla pariatur.'), 49 | new Buffer('021007fa46b46110e7dd6c7f1bb392499d7461950efd884e6bb4260d57906b6f', 'hex'), 50 | new Buffer('0fa9723e149c0772d16ae95b744186f419b48adcbfe685c99b53f6db44ba2668', 'hex'), 51 | new Buffer('512e62c8c8c833cfbd9d361442cb00d63c0a3fd8964cfd2fedc17c7c25ec2d4b', 'hex'), 52 | new Buffer('512e62c8c8c833cfbd9d361442cb00d63c0a3fd8964cfd2fedc17c7c25ec2d4b', 'hex'), 53 | new Buffer('87be2479c0c4e8edfdfaa5603e93f4265b3f8224c1c5946feb424819d18990a4', 'hex'), 54 | new Buffer('Excepteur sint occaecat cupidatat non proident,'), 55 | new Buffer('d61f8a0722e9d38c691fe22613ef68c83a498dd24e3c382ee1abfa665d632371', 'hex'), 56 | new Buffer('90c71412c2ca0c2e5789a98fb7ce36179d3c7f8b164f9aa07df56d44c9e9e96d', 'hex'), 57 | new Buffer('12a794c1aa13d561c9c6111cee631ca9d0a321718d67d3416add9de1693ba41e', 'hex'), 58 | new Buffer('12a794c1aa13d561c9c6111cee631ca9d0a321718d67d3416add9de1693ba41e', 'hex'), 59 | new Buffer('dd9d6a6d8e47465cceac0877ef889b93e7eba979557e3935d7f86dce11b070f3', 'hex'), 60 | new Buffer('sunt in culpa qui officia deserunt mollit anim id est laborum.'), 61 | new Buffer('75a105029f6b8c00429c427ffc7a64d84dbcdf2728ce0d2df9133cef91c9f8d3', 'hex'), 62 | new Buffer('5944b5b0480e84dc233bcc37101c23077542433c868c67325e9c501cfd1b8151', 'hex'), 63 | new Buffer('2659ff95fc74b6215c1dc741e85b7a9710101b30620212f80eb59c3c55993f9d', 'hex'), 64 | new Buffer('2659ff95fc74b6215c1dc741e85b7a9710101b30620212f80eb59c3c55993f9d', 'hex'), 65 | new Buffer('75c6f2ae49a20521de97285b431e717125847fb8935ed84a61e7f8d36a2c3d8e', 'hex'), 66 | ]; 67 | 68 | var height = 1806260; 69 | for (var i = 0; i < 10; ++i, ++height) 70 | { 71 | for (var variant = 0; variant <= 4; ++variant) 72 | { 73 | var hash = multiHashing['cryptonight'](tests[i * 6], variant, height); 74 | assert.deepEqual(hash, tests[i * 6 + variant + 1]); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/vectors/input.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "description": "Basic test vectors", 4 | "date": "Wed Aug 12 09:24:38 UTC 2020", 5 | "license": "CCL0" 6 | }, 7 | "strings": [ 8 | "The quick brown fox jumps over the lazy dog", 9 | "Lorem ipsum dolor sit amet, consectetur adipiscing", 10 | "elit, sed do eiusmod tempor incididunt ut labore", 11 | "et dolore magna aliqua. Ut enim ad minim veniam,", 12 | "quis nostrud exercitation ullamco laboris nisi", 13 | "ut aliquip ex ea commodo consequat. Duis aute", 14 | "irure dolor in reprehenderit in voluptate velit", 15 | "esse cillum dolore eu fugiat nulla pariatur.", 16 | "Excepteur sint occaecat cupidatat non proident,", 17 | "sunt in culpa qui officia deserunt mollit anim id est laborum.", 18 | "abc", 19 | "" 20 | ], 21 | "exclude-algos": [ 22 | "lbry", "cryptonight", "cryptonightfast", "neoscrypt" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/vectors/set1-input.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "description": "Basic test vectors", 4 | "date": "Wed Aug 12 09:24:38 UTC 2020", 5 | "license": "CCL0" 6 | }, 7 | "strings": [ 8 | "The quick brown fox jumps over the lazy dog", 9 | "Lorem ipsum dolor sit amet, consectetur adipiscing", 10 | "elit, sed do eiusmod tempor incididunt ut labore", 11 | "et dolore magna aliqua. Ut enim ad minim veniam,", 12 | "quis nostrud exercitation ullamco laboris nisi", 13 | "ut aliquip ex ea commodo consequat. Duis aute", 14 | "irure dolor in reprehenderit in voluptate velit", 15 | "esse cillum dolore eu fugiat nulla pariatur.", 16 | "Excepteur sint occaecat cupidatat non proident,", 17 | "sunt in culpa qui officia deserunt mollit anim id est laborum." 18 | ], 19 | "exclude-algos": [ 20 | "lbry", "bcrypt", "cryptonight", "cryptonightfast", "neoscrypt" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /tests/vectors/set2-input.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "description": "80-bytes strings", 4 | "date": "Wed Aug 12 09:24:38 UTC 2020", 5 | "license": "CCL0" 6 | }, 7 | "strings": [ 8 | "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the ", 9 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor ", 10 | "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr", 11 | "ud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis au", 12 | "te irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat ", 13 | "nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qu", 14 | "i officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, conse", 15 | "ctetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore ma", 16 | "gna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris n", 17 | "isi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit i" 18 | ], 19 | "exclude-algos": [ 20 | "lbry" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /tests/vectors/set3-input.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "description": "120-bytes strings", 4 | "date": "Wed Aug 12 09:24:38 UTC 2020", 5 | "license": "CCL0" 6 | }, 7 | "strings": [ 8 | "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over", 9 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna ali", 10 | "qua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis au", 11 | "te irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat ", 12 | "cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, conse", 13 | "ctetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, qui", 14 | "s nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit i", 15 | "n voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in c", 16 | "ulpa qui officia deserunt mollit anim idest laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do ei", 17 | "usmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco lab" 18 | ] 19 | } 20 | --------------------------------------------------------------------------------