├── mixhash ├── __init__.pyc ├── x11 │ ├── x11.h │ ├── module.c │ └── x11.c ├── qubit │ ├── qubit.h │ ├── module.c │ └── qubit.c ├── keccak │ ├── keccak.h │ ├── keccak.c │ └── module.c ├── lyra2 │ ├── Lyra2RE.h │ ├── lyra2remodule.c │ ├── lyra2re2module.c │ ├── Lyra2.h │ ├── Lyra2RE.c │ └── Sponge.h ├── sha3 │ ├── makefile │ ├── sph_fugue.h │ ├── sph_hefty1.h │ ├── blake2s.h │ ├── hashblock.h │ ├── haval_helper.c │ ├── qubit.c │ ├── sph_tiger.h │ ├── sph_whirlpool.h │ ├── sph_sha2big.c │ ├── sph_ripemd.h │ ├── sph_jh.h │ ├── sph_keccak.h │ ├── sph_luffa.h │ ├── sph_cubehash.h │ ├── sph_skein.h │ ├── blake2s.c │ ├── sph_simd.h │ ├── sph_echo.h │ ├── sph_bmw.h │ ├── sph_hamsi.h │ ├── md_helper.c │ └── sph_shavite.h ├── neoscrypt │ ├── module.c │ └── neoscrypt.h └── __init__.py ├── MANIFEST.in ├── README.md ├── .gitignore └── setup.py /mixhash/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nasa8x/mixhash/master/mixhash/__init__.pyc -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include setup.py 2 | include README.md 3 | recursive-include mixhash *.py *.c *.h 4 | prune build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Make Genesis Block Proof of Work for multiple Hash Algorithms. 2 | 3 | 4 | ## How to create Genesis Block 5 | https://github.com/nasa8x/genesis-block 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist 4 | build 5 | .vscode 6 | *.log 7 | *.rar 8 | *.zip 9 | .svn/* 10 | obj/* 11 | *.bak 12 | config.js 13 | **/env/prod.js 14 | note.txt 15 | gen.py 16 | test.py -------------------------------------------------------------------------------- /mixhash/x11/x11.h: -------------------------------------------------------------------------------- 1 | #ifndef X13_H 2 | #define X13_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void x11_hash(const char* input, char* output); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /mixhash/qubit/qubit.h: -------------------------------------------------------------------------------- 1 | #ifndef QUBIT_H 2 | #define QUBIT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void qubit_hash(const char* input, char* output); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /mixhash/keccak/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 kaccak_hash(const char* input, char* output); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // KECCAK_H 17 | -------------------------------------------------------------------------------- /mixhash/lyra2/Lyra2RE.h: -------------------------------------------------------------------------------- 1 | #ifndef LYRA2RE_H 2 | #define LYRA2RE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void lyra2re_hash(const char* input, char* output); 9 | void lyra2re2_hash(const char* input, char* output); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /mixhash/sha3/makefile: -------------------------------------------------------------------------------- 1 | 2 | CC=gcc 3 | 4 | CFLAGS= -O3 -march=native 5 | LDFLAGS=-O2 6 | 7 | SOURCES=sph_jh.c sph_blake.c sph_bmw.c sph_groestl.c sph_skein.c sph_keccak.c sph_luffa.c sph_cubehash.c sph_shavite.c \ 8 | sph_simd.c sph_echo.c sph_fugue.c sph_hamsi.c sph_shabal.c sph_whirlpool.c \ 9 | sph_haval.c sph_hefty1.c sph_ripemd.c sph_sha2.c sph_sha2big.c sph_tiger.c \ 10 | blake2s.c 11 | 12 | OBJECTS=$(SOURCES:.c=.o) 13 | OUTPUT=libhash.a 14 | 15 | all: $(SOURCES) $(OUTPUT) 16 | 17 | $(OUTPUT): $(OBJECTS) 18 | ar rc $@ $(OBJECTS) 19 | touch ../stratum.cpp 20 | 21 | .cpp.o: 22 | $(CC) $(CFLAGS) -c $< 23 | 24 | .c.o: 25 | $(CC) $(CFLAGS) -c $< 26 | 27 | blake2s.o: blake2s.c 28 | $(CC) $(CFLAGS) -std=gnu99 -c $< 29 | 30 | clean: 31 | rm *.o 32 | 33 | 34 | -------------------------------------------------------------------------------- /mixhash/neoscrypt/module.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "neoscrypt.h" 4 | 5 | static PyObject *neoscrypt_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | unsigned char *output; 8 | PyObject *value; 9 | PyStringObject *input; 10 | if (!PyArg_ParseTuple(args, "S", &input)) 11 | return NULL; 12 | Py_INCREF(input); 13 | output = PyMem_Malloc(32); 14 | 15 | neoscrypt((unsigned char *)PyString_AsString((PyObject*) input), output); 16 | 17 | Py_DECREF(input); 18 | value = Py_BuildValue("s#", output, 32); 19 | PyMem_Free(output); 20 | return value; 21 | } 22 | 23 | static PyMethodDef NeoScryptMethods[] = { 24 | { "getPoWHash", neoscrypt_getpowhash, METH_VARARGS, "Returns proof-of-work hash using NeoScrypt" }, 25 | { NULL, NULL, 0, NULL } 26 | }; 27 | 28 | PyMODINIT_FUNC initneoscrypt(void) { 29 | (void) Py_InitModule("neoscrypt", NeoScryptMethods); 30 | } 31 | -------------------------------------------------------------------------------- /mixhash/neoscrypt/neoscrypt.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | void neoscrypt(const unsigned char *input, unsigned char *output); 7 | 8 | #define SCRYPT_BLOCK_SIZE 64 9 | #define SCRYPT_HASH_BLOCK_SIZE 64 10 | #define SCRYPT_HASH_DIGEST_SIZE 32 11 | 12 | typedef uint8_t hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 13 | 14 | #define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b))) 15 | #define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b))) 16 | 17 | #define U8TO32_BE(p) \ 18 | (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ 19 | ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]))) 20 | 21 | #define U32TO8_BE(p, v) \ 22 | (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ 23 | (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); 24 | 25 | #define U64TO8_BE(p, v) \ 26 | U32TO8_BE((p), (uint32_t)((v) >> 32)); \ 27 | U32TO8_BE((p) + 4, (uint32_t)((v) )); 28 | -------------------------------------------------------------------------------- /mixhash/keccak/keccak.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../sha3/sph_types.h" 8 | #include "../sha3/sph_keccak.h" 9 | 10 | #include "keccak.h" 11 | 12 | 13 | void keccak_hash(const char *input, char *output, uint32_t len) 14 | { 15 | uint32_t hash[16]; 16 | 17 | sph_keccak256_context ctx_keccak; 18 | //uint32_t len = 80; 19 | 20 | sph_keccak256_init(&ctx_keccak); 21 | sph_keccak256(&ctx_keccak, input, len /* 80 */); 22 | sph_keccak256_close(&ctx_keccak, hash); 23 | 24 | memcpy(output, hash, 32); 25 | 26 | } 27 | 28 | //void keccak512_hash(const char *input, char *output, uint32_t len) 29 | //{ 30 | // uint32_t hash[16]; 31 | // 32 | // sph_keccak512_context ctx_keccak; 33 | // 34 | // sph_keccak512_init(&ctx_keccak); 35 | // sph_keccak512(&ctx_keccak, input, len); 36 | // sph_keccak512_close(&ctx_keccak, hash); 37 | // 38 | // memcpy(output, hash, 32); 39 | //} 40 | -------------------------------------------------------------------------------- /mixhash/x11/module.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "x11.h" 4 | 5 | static PyObject *x11_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | char *output; 8 | PyObject *value; 9 | #if PY_MAJOR_VERSION >= 3 10 | PyBytesObject *input; 11 | #else 12 | PyStringObject *input; 13 | #endif 14 | if (!PyArg_ParseTuple(args, "S", &input)) 15 | return NULL; 16 | Py_INCREF(input); 17 | output = PyMem_Malloc(32); 18 | 19 | #if PY_MAJOR_VERSION >= 3 20 | x11_hash((char *)PyBytes_AsString((PyObject*) input), output); 21 | #else 22 | x11_hash((char *)PyString_AsString((PyObject*) input), output); 23 | #endif 24 | Py_DECREF(input); 25 | #if PY_MAJOR_VERSION >= 3 26 | value = Py_BuildValue("y#", output, 32); 27 | #else 28 | value = Py_BuildValue("s#", output, 32); 29 | #endif 30 | PyMem_Free(output); 31 | return value; 32 | } 33 | 34 | static PyMethodDef X11Methods[] = { 35 | { "getPoWHash", x11_getpowhash, METH_VARARGS, "Returns the proof of work hash using x11 hash" }, 36 | { NULL, NULL, 0, NULL } 37 | }; 38 | 39 | #if PY_MAJOR_VERSION >= 3 40 | static struct PyModuleDef X11Module = { 41 | PyModuleDef_HEAD_INIT, 42 | "x11_hash", 43 | "...", 44 | -1, 45 | X11Methods 46 | }; 47 | 48 | PyMODINIT_FUNC PyInit_x11_hash(void) { 49 | return PyModule_Create(&X11Module); 50 | } 51 | 52 | #else 53 | 54 | PyMODINIT_FUNC initx11_hash(void) { 55 | (void) Py_InitModule("x11_hash", X11Methods); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /mixhash/__init__.py: -------------------------------------------------------------------------------- 1 | import hashlib, qubit_hash, keccak_hash, lyra2re_hash, neoscrypt, x11_hash 2 | # import lyra2re2_hash 3 | # import lyra2re_hash 4 | # import qubit_hash 5 | 6 | # def SHA256Hash(x): 7 | # """Equivalent to hashlib.sha256(x).digest().""" 8 | # return hashlib.sha256(x).digest() 9 | 10 | def SHA256(x): 11 | """Two rounds of SHA256.""" 12 | return hashlib.sha256(hashlib.sha256(x).digest()).digest() 13 | 14 | def Lyra2re(x): 15 | return lyra2re_hash.getPoWHash(x) 16 | 17 | # def Lyra2re2(x): 18 | # return lyra2re2_hash.getPoWHash(x) 19 | 20 | def Keccak(x): 21 | return keccak_hash.getPoWHash(x, len(x)) 22 | 23 | def Qubit(x): 24 | return qubit_hash.getPoWHash(x) 25 | 26 | def Neoscrypt(x): 27 | return neoscrypt.getPoWHash(x) 28 | 29 | # def SkeinHash(x): 30 | # return skeinhash.getPoWHash(x) 31 | 32 | # def QubitHash(x): 33 | # return qubit_hash.getPoWHash(x) 34 | 35 | # def GroestlHash(x): 36 | # return groestlcoin_hash.getHash(x, len(x)) 37 | 38 | def X11(x): 39 | return x11_hash.getPoWHash(x) 40 | 41 | # def ScryptHash(x): 42 | # """Scrypt (Litecoin parameters) hash.""" 43 | # return ltc_scrypt.getPoWHash(x) 44 | 45 | # algorithms = { 46 | # # SHA256Hash is not advertised. 47 | # 'SHA256d': SHA256dHash, 48 | # 'NeoScrypt': NeoscryptHash, 49 | # 'Skein': SkeinHash, 50 | # 'Qubit': QubitHash, 51 | # 'Groestl': GroestlHash, 52 | # 'X11': X11Hash, 53 | # 'Scrypt': ScryptHash, 54 | # } 55 | -------------------------------------------------------------------------------- /mixhash/qubit/module.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "qubit.h" 4 | 5 | static PyObject *qubit_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | char *output; 8 | PyObject *value; 9 | #if PY_MAJOR_VERSION >= 3 10 | PyBytesObject *input; 11 | #else 12 | PyStringObject *input; 13 | #endif 14 | if (!PyArg_ParseTuple(args, "S", &input)) 15 | return NULL; 16 | Py_INCREF(input); 17 | output = PyMem_Malloc(32); 18 | 19 | #if PY_MAJOR_VERSION >= 3 20 | qubit_hash((char *)PyBytes_AsString((PyObject*) input), output); 21 | #else 22 | qubit_hash((char *)PyString_AsString((PyObject*) input), output); 23 | #endif 24 | Py_DECREF(input); 25 | #if PY_MAJOR_VERSION >= 3 26 | value = Py_BuildValue("y#", output, 32); 27 | #else 28 | value = Py_BuildValue("s#", output, 32); 29 | #endif 30 | PyMem_Free(output); 31 | return value; 32 | } 33 | 34 | static PyMethodDef QubitMethods[] = { 35 | { "getPoWHash", qubit_getpowhash, METH_VARARGS, "Returns the proof of work hash using qubit hash" }, 36 | { NULL, NULL, 0, NULL } 37 | }; 38 | 39 | #if PY_MAJOR_VERSION >= 3 40 | static struct PyModuleDef QubitModule = { 41 | PyModuleDef_HEAD_INIT, 42 | "qubit_hash", 43 | "...", 44 | -1, 45 | QubitMethods 46 | }; 47 | 48 | PyMODINIT_FUNC PyInit_qubit_hash(void) { 49 | return PyModule_Create(&QubitModule); 50 | } 51 | 52 | #else 53 | 54 | PyMODINIT_FUNC initqubit_hash(void) { 55 | (void) Py_InitModule("qubit_hash", QubitMethods); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /mixhash/lyra2/lyra2remodule.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Lyra2RE.h" 4 | 5 | static PyObject *lyra2re_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | char *output; 8 | PyObject *value; 9 | #if PY_MAJOR_VERSION >= 3 10 | PyBytesObject *input; 11 | #else 12 | PyStringObject *input; 13 | #endif 14 | if (!PyArg_ParseTuple(args, "S", &input)) 15 | return NULL; 16 | Py_INCREF(input); 17 | output = PyMem_Malloc(32); 18 | 19 | #if PY_MAJOR_VERSION >= 3 20 | lyra2re_hash((char *)PyBytes_AsString((PyObject*) input), output); 21 | #else 22 | lyra2re_hash((char *)PyString_AsString((PyObject*) input), output); 23 | #endif 24 | Py_DECREF(input); 25 | #if PY_MAJOR_VERSION >= 3 26 | value = Py_BuildValue("y#", output, 32); 27 | #else 28 | value = Py_BuildValue("s#", output, 32); 29 | #endif 30 | PyMem_Free(output); 31 | return value; 32 | } 33 | 34 | static PyMethodDef Lyra2REMethods[] = { 35 | { "getPoWHash", lyra2re_getpowhash, METH_VARARGS, "Returns the proof of work hash using Lyra2RE hash" }, 36 | { NULL, NULL, 0, NULL } 37 | }; 38 | 39 | #if PY_MAJOR_VERSION >= 3 40 | static struct PyModuleDef Lyra2REModule = { 41 | PyModuleDef_HEAD_INIT, 42 | "lyra2re_hash", 43 | "...", 44 | -1, 45 | Lyra2REMethods 46 | }; 47 | 48 | PyMODINIT_FUNC PyInit_lyra2re_hash(void) { 49 | return PyModule_Create(&Lyra2REModule); 50 | } 51 | 52 | #else 53 | 54 | PyMODINIT_FUNC initlyra2re_hash(void) { 55 | (void) Py_InitModule("lyra2re_hash", Lyra2REMethods); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /mixhash/qubit/qubit.c: -------------------------------------------------------------------------------- 1 | #include "qubit.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include "../sha3/sph_luffa.h" 9 | #include "../sha3/sph_cubehash.h" 10 | #include "../sha3/sph_shavite.h" 11 | #include "../sha3/sph_simd.h" 12 | #include "../sha3/sph_echo.h" 13 | 14 | 15 | void qubit_hash(const char* input, char* output) 16 | { 17 | sph_luffa512_context ctx_luffa1; 18 | sph_cubehash512_context ctx_cubehash1; 19 | sph_shavite512_context ctx_shavite1; 20 | sph_simd512_context ctx_simd1; 21 | sph_echo512_context ctx_echo1; 22 | 23 | //these uint512 in the c++ source of the client are backed by an array of uint32 24 | uint32_t hashA[16], hashB[16]; 25 | 26 | sph_luffa512_init (&ctx_luffa1); 27 | sph_luffa512 (&ctx_luffa1, input, 80); 28 | sph_luffa512_close (&ctx_luffa1, hashA); 29 | 30 | sph_cubehash512_init (&ctx_cubehash1); 31 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 32 | sph_cubehash512_close(&ctx_cubehash1, hashB); 33 | 34 | sph_shavite512_init (&ctx_shavite1); 35 | sph_shavite512 (&ctx_shavite1, hashB, 64); 36 | sph_shavite512_close(&ctx_shavite1, hashA); 37 | 38 | sph_simd512_init (&ctx_simd1); 39 | sph_simd512 (&ctx_simd1, hashA, 64); 40 | sph_simd512_close(&ctx_simd1, hashB); 41 | 42 | sph_echo512_init (&ctx_echo1); 43 | sph_echo512 (&ctx_echo1, hashB, 64); 44 | sph_echo512_close(&ctx_echo1, hashA); 45 | 46 | memcpy(output, hashA, 32); 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /mixhash/lyra2/lyra2re2module.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Lyra2RE.h" 4 | 5 | static PyObject *lyra2re2_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | char *output; 8 | PyObject *value; 9 | #if PY_MAJOR_VERSION >= 3 10 | PyBytesObject *input; 11 | #else 12 | PyStringObject *input; 13 | #endif 14 | if (!PyArg_ParseTuple(args, "S", &input)) 15 | return NULL; 16 | Py_INCREF(input); 17 | output = PyMem_Malloc(32); 18 | 19 | #if PY_MAJOR_VERSION >= 3 20 | lyra2re2_hash((char *)PyBytes_AsString((PyObject*) input), output); 21 | #else 22 | lyra2re2_hash((char *)PyString_AsString((PyObject*) input), output); 23 | #endif 24 | Py_DECREF(input); 25 | #if PY_MAJOR_VERSION >= 3 26 | value = Py_BuildValue("y#", output, 32); 27 | #else 28 | value = Py_BuildValue("s#", output, 32); 29 | #endif 30 | PyMem_Free(output); 31 | return value; 32 | } 33 | 34 | static PyMethodDef Lyra2RE2Methods[] = { 35 | { "getPoWHash", lyra2re2_getpowhash, METH_VARARGS, "Returns the proof of work hash using Lyra2RE hash" }, 36 | { NULL, NULL, 0, NULL } 37 | }; 38 | 39 | #if PY_MAJOR_VERSION >= 3 40 | static struct PyModuleDef Lyra2RE2Module = { 41 | PyModuleDef_HEAD_INIT, 42 | "lyra2re2_hash", 43 | "...", 44 | -1, 45 | Lyra2RE2Methods 46 | }; 47 | 48 | PyMODINIT_FUNC PyInit_lyra2re2_hash(void) { 49 | return PyModule_Create(&Lyra2RE2Module); 50 | } 51 | 52 | #else 53 | 54 | PyMODINIT_FUNC initlyra2re2_hash(void) { 55 | (void) Py_InitModule("mixhash_lyra2re2", Lyra2RE2Methods); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /mixhash/keccak/module.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "keccak.h" 4 | 5 | static PyObject *keccak_getpowhash(PyObject *self, PyObject *args) 6 | { 7 | 8 | char *output; 9 | PyObject *value; 10 | #if PY_MAJOR_VERSION >= 3 11 | PyBytesObject *input; 12 | #else 13 | PyStringObject *input; 14 | #endif 15 | int length; 16 | if (!PyArg_ParseTuple(args, "Si", &input,&length)) 17 | return NULL; 18 | Py_INCREF(input); 19 | output = PyMem_Malloc(32); 20 | 21 | #if PY_MAJOR_VERSION >= 3 22 | keccak_hash((char *)PyBytes_AsString((PyObject*) input), output, length); 23 | #else 24 | keccak_hash((char *)PyString_AsString((PyObject*) input), output, length); 25 | #endif 26 | Py_DECREF(input); 27 | #if PY_MAJOR_VERSION >= 3 28 | value = Py_BuildValue("y#", output, 32); 29 | #else 30 | value = Py_BuildValue("s#", output, 32); 31 | #endif 32 | PyMem_Free(output); 33 | return value; 34 | } 35 | 36 | static PyMethodDef KeccakMethods[] = { 37 | { "getPoWHash", keccak_getpowhash, METH_VARARGS, "Returns the proof of work hash using Keccak hash" }, 38 | { NULL, NULL, 0, NULL } 39 | }; 40 | 41 | #if PY_MAJOR_VERSION >= 3 42 | static struct PyModuleDef KeccakModule = { 43 | PyModuleDef_HEAD_INIT, 44 | "keccak_hash", 45 | "...", 46 | -1, 47 | KeccakMethods 48 | }; 49 | 50 | PyMODINIT_FUNC PyInit_keccak_hash(void) { 51 | return PyModule_Create(&KeccakModule); 52 | } 53 | 54 | #else 55 | 56 | PyMODINIT_FUNC initkeccak_hash(void) { 57 | (void) Py_InitModule("keccak_hash", KeccakMethods); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /mixhash/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 -------------------------------------------------------------------------------- /mixhash/lyra2/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_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); 43 | 44 | #endif /* LYRA2_H_ */ 45 | -------------------------------------------------------------------------------- /mixhash/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__ */ -------------------------------------------------------------------------------- /mixhash/x11/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 | void x11_hash(const char* input, char* output) 20 | { 21 | sph_blake512_context ctx_blake; 22 | sph_bmw512_context ctx_bmw; 23 | sph_groestl512_context ctx_groestl; 24 | sph_skein512_context ctx_skein; 25 | sph_jh512_context ctx_jh; 26 | sph_keccak512_context ctx_keccak; 27 | sph_luffa512_context ctx_luffa1; 28 | sph_cubehash512_context ctx_cubehash1; 29 | sph_shavite512_context ctx_shavite1; 30 | sph_simd512_context ctx_simd1; 31 | sph_echo512_context ctx_echo1; 32 | 33 | //these uint512 in the c++ source of the client are backed by an array of uint32 34 | uint32_t hashA[16], hashB[16]; 35 | 36 | sph_blake512_init(&ctx_blake); 37 | sph_blake512 (&ctx_blake, input, 80); 38 | sph_blake512_close (&ctx_blake, hashA); 39 | 40 | sph_bmw512_init(&ctx_bmw); 41 | sph_bmw512 (&ctx_bmw, hashA, 64); 42 | sph_bmw512_close(&ctx_bmw, hashB); 43 | 44 | sph_groestl512_init(&ctx_groestl); 45 | sph_groestl512 (&ctx_groestl, hashB, 64); 46 | sph_groestl512_close(&ctx_groestl, hashA); 47 | 48 | sph_skein512_init(&ctx_skein); 49 | sph_skein512 (&ctx_skein, hashA, 64); 50 | sph_skein512_close (&ctx_skein, hashB); 51 | 52 | sph_jh512_init(&ctx_jh); 53 | sph_jh512 (&ctx_jh, hashB, 64); 54 | sph_jh512_close(&ctx_jh, hashA); 55 | 56 | sph_keccak512_init(&ctx_keccak); 57 | sph_keccak512 (&ctx_keccak, hashA, 64); 58 | sph_keccak512_close(&ctx_keccak, hashB); 59 | 60 | sph_luffa512_init (&ctx_luffa1); 61 | sph_luffa512 (&ctx_luffa1, hashB, 64); 62 | sph_luffa512_close (&ctx_luffa1, hashA); 63 | 64 | sph_cubehash512_init (&ctx_cubehash1); 65 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 66 | sph_cubehash512_close(&ctx_cubehash1, hashB); 67 | 68 | sph_shavite512_init (&ctx_shavite1); 69 | sph_shavite512 (&ctx_shavite1, hashB, 64); 70 | sph_shavite512_close(&ctx_shavite1, hashA); 71 | 72 | sph_simd512_init (&ctx_simd1); 73 | sph_simd512 (&ctx_simd1, hashA, 64); 74 | sph_simd512_close(&ctx_simd1, hashB); 75 | 76 | sph_echo512_init (&ctx_echo1); 77 | sph_echo512 (&ctx_echo1, hashB, 64); 78 | sph_echo512_close(&ctx_echo1, hashA); 79 | 80 | memcpy(output, hashA, 32); 81 | 82 | } 83 | 84 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | 3 | keccak_hash_module = Extension('keccak_hash', 4 | sources = [ 5 | 'mixhash/keccak/module.c', 6 | 'mixhash/keccak/keccak.c', 7 | 'mixhash/sha3/keccak.c' 8 | 9 | ], 10 | include_dirs=['mixhash/keccak','mixhash/sha3']) 11 | 12 | qubit_hash_module = Extension('qubit_hash', 13 | sources = ['mixhash/qubit/module.c', 14 | 'mixhash/qubit/qubit.c', 15 | 'mixhash/sha3/cubehash.c', 16 | 'mixhash/sha3/echo.c', 17 | 'mixhash/sha3/luffa.c', 18 | 'mixhash/sha3/simd.c', 19 | 'mixhash/sha3/shavite.c' 20 | ], 21 | include_dirs=['mixhash/qubit', 'mixhash/sha3']) 22 | 23 | 24 | 25 | lyra2re_hash_module = Extension('lyra2re_hash', 26 | sources = [ 27 | 'mixhash/lyra2/lyra2remodule.c', 28 | 'mixhash/lyra2/Lyra2RE.c', 29 | 'mixhash/lyra2/Sponge.c', 30 | 'mixhash/lyra2/Lyra2.c', 31 | 'mixhash/sha3/blake.c', 32 | 'mixhash/sha3/groestl.c', 33 | 'mixhash/sha3/keccak.c', 34 | 'mixhash/sha3/cubehash.c', 35 | 'mixhash/sha3/bmw.c', 36 | 'mixhash/sha3/skein.c'], 37 | include_dirs=['mixhash/lyra2','mixhash/sha3']) 38 | 39 | # lyra2re2_hash_module = Extension('lyra2re2_hash', 40 | # sources = [ 41 | # 'mixhash/lyra2/lyra2re2module.c', 42 | # 'mixhash/lyra2/Lyra2RE.c', 43 | # 'mixhash/lyra2/Sponge.c', 44 | # 'mixhash/lyra2/Lyra2.c', 45 | # 'mixhash/sha3/blake.c', 46 | # 'mixhash/sha3/groestl.c', 47 | # 'mixhash/sha3/keccak.c', 48 | # 'mixhash/sha3/cubehash.c', 49 | # 'mixhash/sha3/bmw.c', 50 | # 'mixhash/sha3/skein.c'], 51 | # include_dirs=['mixhash/lyra2','mixhash/sha3']) 52 | 53 | neoscrypt_module = Extension('neoscrypt', 54 | sources = ['mixhash/neoscrypt/module.c', 55 | 'mixhash/neoscrypt/neoscrypt.c'], 56 | include_dirs=['mixhash/neoscrypt']) 57 | 58 | x11_hash_module = Extension('x11_hash', 59 | sources = ['mixhash/x11/module.c', 60 | 'mixhash/x11/x11.c', 61 | 'mixhash/sha3/sph_blake.c', 62 | 'mixhash/sha3/sph_bmw.c', 63 | 'mixhash/sha3/sph_groestl.c', 64 | 'mixhash/sha3/sph_skein.c', 65 | 'mixhash/sha3/sph_jh.c', 66 | 'mixhash/sha3/sph_keccak.c', 67 | 'mixhash/sha3/sph_luffa.c', 68 | 'mixhash/sha3/sph_cubehash.c', 69 | 'mixhash/sha3/sph_shavite.c', 70 | 'mixhash/sha3/sph_simd.c', 71 | 'mixhash/sha3/sph_echo.c'], 72 | 73 | include_dirs=['mixhash/x11', 'mixhash/sha3']) 74 | 75 | 76 | setup ( name = 'mixhash', 77 | version = '1.0.1', 78 | description = 'Make Genesis Block Proof of Work for multiple Hash Algorithms.', 79 | long_description = 'Make Genesis Block Proof of Work for multiple Hash Algorithms.', 80 | maintainer = 'Nasa Nguyen', 81 | maintainer_email = 'nasa8x@mail.com', 82 | url = 'https://github.com/nasa8x/mixhash', 83 | keywords = ['cryptocurrency', 'coin','bitcoin', 'dash','litecoin', 'scrypt', 'neoscrypt', 'x11', 'qubit', 'skein', 'groestl'], 84 | package_dir = {'mixhash': 'mixhash'}, 85 | py_modules = ['mixhash.__init__'], 86 | ext_modules = [ lyra2re_hash_module, qubit_hash_module, keccak_hash_module, neoscrypt_module, x11_hash_module]) 87 | 88 | -------------------------------------------------------------------------------- /mixhash/lyra2/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 "Lyra2.h" 42 | 43 | void lyra2re_hash(const char* input, char* output) 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_init(&ctx_blake); 53 | sph_blake256 (&ctx_blake, input, 80); 54 | sph_blake256_close (&ctx_blake, hashA); 55 | 56 | sph_keccak256_init(&ctx_keccak); 57 | sph_keccak256 (&ctx_keccak,hashA, 32); 58 | sph_keccak256_close(&ctx_keccak, hashB); 59 | 60 | LYRA2_old(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 61 | 62 | sph_skein256_init(&ctx_skein); 63 | sph_skein256 (&ctx_skein, hashA, 32); 64 | sph_skein256_close(&ctx_skein, hashB); 65 | 66 | sph_groestl256_init(&ctx_groestl); 67 | sph_groestl256 (&ctx_groestl, hashB, 32); 68 | sph_groestl256_close(&ctx_groestl, hashA); 69 | 70 | memcpy(output, hashA, 32); 71 | } 72 | 73 | void lyra2re2_hash(const char* input, char* output) 74 | { 75 | sph_blake256_context ctx_blake; 76 | sph_cubehash256_context ctx_cubehash; 77 | sph_keccak256_context ctx_keccak; 78 | sph_skein256_context ctx_skein; 79 | sph_bmw256_context ctx_bmw; 80 | 81 | uint32_t hashA[8], hashB[8]; 82 | 83 | sph_blake256_init(&ctx_blake); 84 | sph_blake256(&ctx_blake, input, 80); 85 | sph_blake256_close (&ctx_blake, hashA); 86 | 87 | sph_keccak256_init(&ctx_keccak); 88 | sph_keccak256(&ctx_keccak, hashA, 32); 89 | sph_keccak256_close(&ctx_keccak, hashB); 90 | 91 | sph_cubehash256_init(&ctx_cubehash); 92 | sph_cubehash256(&ctx_cubehash, hashB, 32); 93 | sph_cubehash256_close(&ctx_cubehash, hashA); 94 | 95 | LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); 96 | 97 | sph_skein256_init(&ctx_skein); 98 | sph_skein256(&ctx_skein, hashB, 32); 99 | sph_skein256_close(&ctx_skein, hashA); 100 | 101 | sph_cubehash256_init(&ctx_cubehash); 102 | sph_cubehash256(&ctx_cubehash, hashA, 32); 103 | sph_cubehash256_close(&ctx_cubehash, hashB); 104 | 105 | sph_bmw256_init(&ctx_bmw); 106 | sph_bmw256(&ctx_bmw, hashB, 32); 107 | sph_bmw256_close(&ctx_bmw, hashA); 108 | 109 | memcpy(output, hashA, 32); 110 | } 111 | -------------------------------------------------------------------------------- /mixhash/lyra2/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 | -------------------------------------------------------------------------------- /mixhash/sha3/blake2s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * BLAKE2 reference source code package - reference C implementations 3 | * 4 | * Written in 2012 by Samuel Neves 5 | * 6 | * To the extent possible under law, the author(s) have dedicated all copyright 7 | * and related and neighboring rights to this software to the public domain 8 | * worldwide. This software is distributed without any warranty. 9 | * 10 | * You should have received a copy of the CC0 Public Domain Dedication along with 11 | * this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #include 22 | #define inline __inline 23 | #define ALIGN(x) __declspec(align(x)) 24 | #else 25 | #define ALIGN(x) __attribute__((aligned(x))) 26 | #endif 27 | 28 | #if defined(_MSC_VER) || defined(__x86_64__) || defined(__x86__) 29 | #define NATIVE_LITTLE_ENDIAN 30 | #endif 31 | 32 | /* blake2-impl.h */ 33 | 34 | static inline uint32_t load32(const void *src) 35 | { 36 | #if defined(NATIVE_LITTLE_ENDIAN) 37 | return *(uint32_t *)(src); 38 | #else 39 | const uint8_t *p = (uint8_t *)src; 40 | uint32_t w = *p++; 41 | w |= (uint32_t)(*p++) << 8; 42 | w |= (uint32_t)(*p++) << 16; 43 | w |= (uint32_t)(*p++) << 24; 44 | return w; 45 | #endif 46 | } 47 | 48 | static inline void store32(void *dst, uint32_t w) 49 | { 50 | #if defined(NATIVE_LITTLE_ENDIAN) 51 | *(uint32_t *)(dst) = w; 52 | #else 53 | uint8_t *p = (uint8_t *)dst; 54 | *p++ = (uint8_t)w; w >>= 8; 55 | *p++ = (uint8_t)w; w >>= 8; 56 | *p++ = (uint8_t)w; w >>= 8; 57 | *p++ = (uint8_t)w; 58 | #endif 59 | } 60 | 61 | static inline uint64_t load48(const void *src) 62 | { 63 | const uint8_t *p = (const uint8_t *)src; 64 | uint64_t w = *p++; 65 | w |= (uint64_t)(*p++) << 8; 66 | w |= (uint64_t)(*p++) << 16; 67 | w |= (uint64_t)(*p++) << 24; 68 | w |= (uint64_t)(*p++) << 32; 69 | w |= (uint64_t)(*p++) << 40; 70 | return w; 71 | } 72 | 73 | static inline void store48(void *dst, uint64_t w) 74 | { 75 | uint8_t *p = (uint8_t *)dst; 76 | *p++ = (uint8_t)w; w >>= 8; 77 | *p++ = (uint8_t)w; w >>= 8; 78 | *p++ = (uint8_t)w; w >>= 8; 79 | *p++ = (uint8_t)w; w >>= 8; 80 | *p++ = (uint8_t)w; w >>= 8; 81 | *p++ = (uint8_t)w; 82 | } 83 | 84 | /* prevents compiler optimizing out memset() */ 85 | static inline void secure_zero_memory(void *v, size_t n) 86 | { 87 | volatile uint8_t *p = ( volatile uint8_t * )v; 88 | 89 | while( n-- ) *p++ = 0; 90 | } 91 | 92 | /* blake2.h */ 93 | 94 | enum blake2s_constant 95 | { 96 | BLAKE2S_BLOCKBYTES = 64, 97 | BLAKE2S_OUTBYTES = 32, 98 | BLAKE2S_KEYBYTES = 32, 99 | BLAKE2S_SALTBYTES = 8, 100 | BLAKE2S_PERSONALBYTES = 8 101 | }; 102 | 103 | #pragma pack(push, 1) 104 | typedef struct __blake2s_param 105 | { 106 | uint8_t digest_length; // 1 107 | uint8_t key_length; // 2 108 | uint8_t fanout; // 3 109 | uint8_t depth; // 4 110 | uint32_t leaf_length; // 8 111 | uint8_t node_offset[6];// 14 112 | uint8_t node_depth; // 15 113 | uint8_t inner_length; // 16 114 | // uint8_t reserved[0]; 115 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 116 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 117 | } blake2s_param; 118 | 119 | ALIGN( 64 ) typedef struct __blake2s_state 120 | { 121 | uint32_t h[8]; 122 | uint32_t t[2]; 123 | uint32_t f[2]; 124 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 125 | size_t buflen; 126 | uint8_t last_node; 127 | } blake2s_state; 128 | #pragma pack(pop) 129 | 130 | #if defined(__cplusplus) 131 | extern "C" { 132 | #endif 133 | 134 | int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] ); 135 | 136 | // Streaming API 137 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 138 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 139 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 140 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 141 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 142 | 143 | // Simple API 144 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | 146 | // Direct Hash Mining Helpers 147 | #define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */ 148 | #define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0) 149 | 150 | #if defined(__cplusplus) 151 | } 152 | #endif 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /mixhash/sha3/hashblock.h: -------------------------------------------------------------------------------- 1 | #ifndef HASHBLOCK_H 2 | #define HASHBLOCK_H 3 | 4 | #include "sph_blake.h" 5 | #include "sph_bmw.h" 6 | #include "sph_groestl.h" 7 | #include "sph_jh.h" 8 | #include "sph_keccak.h" 9 | #include "sph_skein.h" 10 | 11 | 12 | 13 | void Hash9(void *state, const void *init) 14 | { 15 | sph_blake512_context ctx_blake; 16 | sph_bmw512_context ctx_bmw; 17 | sph_groestl512_context ctx_groestl; 18 | sph_jh512_context ctx_jh; 19 | sph_keccak512_context ctx_keccak; 20 | sph_skein512_context ctx_skein; 21 | static unsigned char pblank[1]; 22 | 23 | 24 | uint32_t mask = 8; 25 | uint32_t zero = 0; 26 | 27 | //these uint512 in the c++ source of the client are backed by an array of uint32 28 | uint32_t hashA[16], hashB[16]; 29 | 30 | /* 31 | int ii=0; 32 | printf("Start: "); 33 | for (ii=0; ii < 80; ii++) 34 | { 35 | printf ("%.2x",((uint8_t*)init)[ii]); 36 | }; 37 | printf ("\n"); 38 | */ 39 | 40 | sph_blake512_init(&ctx_blake); 41 | sph_blake512 (&ctx_blake, init, 80); 42 | sph_blake512_close (&ctx_blake, hashA); //0 43 | 44 | /* 45 | printf("bla512: "); 46 | for (ii=0; ii < 64; ii++) 47 | { 48 | printf ("%.2x",((uint8_t*)hashA)[ii]); 49 | }; 50 | printf ("\n"); 51 | */ 52 | 53 | sph_bmw512_init(&ctx_bmw); 54 | sph_bmw512 (&ctx_bmw, hashA, 64); //0 55 | sph_bmw512_close(&ctx_bmw, hashB); //1 56 | 57 | /* 58 | printf("bmw512: "); 59 | for (ii=0; ii < 64; ii++) 60 | { 61 | printf ("%.2x",((uint8_t*)hashB)[ii]); 62 | }; 63 | printf ("\n"); 64 | */ 65 | 66 | if ((hashB[0] & mask) != zero) //1 67 | { 68 | sph_groestl512_init(&ctx_groestl); 69 | sph_groestl512 (&ctx_groestl, hashB, 64); //1 70 | sph_groestl512_close(&ctx_groestl, hashA); //2 71 | } 72 | else 73 | { 74 | sph_skein512_init(&ctx_skein); 75 | sph_skein512 (&ctx_skein, hashB, 64); //1 76 | sph_skein512_close(&ctx_skein, hashA); //2 77 | } 78 | 79 | /* 80 | printf("1stcon: "); 81 | for (ii=0; ii < 64; ii++) 82 | { 83 | printf ("%.2x",((uint8_t*)hashA)[ii]); 84 | }; 85 | printf ("\n"); 86 | */ 87 | 88 | sph_groestl512_init(&ctx_groestl); 89 | sph_groestl512 (&ctx_groestl, hashA, 64); //2 90 | sph_groestl512_close(&ctx_groestl, hashB); //3 91 | 92 | sph_jh512_init(&ctx_jh); 93 | sph_jh512 (&ctx_jh, hashB, 64); //3 94 | sph_jh512_close(&ctx_jh, hashA); //4 95 | 96 | if ((hashA[0] & mask) != zero) //4 97 | { 98 | sph_blake512_init(&ctx_blake); 99 | sph_blake512 (&ctx_blake, hashA, 64); // 100 | sph_blake512_close(&ctx_blake, hashB); //5 101 | } 102 | else 103 | { 104 | sph_bmw512_init(&ctx_bmw); 105 | sph_bmw512 (&ctx_bmw, hashA, 64); //4 106 | sph_bmw512_close(&ctx_bmw, hashB); //5 107 | } 108 | 109 | sph_keccak512_init(&ctx_keccak); 110 | sph_keccak512 (&ctx_keccak,hashB, 64); //5 111 | sph_keccak512_close(&ctx_keccak, hashA); //6 112 | 113 | sph_skein512_init(&ctx_skein); 114 | sph_skein512 (&ctx_skein, hashA, 64); //6 115 | sph_skein512_close(&ctx_skein, hashB); //7 116 | 117 | if ((hashB[0] & mask) != zero) //7 118 | { 119 | sph_keccak512_init(&ctx_keccak); 120 | sph_keccak512 (&ctx_keccak, hashB, 64); // 121 | sph_keccak512_close(&ctx_keccak, hashA); //8 122 | } 123 | else 124 | { 125 | sph_jh512_init(&ctx_jh); 126 | sph_jh512 (&ctx_jh, hashB, 64); //7 127 | sph_jh512_close(&ctx_jh, hashA); //8 128 | } 129 | 130 | /* 131 | printf("result: "); 132 | for (ii=0; ii < 64; ii++) 133 | { 134 | printf ("%.2x",((uint8_t*)hashA)[ii]); 135 | }; 136 | printf ("\n"); 137 | */ 138 | //return hash[8].trim256(); //8 139 | memcpy(state, hashA, 32); 140 | 141 | /* 142 | printf("result: "); 143 | for (ii=0; ii < 32; ii++) 144 | { 145 | printf ("%.2x",((uint8_t*)state)[ii]); 146 | }; 147 | printf ("\n"); 148 | */ 149 | } 150 | 151 | 152 | 153 | void Hash6(void *state, const void *init) 154 | 155 | { 156 | sph_blake512_context ctx_blake; 157 | sph_bmw512_context ctx_bmw; 158 | sph_groestl512_context ctx_groestl; 159 | sph_jh512_context ctx_jh; 160 | sph_keccak512_context ctx_keccak; 161 | sph_skein512_context ctx_skein; 162 | //static unsigned char pblank[1]; 163 | 164 | char hashA[64], hashB[64]; 165 | 166 | sph_blake512_init(&ctx_blake); 167 | sph_blake512 (&ctx_blake, init, 80); 168 | // sph_blake512_close(&ctx_blake, (void*)(&hashA)); 169 | sph_blake512_close (&ctx_blake, hashA); 170 | 171 | sph_bmw512_init(&ctx_bmw); 172 | sph_bmw512 (&ctx_bmw, (const void*)(hashA), 64); 173 | sph_bmw512_close(&ctx_bmw, (void*)(hashB)); 174 | 175 | sph_groestl512_init(&ctx_groestl); 176 | sph_groestl512 (&ctx_groestl, (const void*)(hashB), 64); 177 | sph_groestl512_close(&ctx_groestl, (void*)(hashA)); 178 | 179 | sph_jh512_init(&ctx_jh); 180 | sph_jh512 (&ctx_jh, (const void*)(hashA), 64); 181 | sph_jh512_close(&ctx_jh, (void*)(hashB)); 182 | 183 | sph_keccak512_init(&ctx_keccak); 184 | sph_keccak512 (&ctx_keccak, (const void*)(hashB), 64); 185 | sph_keccak512_close(&ctx_keccak, (void*)(hashA)); 186 | 187 | sph_skein512_init(&ctx_skein); 188 | sph_skein512 (&ctx_skein, (const void*)(hashA), 64); 189 | sph_skein512_close(&ctx_skein, (void*)(hashB)); 190 | 191 | memcpy(state, hashB, 32); 192 | }; 193 | 194 | 195 | #endif // HASHBLOCK_H 196 | -------------------------------------------------------------------------------- /mixhash/sha3/haval_helper.c: -------------------------------------------------------------------------------- 1 | /* $Id: haval_helper.c 218 2010-06-08 17:06:34Z tp $ */ 2 | /* 3 | * Helper code, included (three times !) by HAVAL implementation. 4 | * 5 | * TODO: try to merge this with md_helper.c. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @author Thomas Pornin 33 | */ 34 | 35 | #undef SPH_XCAT 36 | #define SPH_XCAT(a, b) SPH_XCAT_(a, b) 37 | #undef SPH_XCAT_ 38 | #define SPH_XCAT_(a, b) a ## b 39 | 40 | static void 41 | #ifdef SPH_UPTR 42 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short) 43 | #else 44 | SPH_XCAT(haval, PASSES) 45 | #endif 46 | (sph_haval_context *sc, const void *data, size_t len) 47 | { 48 | unsigned current; 49 | 50 | #if SPH_64 51 | current = (unsigned)sc->count & 127U; 52 | #else 53 | current = (unsigned)sc->count_low & 127U; 54 | #endif 55 | while (len > 0) { 56 | unsigned clen; 57 | #if !SPH_64 58 | sph_u32 clow, clow2; 59 | #endif 60 | 61 | clen = 128U - current; 62 | if (clen > len) 63 | clen = len; 64 | memcpy(sc->buf + current, data, clen); 65 | data = (const unsigned char *)data + clen; 66 | current += clen; 67 | len -= clen; 68 | if (current == 128U) { 69 | DSTATE; 70 | IN_PREPARE(sc->buf); 71 | 72 | RSTATE; 73 | SPH_XCAT(CORE, PASSES)(INW); 74 | WSTATE; 75 | current = 0; 76 | } 77 | #if SPH_64 78 | sc->count += clen; 79 | #else 80 | clow = sc->count_low; 81 | clow2 = SPH_T32(clow + clen); 82 | sc->count_low = clow2; 83 | if (clow2 < clow) 84 | sc->count_high ++; 85 | #endif 86 | } 87 | } 88 | 89 | #ifdef SPH_UPTR 90 | static void 91 | SPH_XCAT(haval, PASSES)(sph_haval_context *sc, const void *data, size_t len) 92 | { 93 | unsigned current; 94 | size_t orig_len; 95 | #if !SPH_64 96 | sph_u32 clow, clow2; 97 | #endif 98 | DSTATE; 99 | 100 | if (len < 256U) { 101 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 102 | return; 103 | } 104 | #if SPH_64 105 | current = (unsigned)sc->count & 127U; 106 | #else 107 | current = (unsigned)sc->count_low & 127U; 108 | #endif 109 | if (current > 0) { 110 | unsigned clen; 111 | 112 | clen = 128U - current; 113 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, clen); 114 | data = (const unsigned char *)data + clen; 115 | len -= clen; 116 | } 117 | #if !SPH_UNALIGNED 118 | if (((SPH_UPTR)data & 3U) != 0) { 119 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 120 | return; 121 | } 122 | #endif 123 | orig_len = len; 124 | RSTATE; 125 | while (len >= 128U) { 126 | IN_PREPARE(data); 127 | 128 | SPH_XCAT(CORE, PASSES)(INW); 129 | data = (const unsigned char *)data + 128U; 130 | len -= 128U; 131 | } 132 | WSTATE; 133 | if (len > 0) 134 | memcpy(sc->buf, data, len); 135 | #if SPH_64 136 | sc->count += (sph_u64)orig_len; 137 | #else 138 | clow = sc->count_low; 139 | clow2 = SPH_T32(clow + orig_len); 140 | sc->count_low = clow2; 141 | if (clow2 < clow) 142 | sc->count_high ++; 143 | orig_len >>= 12; 144 | orig_len >>= 10; 145 | orig_len >>= 10; 146 | sc->count_high += orig_len; 147 | #endif 148 | } 149 | #endif 150 | 151 | static void 152 | SPH_XCAT(SPH_XCAT(haval, PASSES), _close)(sph_haval_context *sc, 153 | unsigned ub, unsigned n, void *dst) 154 | { 155 | unsigned current; 156 | DSTATE; 157 | 158 | #if SPH_64 159 | current = (unsigned)sc->count & 127U; 160 | #else 161 | current = (unsigned)sc->count_low & 127U; 162 | #endif 163 | sc->buf[current ++] = (0x01 << n) | ((ub & 0xFF) >> (8 - n)); 164 | RSTATE; 165 | if (current > 118U) { 166 | memset(sc->buf + current, 0, 128U - current); 167 | 168 | do { 169 | IN_PREPARE(sc->buf); 170 | 171 | SPH_XCAT(CORE, PASSES)(INW); 172 | } while (0); 173 | current = 0; 174 | } 175 | memset(sc->buf + current, 0, 118U - current); 176 | sc->buf[118] = 0x01 | (PASSES << 3); 177 | sc->buf[119] = sc->olen << 3; 178 | #if SPH_64 179 | sph_enc64le_aligned(sc->buf + 120, SPH_T64(sc->count << 3)); 180 | #else 181 | sph_enc32le_aligned(sc->buf + 120, SPH_T32(sc->count_low << 3)); 182 | sph_enc32le_aligned(sc->buf + 124, 183 | SPH_T32((sc->count_high << 3) | (sc->count_low >> 29))); 184 | #endif 185 | do { 186 | IN_PREPARE(sc->buf); 187 | 188 | SPH_XCAT(CORE, PASSES)(INW); 189 | } while (0); 190 | 191 | WSTATE; 192 | haval_out(sc, dst); 193 | haval_init(sc, sc->olen, sc->passes); 194 | } 195 | 196 | -------------------------------------------------------------------------------- /mixhash/sha3/qubit.c: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | #include "miner.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sph_luffa.h" 8 | #include "sph_cubehash.h" 9 | #include "sph_shavite.h" 10 | #include "sph_simd.h" 11 | #include "sph_echo.h" 12 | 13 | 14 | /* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */ 15 | typedef struct { 16 | sph_luffa512_context luffa1; 17 | sph_cubehash512_context cubehash1; 18 | sph_shavite512_context shavite1; 19 | sph_simd512_context simd1; 20 | sph_echo512_context echo1; 21 | } qubithash_context_holder; 22 | 23 | qubithash_context_holder base_contexts; 24 | 25 | void init_qubithash_contexts() 26 | { 27 | // sph_blake512_init(&base_contexts.blake1); 28 | sph_luffa512_init(&base_contexts.luffa1); 29 | sph_cubehash512_init(&base_contexts.cubehash1); 30 | sph_shavite512_init(&base_contexts.shavite1); 31 | sph_simd512_init(&base_contexts.simd1); 32 | sph_echo512_init(&base_contexts.echo1); 33 | } 34 | 35 | static void qubithash(void *state, const void *input) 36 | { 37 | qubithash_context_holder ctx; 38 | 39 | //these uint512 in the c++ source of the client are backed by an array of uint32 40 | uint32_t hashA[16], hashB[16]; 41 | 42 | //do one memcopy to get fresh contexts, its faster even with a larger block then issuing 9 memcopies 43 | memcpy(&ctx, &base_contexts, sizeof(base_contexts)); 44 | 45 | sph_luffa512 (&ctx.luffa1, input, 80); 46 | sph_luffa512_close (&ctx.luffa1, hashA); 47 | 48 | sph_cubehash512 (&ctx.cubehash1, hashA, 64); 49 | sph_cubehash512_close(&ctx.cubehash1, hashB); 50 | 51 | sph_shavite512 (&ctx.shavite1, hashB, 64); 52 | sph_shavite512_close(&ctx.shavite1, hashA); 53 | 54 | sph_simd512 (&ctx.simd1, hashA, 64); 55 | sph_simd512_close(&ctx.simd1, hashB); 56 | 57 | sph_echo512 (&ctx.echo1, hashB, 64); 58 | sph_echo512_close(&ctx.echo1, hashA); 59 | 60 | 61 | memcpy(state, hashA, 32); 62 | 63 | } 64 | 65 | int scanhash_qubit(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 66 | uint32_t max_nonce, unsigned long *hashes_done) 67 | { 68 | uint32_t n = pdata[19] - 1; 69 | const uint32_t first_nonce = pdata[19]; 70 | const uint32_t Htarg = ptarget[7]; 71 | 72 | uint32_t hash64[8] __attribute__((aligned(32))); 73 | uint32_t endiandata[32]; 74 | 75 | //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"}; 76 | 77 | //we need bigendian data... 78 | //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 79 | int kk=0; 80 | for (; kk < 32; kk++) 81 | { 82 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 83 | }; 84 | 85 | // if (opt_debug) 86 | // { 87 | // applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce); 88 | // } 89 | 90 | /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */ 91 | /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */ 92 | if (ptarget[7]==0) { 93 | do { 94 | pdata[19] = ++n; 95 | be32enc(&endiandata[19], n); 96 | qubithash(hash64, &endiandata); 97 | if (((hash64[7]&0xFFFFFFFF)==0) && 98 | fulltest(hash64, ptarget)) { 99 | *hashes_done = n - first_nonce + 1; 100 | return true; 101 | } 102 | } while (n < max_nonce && !work_restart[thr_id].restart); 103 | } 104 | else if (ptarget[7]<=0xF) 105 | { 106 | do { 107 | pdata[19] = ++n; 108 | be32enc(&endiandata[19], n); 109 | qubithash(hash64, &endiandata); 110 | if (((hash64[7]&0xFFFFFFF0)==0) && 111 | fulltest(hash64, ptarget)) { 112 | *hashes_done = n - first_nonce + 1; 113 | return true; 114 | } 115 | } while (n < max_nonce && !work_restart[thr_id].restart); 116 | } 117 | else if (ptarget[7]<=0xFF) 118 | { 119 | do { 120 | pdata[19] = ++n; 121 | be32enc(&endiandata[19], n); 122 | qubithash(hash64, &endiandata); 123 | if (((hash64[7]&0xFFFFFF00)==0) && 124 | fulltest(hash64, ptarget)) { 125 | *hashes_done = n - first_nonce + 1; 126 | return true; 127 | } 128 | } while (n < max_nonce && !work_restart[thr_id].restart); 129 | } 130 | else if (ptarget[7]<=0xFFF) 131 | { 132 | do { 133 | pdata[19] = ++n; 134 | be32enc(&endiandata[19], n); 135 | qubithash(hash64, &endiandata); 136 | if (((hash64[7]&0xFFFFF000)==0) && 137 | fulltest(hash64, ptarget)) { 138 | *hashes_done = n - first_nonce + 1; 139 | return true; 140 | } 141 | } while (n < max_nonce && !work_restart[thr_id].restart); 142 | 143 | } 144 | else if (ptarget[7]<=0xFFFF) 145 | { 146 | do { 147 | pdata[19] = ++n; 148 | be32enc(&endiandata[19], n); 149 | qubithash(hash64, &endiandata); 150 | if (((hash64[7]&0xFFFF0000)==0) && 151 | fulltest(hash64, ptarget)) { 152 | *hashes_done = n - first_nonce + 1; 153 | return true; 154 | } 155 | } while (n < max_nonce && !work_restart[thr_id].restart); 156 | 157 | } 158 | else 159 | { 160 | do { 161 | pdata[19] = ++n; 162 | be32enc(&endiandata[19], n); 163 | qubithash(hash64, &endiandata); 164 | if (fulltest(hash64, ptarget)) { 165 | *hashes_done = n - first_nonce + 1; 166 | return true; 167 | } 168 | } while (n < max_nonce && !work_restart[thr_id].restart); 169 | } 170 | 171 | 172 | *hashes_done = n - first_nonce + 1; 173 | pdata[19] = n; 174 | return 0; 175 | } -------------------------------------------------------------------------------- /mixhash/sha3/sph_tiger.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_tiger.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * Tiger / Tiger-2 interface. 4 | * 5 | * Tiger has been published in: R. Anderson, E. Biham, "Tiger: A Fast 6 | * New Hash Function", Fast Software Encryption - FSE'96, LNCS 1039, 7 | * Springer (1996), pp. 89--97. 8 | * 9 | * Tiger2 has never been formally published, but it was described as 10 | * identical to Tiger, except for the padding which is the same in 11 | * Tiger2 as it is in MD4. Fortunately, an implementation of Tiger2 12 | * was submitted to NESSIE, which produced test vectors; the sphlib 13 | * implementation of Tiger2 is compatible with the NESSIE test vectors. 14 | * 15 | * ==========================(LICENSE BEGIN)============================ 16 | * 17 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining 20 | * a copy of this software and associated documentation files (the 21 | * "Software"), to deal in the Software without restriction, including 22 | * without limitation the rights to use, copy, modify, merge, publish, 23 | * distribute, sublicense, and/or sell copies of the Software, and to 24 | * permit persons to whom the Software is furnished to do so, subject to 25 | * the following conditions: 26 | * 27 | * The above copyright notice and this permission notice shall be 28 | * included in all copies or substantial portions of the Software. 29 | * 30 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 31 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 32 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 33 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 34 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 35 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 36 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | * 38 | * ===========================(LICENSE END)============================= 39 | * 40 | * @file sph_tiger.h 41 | * @author Thomas Pornin 42 | */ 43 | 44 | #ifndef SPH_TIGER_H__ 45 | #define SPH_TIGER_H__ 46 | 47 | #include 48 | #include "sph_types.h" 49 | 50 | #if SPH_64 51 | 52 | /** 53 | * Output size (in bits) for Tiger. 54 | */ 55 | #define SPH_SIZE_tiger 192 56 | 57 | /** 58 | * Output size (in bits) for Tiger2. 59 | */ 60 | #define SPH_SIZE_tiger2 192 61 | 62 | /** 63 | * This structure is a context for Tiger computations: it contains the 64 | * intermediate values and some data from the last entered block. Once 65 | * a Tiger computation has been performed, the context can be reused for 66 | * another computation. 67 | * 68 | * The contents of this structure are private. A running Tiger computation 69 | * can be cloned by copying the context (e.g. with a simple 70 | * memcpy()). 71 | */ 72 | typedef struct { 73 | #ifndef DOXYGEN_IGNORE 74 | unsigned char buf[64]; /* first field, for alignment */ 75 | sph_u64 val[3]; 76 | sph_u64 count; 77 | #endif 78 | } sph_tiger_context; 79 | 80 | /** 81 | * Initialize a Tiger context. This process performs no memory allocation. 82 | * 83 | * @param cc the Tiger context (pointer to 84 | * a sph_tiger_context) 85 | */ 86 | void sph_tiger_init(void *cc); 87 | 88 | /** 89 | * Process some data bytes. It is acceptable that len is zero 90 | * (in which case this function does nothing). 91 | * 92 | * @param cc the Tiger context 93 | * @param data the input data 94 | * @param len the input data length (in bytes) 95 | */ 96 | void sph_tiger(void *cc, const void *data, size_t len); 97 | 98 | /** 99 | * Terminate the current Tiger computation and output the result into the 100 | * provided buffer. The destination buffer must be wide enough to 101 | * accomodate the result (24 bytes). The context is automatically 102 | * reinitialized. 103 | * 104 | * @param cc the Tiger context 105 | * @param dst the destination buffer 106 | */ 107 | void sph_tiger_close(void *cc, void *dst); 108 | 109 | /** 110 | * Apply the Tiger compression function on the provided data. The 111 | * msg parameter contains the 8 64-bit input blocks, 112 | * as numerical values (hence after the little-endian decoding). The 113 | * val parameter contains the 3 64-bit input blocks for 114 | * the compression function; the output is written in place in this 115 | * array. 116 | * 117 | * @param msg the message block (8 values) 118 | * @param val the function 192-bit input and output 119 | */ 120 | void sph_tiger_comp(const sph_u64 msg[8], sph_u64 val[3]); 121 | 122 | /** 123 | * This structure is a context for Tiger2 computations. It is identical 124 | * to the Tiger context, and they may be freely exchanged, since the 125 | * difference between Tiger and Tiger2 resides solely in the padding, which 126 | * is computed only in the last computation step. 127 | */ 128 | typedef sph_tiger_context sph_tiger2_context; 129 | 130 | #ifdef DOXYGEN_IGNORE 131 | /** 132 | * Initialize a Tiger2 context. This function is identical to 133 | * sph_tiger_init(). 134 | * 135 | * @param cc the Tiger2 context (pointer to 136 | * a sph_tiger2_context) 137 | */ 138 | void sph_tiger2_init(void *cc); 139 | #endif 140 | 141 | #ifndef DOXYGEN_IGNORE 142 | #define sph_tiger2_init sph_tiger_init 143 | #endif 144 | 145 | #ifdef DOXYGEN_IGNORE 146 | /** 147 | * Process some data bytes. This function is identical to 148 | * sph_tiger(). 149 | * 150 | * @param cc the Tiger2 context 151 | * @param data the input data 152 | * @param len the input data length (in bytes) 153 | */ 154 | void sph_tiger2(void *cc, const void *data, size_t len); 155 | #endif 156 | 157 | #ifndef DOXYGEN_IGNORE 158 | #define sph_tiger2 sph_tiger 159 | #endif 160 | 161 | /** 162 | * Terminate the current Tiger2 computation and output the result into the 163 | * provided buffer. The destination buffer must be wide enough to 164 | * accomodate the result (24 bytes). The context is automatically 165 | * reinitialized. Note that this function is NOT identical to 166 | * sph_tiger2_close(): this is the exact and unique point 167 | * where Tiger and Tiger2 differ. 168 | * 169 | * @param cc the Tiger context 170 | * @param dst the destination buffer 171 | */ 172 | void sph_tiger2_close(void *cc, void *dst); 173 | 174 | #ifdef DOXYGEN_IGNORE 175 | /** 176 | * Apply the Tiger2 compression function, which is identical to the Tiger 177 | * compression function. 178 | * 179 | * @param msg the message block (8 values) 180 | * @param val the function 192-bit input and output 181 | */ 182 | void sph_tiger2_comp(const sph_u64 msg[8], sph_u64 val[3]); 183 | #endif 184 | 185 | #ifndef DOXYGEN_IGNORE 186 | #define sph_tiger2_comp sph_tiger_comp 187 | #endif 188 | 189 | #endif 190 | 191 | #endif 192 | 193 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_whirlpool.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_whirlpool.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * WHIRLPOOL interface. 4 | * 5 | * WHIRLPOOL knows three variants, dubbed "WHIRLPOOL-0" (original 6 | * version, published in 2000, studied by NESSIE), "WHIRLPOOL-1" 7 | * (first revision, 2001, with a new S-box) and "WHIRLPOOL" (current 8 | * version, 2003, with a new diffusion matrix, also described as "plain 9 | * WHIRLPOOL"). All three variants are implemented here. 10 | * 11 | * The original WHIRLPOOL (i.e. WHIRLPOOL-0) was published in: P. S. L. 12 | * M. Barreto, V. Rijmen, "The Whirlpool Hashing Function", First open 13 | * NESSIE Workshop, Leuven, Belgium, November 13--14, 2000. 14 | * 15 | * The current WHIRLPOOL specification and a reference implementation 16 | * can be found on the WHIRLPOOL web page: 17 | * http://paginas.terra.com.br/informatica/paulobarreto/WhirlpoolPage.html 18 | * 19 | * ==========================(LICENSE BEGIN)============================ 20 | * 21 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining 24 | * a copy of this software and associated documentation files (the 25 | * "Software"), to deal in the Software without restriction, including 26 | * without limitation the rights to use, copy, modify, merge, publish, 27 | * distribute, sublicense, and/or sell copies of the Software, and to 28 | * permit persons to whom the Software is furnished to do so, subject to 29 | * the following conditions: 30 | * 31 | * The above copyright notice and this permission notice shall be 32 | * included in all copies or substantial portions of the Software. 33 | * 34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 35 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 36 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 37 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 38 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 39 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 40 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | * 42 | * ===========================(LICENSE END)============================= 43 | * 44 | * @file sph_whirlpool.h 45 | * @author Thomas Pornin 46 | */ 47 | 48 | #ifndef SPH_WHIRLPOOL_H__ 49 | #define SPH_WHIRLPOOL_H__ 50 | 51 | #include 52 | #include "sph_types.h" 53 | 54 | #if SPH_64 55 | 56 | /** 57 | * Output size (in bits) for WHIRLPOOL. 58 | */ 59 | #define SPH_SIZE_whirlpool 512 60 | 61 | /** 62 | * Output size (in bits) for WHIRLPOOL-0. 63 | */ 64 | #define SPH_SIZE_whirlpool0 512 65 | 66 | /** 67 | * Output size (in bits) for WHIRLPOOL-1. 68 | */ 69 | #define SPH_SIZE_whirlpool1 512 70 | 71 | /** 72 | * This structure is a context for WHIRLPOOL computations: it contains the 73 | * intermediate values and some data from the last entered block. Once 74 | * a WHIRLPOOL computation has been performed, the context can be reused for 75 | * another computation. 76 | * 77 | * The contents of this structure are private. A running WHIRLPOOL computation 78 | * can be cloned by copying the context (e.g. with a simple 79 | * memcpy()). 80 | */ 81 | typedef struct { 82 | #ifndef DOXYGEN_IGNORE 83 | unsigned char buf[64]; /* first field, for alignment */ 84 | sph_u64 state[8]; 85 | #if SPH_64 86 | sph_u64 count; 87 | #else 88 | sph_u32 count_high, count_low; 89 | #endif 90 | #endif 91 | } sph_whirlpool_context; 92 | 93 | /** 94 | * Initialize a WHIRLPOOL context. This process performs no memory allocation. 95 | * 96 | * @param cc the WHIRLPOOL context (pointer to a 97 | * sph_whirlpool_context) 98 | */ 99 | void sph_whirlpool_init(void *cc); 100 | 101 | /** 102 | * Process some data bytes. It is acceptable that len is zero 103 | * (in which case this function does nothing). This function applies the 104 | * plain WHIRLPOOL algorithm. 105 | * 106 | * @param cc the WHIRLPOOL context 107 | * @param data the input data 108 | * @param len the input data length (in bytes) 109 | */ 110 | void sph_whirlpool(void *cc, const void *data, size_t len); 111 | 112 | /** 113 | * Terminate the current WHIRLPOOL computation and output the result into the 114 | * provided buffer. The destination buffer must be wide enough to 115 | * accomodate the result (64 bytes). The context is automatically 116 | * reinitialized. 117 | * 118 | * @param cc the WHIRLPOOL context 119 | * @param dst the destination buffer 120 | */ 121 | void sph_whirlpool_close(void *cc, void *dst); 122 | 123 | /** 124 | * WHIRLPOOL-0 uses the same structure than plain WHIRLPOOL. 125 | */ 126 | typedef sph_whirlpool_context sph_whirlpool0_context; 127 | 128 | #ifdef DOXYGEN_IGNORE 129 | /** 130 | * Initialize a WHIRLPOOL-0 context. This function is identical to 131 | * sph_whirlpool_init(). 132 | * 133 | * @param cc the WHIRLPOOL context (pointer to a 134 | * sph_whirlpool0_context) 135 | */ 136 | void sph_whirlpool0_init(void *cc); 137 | #endif 138 | 139 | #ifndef DOXYGEN_IGNORE 140 | #define sph_whirlpool0_init sph_whirlpool_init 141 | #endif 142 | 143 | /** 144 | * Process some data bytes. It is acceptable that len is zero 145 | * (in which case this function does nothing). This function applies the 146 | * WHIRLPOOL-0 algorithm. 147 | * 148 | * @param cc the WHIRLPOOL context 149 | * @param data the input data 150 | * @param len the input data length (in bytes) 151 | */ 152 | void sph_whirlpool0(void *cc, const void *data, size_t len); 153 | 154 | /** 155 | * Terminate the current WHIRLPOOL-0 computation and output the result into the 156 | * provided buffer. The destination buffer must be wide enough to 157 | * accomodate the result (64 bytes). The context is automatically 158 | * reinitialized. 159 | * 160 | * @param cc the WHIRLPOOL-0 context 161 | * @param dst the destination buffer 162 | */ 163 | void sph_whirlpool0_close(void *cc, void *dst); 164 | 165 | /** 166 | * WHIRLPOOL-1 uses the same structure than plain WHIRLPOOL. 167 | */ 168 | typedef sph_whirlpool_context sph_whirlpool1_context; 169 | 170 | #ifdef DOXYGEN_IGNORE 171 | /** 172 | * Initialize a WHIRLPOOL-1 context. This function is identical to 173 | * sph_whirlpool_init(). 174 | * 175 | * @param cc the WHIRLPOOL context (pointer to a 176 | * sph_whirlpool1_context) 177 | */ 178 | void sph_whirlpool1_init(void *cc); 179 | #endif 180 | 181 | #ifndef DOXYGEN_IGNORE 182 | #define sph_whirlpool1_init sph_whirlpool_init 183 | #endif 184 | 185 | /** 186 | * Process some data bytes. It is acceptable that len is zero 187 | * (in which case this function does nothing). This function applies the 188 | * WHIRLPOOL-1 algorithm. 189 | * 190 | * @param cc the WHIRLPOOL context 191 | * @param data the input data 192 | * @param len the input data length (in bytes) 193 | */ 194 | void sph_whirlpool1(void *cc, const void *data, size_t len); 195 | 196 | /** 197 | * Terminate the current WHIRLPOOL-1 computation and output the result into the 198 | * provided buffer. The destination buffer must be wide enough to 199 | * accomodate the result (64 bytes). The context is automatically 200 | * reinitialized. 201 | * 202 | * @param cc the WHIRLPOOL-1 context 203 | * @param dst the destination buffer 204 | */ 205 | void sph_whirlpool1_close(void *cc, void *dst); 206 | 207 | #endif 208 | 209 | #endif -------------------------------------------------------------------------------- /mixhash/sha3/sph_sha2big.c: -------------------------------------------------------------------------------- 1 | /* $Id: sha2big.c 216 2010-06-08 09:46:57Z tp $ */ 2 | /* 3 | * SHA-384 / SHA-512 implementation. 4 | * 5 | * ==========================(LICENSE BEGIN)============================ 6 | * 7 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ===========================(LICENSE END)============================= 29 | * 30 | * @author Thomas Pornin 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | #include "sph_sha2.h" 37 | 38 | #if SPH_64 39 | 40 | #define CH(X, Y, Z) ((((Y) ^ (Z)) & (X)) ^ (Z)) 41 | #define MAJ(X, Y, Z) (((X) & (Y)) | (((X) | (Y)) & (Z))) 42 | 43 | #define ROTR64 SPH_ROTR64 44 | 45 | #define BSG5_0(x) (ROTR64(x, 28) ^ ROTR64(x, 34) ^ ROTR64(x, 39)) 46 | #define BSG5_1(x) (ROTR64(x, 14) ^ ROTR64(x, 18) ^ ROTR64(x, 41)) 47 | #define SSG5_0(x) (ROTR64(x, 1) ^ ROTR64(x, 8) ^ SPH_T64((x) >> 7)) 48 | #define SSG5_1(x) (ROTR64(x, 19) ^ ROTR64(x, 61) ^ SPH_T64((x) >> 6)) 49 | 50 | static const sph_u64 K512[80] = { 51 | SPH_C64(0x428A2F98D728AE22), SPH_C64(0x7137449123EF65CD), 52 | SPH_C64(0xB5C0FBCFEC4D3B2F), SPH_C64(0xE9B5DBA58189DBBC), 53 | SPH_C64(0x3956C25BF348B538), SPH_C64(0x59F111F1B605D019), 54 | SPH_C64(0x923F82A4AF194F9B), SPH_C64(0xAB1C5ED5DA6D8118), 55 | SPH_C64(0xD807AA98A3030242), SPH_C64(0x12835B0145706FBE), 56 | SPH_C64(0x243185BE4EE4B28C), SPH_C64(0x550C7DC3D5FFB4E2), 57 | SPH_C64(0x72BE5D74F27B896F), SPH_C64(0x80DEB1FE3B1696B1), 58 | SPH_C64(0x9BDC06A725C71235), SPH_C64(0xC19BF174CF692694), 59 | SPH_C64(0xE49B69C19EF14AD2), SPH_C64(0xEFBE4786384F25E3), 60 | SPH_C64(0x0FC19DC68B8CD5B5), SPH_C64(0x240CA1CC77AC9C65), 61 | SPH_C64(0x2DE92C6F592B0275), SPH_C64(0x4A7484AA6EA6E483), 62 | SPH_C64(0x5CB0A9DCBD41FBD4), SPH_C64(0x76F988DA831153B5), 63 | SPH_C64(0x983E5152EE66DFAB), SPH_C64(0xA831C66D2DB43210), 64 | SPH_C64(0xB00327C898FB213F), SPH_C64(0xBF597FC7BEEF0EE4), 65 | SPH_C64(0xC6E00BF33DA88FC2), SPH_C64(0xD5A79147930AA725), 66 | SPH_C64(0x06CA6351E003826F), SPH_C64(0x142929670A0E6E70), 67 | SPH_C64(0x27B70A8546D22FFC), SPH_C64(0x2E1B21385C26C926), 68 | SPH_C64(0x4D2C6DFC5AC42AED), SPH_C64(0x53380D139D95B3DF), 69 | SPH_C64(0x650A73548BAF63DE), SPH_C64(0x766A0ABB3C77B2A8), 70 | SPH_C64(0x81C2C92E47EDAEE6), SPH_C64(0x92722C851482353B), 71 | SPH_C64(0xA2BFE8A14CF10364), SPH_C64(0xA81A664BBC423001), 72 | SPH_C64(0xC24B8B70D0F89791), SPH_C64(0xC76C51A30654BE30), 73 | SPH_C64(0xD192E819D6EF5218), SPH_C64(0xD69906245565A910), 74 | SPH_C64(0xF40E35855771202A), SPH_C64(0x106AA07032BBD1B8), 75 | SPH_C64(0x19A4C116B8D2D0C8), SPH_C64(0x1E376C085141AB53), 76 | SPH_C64(0x2748774CDF8EEB99), SPH_C64(0x34B0BCB5E19B48A8), 77 | SPH_C64(0x391C0CB3C5C95A63), SPH_C64(0x4ED8AA4AE3418ACB), 78 | SPH_C64(0x5B9CCA4F7763E373), SPH_C64(0x682E6FF3D6B2B8A3), 79 | SPH_C64(0x748F82EE5DEFB2FC), SPH_C64(0x78A5636F43172F60), 80 | SPH_C64(0x84C87814A1F0AB72), SPH_C64(0x8CC702081A6439EC), 81 | SPH_C64(0x90BEFFFA23631E28), SPH_C64(0xA4506CEBDE82BDE9), 82 | SPH_C64(0xBEF9A3F7B2C67915), SPH_C64(0xC67178F2E372532B), 83 | SPH_C64(0xCA273ECEEA26619C), SPH_C64(0xD186B8C721C0C207), 84 | SPH_C64(0xEADA7DD6CDE0EB1E), SPH_C64(0xF57D4F7FEE6ED178), 85 | SPH_C64(0x06F067AA72176FBA), SPH_C64(0x0A637DC5A2C898A6), 86 | SPH_C64(0x113F9804BEF90DAE), SPH_C64(0x1B710B35131C471B), 87 | SPH_C64(0x28DB77F523047D84), SPH_C64(0x32CAAB7B40C72493), 88 | SPH_C64(0x3C9EBE0A15C9BEBC), SPH_C64(0x431D67C49C100D4C), 89 | SPH_C64(0x4CC5D4BECB3E42B6), SPH_C64(0x597F299CFC657E2A), 90 | SPH_C64(0x5FCB6FAB3AD6FAEC), SPH_C64(0x6C44198C4A475817) 91 | }; 92 | 93 | static const sph_u64 H384[8] = { 94 | SPH_C64(0xCBBB9D5DC1059ED8), SPH_C64(0x629A292A367CD507), 95 | SPH_C64(0x9159015A3070DD17), SPH_C64(0x152FECD8F70E5939), 96 | SPH_C64(0x67332667FFC00B31), SPH_C64(0x8EB44A8768581511), 97 | SPH_C64(0xDB0C2E0D64F98FA7), SPH_C64(0x47B5481DBEFA4FA4) 98 | }; 99 | 100 | static const sph_u64 H512[8] = { 101 | SPH_C64(0x6A09E667F3BCC908), SPH_C64(0xBB67AE8584CAA73B), 102 | SPH_C64(0x3C6EF372FE94F82B), SPH_C64(0xA54FF53A5F1D36F1), 103 | SPH_C64(0x510E527FADE682D1), SPH_C64(0x9B05688C2B3E6C1F), 104 | SPH_C64(0x1F83D9ABFB41BD6B), SPH_C64(0x5BE0CD19137E2179) 105 | }; 106 | 107 | /* 108 | * This macro defines the body for a SHA-384 / SHA-512 compression function 109 | * implementation. The "in" parameter should evaluate, when applied to a 110 | * numerical input parameter from 0 to 15, to an expression which yields 111 | * the corresponding input block. The "r" parameter should evaluate to 112 | * an array or pointer expression designating the array of 8 words which 113 | * contains the input and output of the compression function. 114 | * 115 | * SHA-512 is hard for the compiler. If the loop is completely unrolled, 116 | * then the code will be quite huge (possibly more than 100 kB), and the 117 | * performance will be degraded due to cache misses on the code. We 118 | * unroll only eight steps, which avoids all needless copies when 119 | * 64-bit registers are swapped. 120 | */ 121 | 122 | #define SHA3_STEP(A, B, C, D, E, F, G, H, i) do { \ 123 | sph_u64 T1, T2; \ 124 | T1 = SPH_T64(H + BSG5_1(E) + CH(E, F, G) + K512[i] + W[i]); \ 125 | T2 = SPH_T64(BSG5_0(A) + MAJ(A, B, C)); \ 126 | D = SPH_T64(D + T1); \ 127 | H = SPH_T64(T1 + T2); \ 128 | } while (0) 129 | 130 | #define SHA3_ROUND_BODY(in, r) do { \ 131 | int i; \ 132 | sph_u64 A, B, C, D, E, F, G, H; \ 133 | sph_u64 W[80]; \ 134 | \ 135 | for (i = 0; i < 16; i ++) \ 136 | W[i] = in(i); \ 137 | for (i = 16; i < 80; i ++) \ 138 | W[i] = SPH_T64(SSG5_1(W[i - 2]) + W[i - 7] \ 139 | + SSG5_0(W[i - 15]) + W[i - 16]); \ 140 | A = (r)[0]; \ 141 | B = (r)[1]; \ 142 | C = (r)[2]; \ 143 | D = (r)[3]; \ 144 | E = (r)[4]; \ 145 | F = (r)[5]; \ 146 | G = (r)[6]; \ 147 | H = (r)[7]; \ 148 | for (i = 0; i < 80; i += 8) { \ 149 | SHA3_STEP(A, B, C, D, E, F, G, H, i + 0); \ 150 | SHA3_STEP(H, A, B, C, D, E, F, G, i + 1); \ 151 | SHA3_STEP(G, H, A, B, C, D, E, F, i + 2); \ 152 | SHA3_STEP(F, G, H, A, B, C, D, E, i + 3); \ 153 | SHA3_STEP(E, F, G, H, A, B, C, D, i + 4); \ 154 | SHA3_STEP(D, E, F, G, H, A, B, C, i + 5); \ 155 | SHA3_STEP(C, D, E, F, G, H, A, B, i + 6); \ 156 | SHA3_STEP(B, C, D, E, F, G, H, A, i + 7); \ 157 | } \ 158 | (r)[0] = SPH_T64((r)[0] + A); \ 159 | (r)[1] = SPH_T64((r)[1] + B); \ 160 | (r)[2] = SPH_T64((r)[2] + C); \ 161 | (r)[3] = SPH_T64((r)[3] + D); \ 162 | (r)[4] = SPH_T64((r)[4] + E); \ 163 | (r)[5] = SPH_T64((r)[5] + F); \ 164 | (r)[6] = SPH_T64((r)[6] + G); \ 165 | (r)[7] = SPH_T64((r)[7] + H); \ 166 | } while (0) 167 | 168 | /* 169 | * One round of SHA-384 / SHA-512. The data must be aligned for 64-bit access. 170 | */ 171 | static void 172 | sha3_round(const unsigned char *data, sph_u64 r[8]) 173 | { 174 | #define SHA3_IN(x) sph_dec64be_aligned(data + (8 * (x))) 175 | SHA3_ROUND_BODY(SHA3_IN, r); 176 | #undef SHA3_IN 177 | } 178 | 179 | /* see sph_sha3.h */ 180 | void 181 | sph_sha384_init(void *cc) 182 | { 183 | sph_sha384_context *sc; 184 | 185 | sc = (sph_sha384_context*)cc; 186 | memcpy(sc->val, H384, sizeof H384); 187 | sc->count = 0; 188 | } 189 | 190 | /* see sph_sha3.h */ 191 | void 192 | sph_sha512_init(void *cc) 193 | { 194 | sph_sha512_context *sc; 195 | 196 | sc = (sph_sha512_context*)cc; 197 | memcpy(sc->val, H512, sizeof H512); 198 | sc->count = 0; 199 | } 200 | 201 | #define RFUN sha3_round 202 | #define HASH sha384 203 | #define BE64 1 204 | #include "md_helper.c" 205 | 206 | /* see sph_sha3.h */ 207 | void 208 | sph_sha384_close(void *cc, void *dst) 209 | { 210 | sha384_close(cc, dst, 6); 211 | sph_sha384_init(cc); 212 | } 213 | 214 | /* see sph_sha3.h */ 215 | void 216 | sph_sha384_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 217 | { 218 | sha384_addbits_and_close(cc, ub, n, dst, 6); 219 | sph_sha384_init(cc); 220 | } 221 | 222 | /* see sph_sha3.h */ 223 | void 224 | sph_sha512_close(void *cc, void *dst) 225 | { 226 | sha384_close(cc, dst, 8); 227 | sph_sha512_init(cc); 228 | } 229 | 230 | /* see sph_sha3.h */ 231 | void 232 | sph_sha512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 233 | { 234 | sha384_addbits_and_close(cc, ub, n, dst, 8); 235 | sph_sha512_init(cc); 236 | } 237 | 238 | /* see sph_sha3.h */ 239 | void 240 | sph_sha384_comp(const sph_u64 msg[16], sph_u64 val[8]) 241 | { 242 | #define SHA3_IN(x) msg[x] 243 | SHA3_ROUND_BODY(SHA3_IN, val); 244 | #undef SHA3_IN 245 | } 246 | 247 | #endif 248 | 249 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_ripemd.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_ripemd.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * RIPEMD, RIPEMD-128 and RIPEMD-160 interface. 4 | * 5 | * RIPEMD was first described in: Research and Development in Advanced 6 | * Communication Technologies in Europe, "RIPE Integrity Primitives: 7 | * Final Report of RACE Integrity Primitives Evaluation (R1040)", RACE, 8 | * June 1992. 9 | * 10 | * A new, strengthened version, dubbed RIPEMD-160, was published in: H. 11 | * Dobbertin, A. Bosselaers, and B. Preneel, "RIPEMD-160, a strengthened 12 | * version of RIPEMD", Fast Software Encryption - FSE'96, LNCS 1039, 13 | * Springer (1996), pp. 71--82. 14 | * 15 | * This article describes both RIPEMD-160, with a 160-bit output, and a 16 | * reduced version called RIPEMD-128, which has a 128-bit output. RIPEMD-128 17 | * was meant as a "drop-in" replacement for any hash function with 128-bit 18 | * output, especially the original RIPEMD. 19 | * 20 | * @warning Collisions, and an efficient method to build other collisions, 21 | * have been published for the original RIPEMD, which is thus considered as 22 | * cryptographically broken. It is also very rarely encountered, and there 23 | * seems to exist no free description or implementation of RIPEMD (except 24 | * the sphlib code, of course). As of january 2007, RIPEMD-128 and RIPEMD-160 25 | * seem as secure as their output length allows. 26 | * 27 | * ==========================(LICENSE BEGIN)============================ 28 | * 29 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 30 | * 31 | * Permission is hereby granted, free of charge, to any person obtaining 32 | * a copy of this software and associated documentation files (the 33 | * "Software"), to deal in the Software without restriction, including 34 | * without limitation the rights to use, copy, modify, merge, publish, 35 | * distribute, sublicense, and/or sell copies of the Software, and to 36 | * permit persons to whom the Software is furnished to do so, subject to 37 | * the following conditions: 38 | * 39 | * The above copyright notice and this permission notice shall be 40 | * included in all copies or substantial portions of the Software. 41 | * 42 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 43 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 44 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 45 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 46 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 47 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 48 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 49 | * 50 | * ===========================(LICENSE END)============================= 51 | * 52 | * @file sph_ripemd.h 53 | * @author Thomas Pornin 54 | */ 55 | 56 | #ifndef SPH_RIPEMD_H__ 57 | #define SPH_RIPEMD_H__ 58 | 59 | #include 60 | #include "sph_types.h" 61 | 62 | /** 63 | * Output size (in bits) for RIPEMD. 64 | */ 65 | #define SPH_SIZE_ripemd 128 66 | 67 | /** 68 | * Output size (in bits) for RIPEMD-128. 69 | */ 70 | #define SPH_SIZE_ripemd128 128 71 | 72 | /** 73 | * Output size (in bits) for RIPEMD-160. 74 | */ 75 | #define SPH_SIZE_ripemd160 160 76 | 77 | /** 78 | * This structure is a context for RIPEMD computations: it contains the 79 | * intermediate values and some data from the last entered block. Once 80 | * a RIPEMD computation has been performed, the context can be reused for 81 | * another computation. 82 | * 83 | * The contents of this structure are private. A running RIPEMD computation 84 | * can be cloned by copying the context (e.g. with a simple 85 | * memcpy()). 86 | */ 87 | typedef struct { 88 | #ifndef DOXYGEN_IGNORE 89 | unsigned char buf[64]; /* first field, for alignment */ 90 | sph_u32 val[4]; 91 | #if SPH_64 92 | sph_u64 count; 93 | #else 94 | sph_u32 count_high, count_low; 95 | #endif 96 | #endif 97 | } sph_ripemd_context; 98 | 99 | /** 100 | * Initialize a RIPEMD context. This process performs no memory allocation. 101 | * 102 | * @param cc the RIPEMD context (pointer to 103 | * a sph_ripemd_context) 104 | */ 105 | void sph_ripemd_init(void *cc); 106 | 107 | /** 108 | * Process some data bytes. It is acceptable that len is zero 109 | * (in which case this function does nothing). 110 | * 111 | * @param cc the RIPEMD context 112 | * @param data the input data 113 | * @param len the input data length (in bytes) 114 | */ 115 | void sph_ripemd(void *cc, const void *data, size_t len); 116 | 117 | /** 118 | * Terminate the current RIPEMD computation and output the result into the 119 | * provided buffer. The destination buffer must be wide enough to 120 | * accomodate the result (16 bytes). The context is automatically 121 | * reinitialized. 122 | * 123 | * @param cc the RIPEMD context 124 | * @param dst the destination buffer 125 | */ 126 | void sph_ripemd_close(void *cc, void *dst); 127 | 128 | /** 129 | * Apply the RIPEMD compression function on the provided data. The 130 | * msg parameter contains the 16 32-bit input blocks, 131 | * as numerical values (hence after the little-endian decoding). The 132 | * val parameter contains the 5 32-bit input blocks for 133 | * the compression function; the output is written in place in this 134 | * array. 135 | * 136 | * @param msg the message block (16 values) 137 | * @param val the function 128-bit input and output 138 | */ 139 | void sph_ripemd_comp(const sph_u32 msg[16], sph_u32 val[4]); 140 | 141 | /* ===================================================================== */ 142 | 143 | /** 144 | * This structure is a context for RIPEMD-128 computations: it contains the 145 | * intermediate values and some data from the last entered block. Once 146 | * a RIPEMD-128 computation has been performed, the context can be reused for 147 | * another computation. 148 | * 149 | * The contents of this structure are private. A running RIPEMD-128 computation 150 | * can be cloned by copying the context (e.g. with a simple 151 | * memcpy()). 152 | */ 153 | typedef struct { 154 | #ifndef DOXYGEN_IGNORE 155 | unsigned char buf[64]; /* first field, for alignment */ 156 | sph_u32 val[4]; 157 | #if SPH_64 158 | sph_u64 count; 159 | #else 160 | sph_u32 count_high, count_low; 161 | #endif 162 | #endif 163 | } sph_ripemd128_context; 164 | 165 | /** 166 | * Initialize a RIPEMD-128 context. This process performs no memory allocation. 167 | * 168 | * @param cc the RIPEMD-128 context (pointer to 169 | * a sph_ripemd128_context) 170 | */ 171 | void sph_ripemd128_init(void *cc); 172 | 173 | /** 174 | * Process some data bytes. It is acceptable that len is zero 175 | * (in which case this function does nothing). 176 | * 177 | * @param cc the RIPEMD-128 context 178 | * @param data the input data 179 | * @param len the input data length (in bytes) 180 | */ 181 | void sph_ripemd128(void *cc, const void *data, size_t len); 182 | 183 | /** 184 | * Terminate the current RIPEMD-128 computation and output the result into the 185 | * provided buffer. The destination buffer must be wide enough to 186 | * accomodate the result (16 bytes). The context is automatically 187 | * reinitialized. 188 | * 189 | * @param cc the RIPEMD-128 context 190 | * @param dst the destination buffer 191 | */ 192 | void sph_ripemd128_close(void *cc, void *dst); 193 | 194 | /** 195 | * Apply the RIPEMD-128 compression function on the provided data. The 196 | * msg parameter contains the 16 32-bit input blocks, 197 | * as numerical values (hence after the little-endian decoding). The 198 | * val parameter contains the 5 32-bit input blocks for 199 | * the compression function; the output is written in place in this 200 | * array. 201 | * 202 | * @param msg the message block (16 values) 203 | * @param val the function 128-bit input and output 204 | */ 205 | void sph_ripemd128_comp(const sph_u32 msg[16], sph_u32 val[4]); 206 | 207 | /* ===================================================================== */ 208 | 209 | /** 210 | * This structure is a context for RIPEMD-160 computations: it contains the 211 | * intermediate values and some data from the last entered block. Once 212 | * a RIPEMD-160 computation has been performed, the context can be reused for 213 | * another computation. 214 | * 215 | * The contents of this structure are private. A running RIPEMD-160 computation 216 | * can be cloned by copying the context (e.g. with a simple 217 | * memcpy()). 218 | */ 219 | typedef struct { 220 | #ifndef DOXYGEN_IGNORE 221 | unsigned char buf[64]; /* first field, for alignment */ 222 | sph_u32 val[5]; 223 | #if SPH_64 224 | sph_u64 count; 225 | #else 226 | sph_u32 count_high, count_low; 227 | #endif 228 | #endif 229 | } sph_ripemd160_context; 230 | 231 | /** 232 | * Initialize a RIPEMD-160 context. This process performs no memory allocation. 233 | * 234 | * @param cc the RIPEMD-160 context (pointer to 235 | * a sph_ripemd160_context) 236 | */ 237 | void sph_ripemd160_init(void *cc); 238 | 239 | /** 240 | * Process some data bytes. It is acceptable that len is zero 241 | * (in which case this function does nothing). 242 | * 243 | * @param cc the RIPEMD-160 context 244 | * @param data the input data 245 | * @param len the input data length (in bytes) 246 | */ 247 | void sph_ripemd160(void *cc, const void *data, size_t len); 248 | 249 | /** 250 | * Terminate the current RIPEMD-160 computation and output the result into the 251 | * provided buffer. The destination buffer must be wide enough to 252 | * accomodate the result (20 bytes). The context is automatically 253 | * reinitialized. 254 | * 255 | * @param cc the RIPEMD-160 context 256 | * @param dst the destination buffer 257 | */ 258 | void sph_ripemd160_close(void *cc, void *dst); 259 | 260 | /** 261 | * Apply the RIPEMD-160 compression function on the provided data. The 262 | * msg parameter contains the 16 32-bit input blocks, 263 | * as numerical values (hence after the little-endian decoding). The 264 | * val parameter contains the 5 32-bit input blocks for 265 | * the compression function; the output is written in place in this 266 | * array. 267 | * 268 | * @param msg the message block (16 values) 269 | * @param val the function 160-bit input and output 270 | */ 271 | void sph_ripemd160_comp(const sph_u32 msg[16], sph_u32 val[5]); 272 | 273 | #endif 274 | 275 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_jh.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_jh.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * JH interface. JH is a family of functions which differ by 4 | * their output size; this implementation defines JH for output 5 | * sizes 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_jh.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_JH_H__ 37 | #define SPH_JH_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for JH-224. 48 | */ 49 | #define SPH_SIZE_jh224 224 50 | 51 | /** 52 | * Output size (in bits) for JH-256. 53 | */ 54 | #define SPH_SIZE_jh256 256 55 | 56 | /** 57 | * Output size (in bits) for JH-384. 58 | */ 59 | #define SPH_SIZE_jh384 384 60 | 61 | /** 62 | * Output size (in bits) for JH-512. 63 | */ 64 | #define SPH_SIZE_jh512 512 65 | 66 | /** 67 | * This structure is a context for JH computations: it contains the 68 | * intermediate values and some data from the last entered block. Once 69 | * a JH computation has been performed, the context can be reused for 70 | * another computation. 71 | * 72 | * The contents of this structure are private. A running JH computation 73 | * can be cloned by copying the context (e.g. with a simple 74 | * memcpy()). 75 | */ 76 | typedef struct { 77 | #ifndef DOXYGEN_IGNORE 78 | unsigned char buf[64]; /* first field, for alignment */ 79 | size_t ptr; 80 | union { 81 | #if SPH_64 82 | sph_u64 wide[16]; 83 | #endif 84 | sph_u32 narrow[32]; 85 | } H; 86 | #if SPH_64 87 | sph_u64 block_count; 88 | #else 89 | sph_u32 block_count_high, block_count_low; 90 | #endif 91 | #endif 92 | } sph_jh_context; 93 | 94 | /** 95 | * Type for a JH-224 context (identical to the common context). 96 | */ 97 | typedef sph_jh_context sph_jh224_context; 98 | 99 | /** 100 | * Type for a JH-256 context (identical to the common context). 101 | */ 102 | typedef sph_jh_context sph_jh256_context; 103 | 104 | /** 105 | * Type for a JH-384 context (identical to the common context). 106 | */ 107 | typedef sph_jh_context sph_jh384_context; 108 | 109 | /** 110 | * Type for a JH-512 context (identical to the common context). 111 | */ 112 | typedef sph_jh_context sph_jh512_context; 113 | 114 | /** 115 | * Initialize a JH-224 context. This process performs no memory allocation. 116 | * 117 | * @param cc the JH-224 context (pointer to a 118 | * sph_jh224_context) 119 | */ 120 | void sph_jh224_init(void *cc); 121 | 122 | /** 123 | * Process some data bytes. It is acceptable that len is zero 124 | * (in which case this function does nothing). 125 | * 126 | * @param cc the JH-224 context 127 | * @param data the input data 128 | * @param len the input data length (in bytes) 129 | */ 130 | void sph_jh224(void *cc, const void *data, size_t len); 131 | 132 | /** 133 | * Terminate the current JH-224 computation and output the result into 134 | * the provided buffer. The destination buffer must be wide enough to 135 | * accomodate the result (28 bytes). The context is automatically 136 | * reinitialized. 137 | * 138 | * @param cc the JH-224 context 139 | * @param dst the destination buffer 140 | */ 141 | void sph_jh224_close(void *cc, void *dst); 142 | 143 | /** 144 | * Add a few additional bits (0 to 7) to the current computation, then 145 | * terminate it and output the result in the provided buffer, which must 146 | * be wide enough to accomodate the result (28 bytes). If bit number i 147 | * in ub has value 2^i, then the extra bits are those 148 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 149 | * level). The context is automatically reinitialized. 150 | * 151 | * @param cc the JH-224 context 152 | * @param ub the extra bits 153 | * @param n the number of extra bits (0 to 7) 154 | * @param dst the destination buffer 155 | */ 156 | void sph_jh224_addbits_and_close( 157 | void *cc, unsigned ub, unsigned n, void *dst); 158 | 159 | /** 160 | * Initialize a JH-256 context. This process performs no memory allocation. 161 | * 162 | * @param cc the JH-256 context (pointer to a 163 | * sph_jh256_context) 164 | */ 165 | void sph_jh256_init(void *cc); 166 | 167 | /** 168 | * Process some data bytes. It is acceptable that len is zero 169 | * (in which case this function does nothing). 170 | * 171 | * @param cc the JH-256 context 172 | * @param data the input data 173 | * @param len the input data length (in bytes) 174 | */ 175 | void sph_jh256(void *cc, const void *data, size_t len); 176 | 177 | /** 178 | * Terminate the current JH-256 computation and output the result into 179 | * the provided buffer. The destination buffer must be wide enough to 180 | * accomodate the result (32 bytes). The context is automatically 181 | * reinitialized. 182 | * 183 | * @param cc the JH-256 context 184 | * @param dst the destination buffer 185 | */ 186 | void sph_jh256_close(void *cc, void *dst); 187 | 188 | /** 189 | * Add a few additional bits (0 to 7) to the current computation, then 190 | * terminate it and output the result in the provided buffer, which must 191 | * be wide enough to accomodate the result (32 bytes). If bit number i 192 | * in ub has value 2^i, then the extra bits are those 193 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 194 | * level). The context is automatically reinitialized. 195 | * 196 | * @param cc the JH-256 context 197 | * @param ub the extra bits 198 | * @param n the number of extra bits (0 to 7) 199 | * @param dst the destination buffer 200 | */ 201 | void sph_jh256_addbits_and_close( 202 | void *cc, unsigned ub, unsigned n, void *dst); 203 | 204 | /** 205 | * Initialize a JH-384 context. This process performs no memory allocation. 206 | * 207 | * @param cc the JH-384 context (pointer to a 208 | * sph_jh384_context) 209 | */ 210 | void sph_jh384_init(void *cc); 211 | 212 | /** 213 | * Process some data bytes. It is acceptable that len is zero 214 | * (in which case this function does nothing). 215 | * 216 | * @param cc the JH-384 context 217 | * @param data the input data 218 | * @param len the input data length (in bytes) 219 | */ 220 | void sph_jh384(void *cc, const void *data, size_t len); 221 | 222 | /** 223 | * Terminate the current JH-384 computation and output the result into 224 | * the provided buffer. The destination buffer must be wide enough to 225 | * accomodate the result (48 bytes). The context is automatically 226 | * reinitialized. 227 | * 228 | * @param cc the JH-384 context 229 | * @param dst the destination buffer 230 | */ 231 | void sph_jh384_close(void *cc, void *dst); 232 | 233 | /** 234 | * Add a few additional bits (0 to 7) to the current computation, then 235 | * terminate it and output the result in the provided buffer, which must 236 | * be wide enough to accomodate the result (48 bytes). If bit number i 237 | * in ub has value 2^i, then the extra bits are those 238 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 239 | * level). The context is automatically reinitialized. 240 | * 241 | * @param cc the JH-384 context 242 | * @param ub the extra bits 243 | * @param n the number of extra bits (0 to 7) 244 | * @param dst the destination buffer 245 | */ 246 | void sph_jh384_addbits_and_close( 247 | void *cc, unsigned ub, unsigned n, void *dst); 248 | 249 | /** 250 | * Initialize a JH-512 context. This process performs no memory allocation. 251 | * 252 | * @param cc the JH-512 context (pointer to a 253 | * sph_jh512_context) 254 | */ 255 | void sph_jh512_init(void *cc); 256 | 257 | /** 258 | * Process some data bytes. It is acceptable that len is zero 259 | * (in which case this function does nothing). 260 | * 261 | * @param cc the JH-512 context 262 | * @param data the input data 263 | * @param len the input data length (in bytes) 264 | */ 265 | void sph_jh512(void *cc, const void *data, size_t len); 266 | 267 | /** 268 | * Terminate the current JH-512 computation and output the result into 269 | * the provided buffer. The destination buffer must be wide enough to 270 | * accomodate the result (64 bytes). The context is automatically 271 | * reinitialized. 272 | * 273 | * @param cc the JH-512 context 274 | * @param dst the destination buffer 275 | */ 276 | void sph_jh512_close(void *cc, void *dst); 277 | 278 | /** 279 | * Add a few additional bits (0 to 7) to the current computation, then 280 | * terminate it and output the result in the provided buffer, which must 281 | * be wide enough to accomodate the result (64 bytes). If bit number i 282 | * in ub has value 2^i, then the extra bits are those 283 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 284 | * level). The context is automatically reinitialized. 285 | * 286 | * @param cc the JH-512 context 287 | * @param ub the extra bits 288 | * @param n the number of extra bits (0 to 7) 289 | * @param dst the destination buffer 290 | */ 291 | void sph_jh512_addbits_and_close( 292 | void *cc, unsigned ub, unsigned n, void *dst); 293 | 294 | #ifdef __cplusplus 295 | } 296 | #endif 297 | 298 | #endif 299 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_keccak.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_keccak.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * Keccak interface. This is the interface for Keccak with the 4 | * recommended parameters for SHA-3, with output lengths 224, 256, 5 | * 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_keccak.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_KECCAK_H__ 37 | #define SPH_KECCAK_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for Keccak-224. 48 | */ 49 | #define SPH_SIZE_keccak224 224 50 | 51 | /** 52 | * Output size (in bits) for Keccak-256. 53 | */ 54 | #define SPH_SIZE_keccak256 256 55 | 56 | /** 57 | * Output size (in bits) for Keccak-384. 58 | */ 59 | #define SPH_SIZE_keccak384 384 60 | 61 | /** 62 | * Output size (in bits) for Keccak-512. 63 | */ 64 | #define SPH_SIZE_keccak512 512 65 | 66 | /** 67 | * This structure is a context for Keccak computations: it contains the 68 | * intermediate values and some data from the last entered block. Once a 69 | * Keccak computation has been performed, the context can be reused for 70 | * another computation. 71 | * 72 | * The contents of this structure are private. A running Keccak computation 73 | * can be cloned by copying the context (e.g. with a simple 74 | * memcpy()). 75 | */ 76 | typedef struct { 77 | #ifndef DOXYGEN_IGNORE 78 | unsigned char buf[144]; /* first field, for alignment */ 79 | size_t ptr, lim; 80 | union { 81 | #if SPH_64 82 | sph_u64 wide[25]; 83 | #endif 84 | sph_u32 narrow[50]; 85 | } u; 86 | #endif 87 | } sph_keccak_context; 88 | 89 | /** 90 | * Type for a Keccak-224 context (identical to the common context). 91 | */ 92 | typedef sph_keccak_context sph_keccak224_context; 93 | 94 | /** 95 | * Type for a Keccak-256 context (identical to the common context). 96 | */ 97 | typedef sph_keccak_context sph_keccak256_context; 98 | 99 | /** 100 | * Type for a Keccak-384 context (identical to the common context). 101 | */ 102 | typedef sph_keccak_context sph_keccak384_context; 103 | 104 | /** 105 | * Type for a Keccak-512 context (identical to the common context). 106 | */ 107 | typedef sph_keccak_context sph_keccak512_context; 108 | 109 | /** 110 | * Initialize a Keccak-224 context. This process performs no memory allocation. 111 | * 112 | * @param cc the Keccak-224 context (pointer to a 113 | * sph_keccak224_context) 114 | */ 115 | void sph_keccak224_init(void *cc); 116 | 117 | /** 118 | * Process some data bytes. It is acceptable that len is zero 119 | * (in which case this function does nothing). 120 | * 121 | * @param cc the Keccak-224 context 122 | * @param data the input data 123 | * @param len the input data length (in bytes) 124 | */ 125 | void sph_keccak224(void *cc, const void *data, size_t len); 126 | 127 | /** 128 | * Terminate the current Keccak-224 computation and output the result into 129 | * the provided buffer. The destination buffer must be wide enough to 130 | * accomodate the result (28 bytes). The context is automatically 131 | * reinitialized. 132 | * 133 | * @param cc the Keccak-224 context 134 | * @param dst the destination buffer 135 | */ 136 | void sph_keccak224_close(void *cc, void *dst); 137 | 138 | /** 139 | * Add a few additional bits (0 to 7) to the current computation, then 140 | * terminate it and output the result in the provided buffer, which must 141 | * be wide enough to accomodate the result (28 bytes). If bit number i 142 | * in ub has value 2^i, then the extra bits are those 143 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 144 | * level). The context is automatically reinitialized. 145 | * 146 | * @param cc the Keccak-224 context 147 | * @param ub the extra bits 148 | * @param n the number of extra bits (0 to 7) 149 | * @param dst the destination buffer 150 | */ 151 | void sph_keccak224_addbits_and_close( 152 | void *cc, unsigned ub, unsigned n, void *dst); 153 | 154 | /** 155 | * Initialize a Keccak-256 context. This process performs no memory allocation. 156 | * 157 | * @param cc the Keccak-256 context (pointer to a 158 | * sph_keccak256_context) 159 | */ 160 | void sph_keccak256_init(void *cc); 161 | 162 | /** 163 | * Process some data bytes. It is acceptable that len is zero 164 | * (in which case this function does nothing). 165 | * 166 | * @param cc the Keccak-256 context 167 | * @param data the input data 168 | * @param len the input data length (in bytes) 169 | */ 170 | void sph_keccak256(void *cc, const void *data, size_t len); 171 | 172 | /** 173 | * Terminate the current Keccak-256 computation and output the result into 174 | * the provided buffer. The destination buffer must be wide enough to 175 | * accomodate the result (32 bytes). The context is automatically 176 | * reinitialized. 177 | * 178 | * @param cc the Keccak-256 context 179 | * @param dst the destination buffer 180 | */ 181 | void sph_keccak256_close(void *cc, void *dst); 182 | 183 | /** 184 | * Add a few additional bits (0 to 7) to the current computation, then 185 | * terminate it and output the result in the provided buffer, which must 186 | * be wide enough to accomodate the result (32 bytes). If bit number i 187 | * in ub has value 2^i, then the extra bits are those 188 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 189 | * level). The context is automatically reinitialized. 190 | * 191 | * @param cc the Keccak-256 context 192 | * @param ub the extra bits 193 | * @param n the number of extra bits (0 to 7) 194 | * @param dst the destination buffer 195 | */ 196 | void sph_keccak256_addbits_and_close( 197 | void *cc, unsigned ub, unsigned n, void *dst); 198 | 199 | /** 200 | * Initialize a Keccak-384 context. This process performs no memory allocation. 201 | * 202 | * @param cc the Keccak-384 context (pointer to a 203 | * sph_keccak384_context) 204 | */ 205 | void sph_keccak384_init(void *cc); 206 | 207 | /** 208 | * Process some data bytes. It is acceptable that len is zero 209 | * (in which case this function does nothing). 210 | * 211 | * @param cc the Keccak-384 context 212 | * @param data the input data 213 | * @param len the input data length (in bytes) 214 | */ 215 | void sph_keccak384(void *cc, const void *data, size_t len); 216 | 217 | /** 218 | * Terminate the current Keccak-384 computation and output the result into 219 | * the provided buffer. The destination buffer must be wide enough to 220 | * accomodate the result (48 bytes). The context is automatically 221 | * reinitialized. 222 | * 223 | * @param cc the Keccak-384 context 224 | * @param dst the destination buffer 225 | */ 226 | void sph_keccak384_close(void *cc, void *dst); 227 | 228 | /** 229 | * Add a few additional bits (0 to 7) to the current computation, then 230 | * terminate it and output the result in the provided buffer, which must 231 | * be wide enough to accomodate the result (48 bytes). If bit number i 232 | * in ub has value 2^i, then the extra bits are those 233 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 234 | * level). The context is automatically reinitialized. 235 | * 236 | * @param cc the Keccak-384 context 237 | * @param ub the extra bits 238 | * @param n the number of extra bits (0 to 7) 239 | * @param dst the destination buffer 240 | */ 241 | void sph_keccak384_addbits_and_close( 242 | void *cc, unsigned ub, unsigned n, void *dst); 243 | 244 | /** 245 | * Initialize a Keccak-512 context. This process performs no memory allocation. 246 | * 247 | * @param cc the Keccak-512 context (pointer to a 248 | * sph_keccak512_context) 249 | */ 250 | void sph_keccak512_init(void *cc); 251 | 252 | /** 253 | * Process some data bytes. It is acceptable that len is zero 254 | * (in which case this function does nothing). 255 | * 256 | * @param cc the Keccak-512 context 257 | * @param data the input data 258 | * @param len the input data length (in bytes) 259 | */ 260 | void sph_keccak512(void *cc, const void *data, size_t len); 261 | 262 | /** 263 | * Terminate the current Keccak-512 computation and output the result into 264 | * the provided buffer. The destination buffer must be wide enough to 265 | * accomodate the result (64 bytes). The context is automatically 266 | * reinitialized. 267 | * 268 | * @param cc the Keccak-512 context 269 | * @param dst the destination buffer 270 | */ 271 | void sph_keccak512_close(void *cc, void *dst); 272 | 273 | /** 274 | * Add a few additional bits (0 to 7) to the current computation, then 275 | * terminate it and output the result in the provided buffer, which must 276 | * be wide enough to accomodate the result (64 bytes). If bit number i 277 | * in ub has value 2^i, then the extra bits are those 278 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 279 | * level). The context is automatically reinitialized. 280 | * 281 | * @param cc the Keccak-512 context 282 | * @param ub the extra bits 283 | * @param n the number of extra bits (0 to 7) 284 | * @param dst the destination buffer 285 | */ 286 | void sph_keccak512_addbits_and_close( 287 | void *cc, unsigned ub, unsigned n, void *dst); 288 | 289 | #ifdef __cplusplus 290 | } 291 | #endif 292 | 293 | #endif 294 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_luffa.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_luffa.h 154 2010-04-26 17:00:24Z tp $ */ 2 | /** 3 | * Luffa interface. Luffa is a family of functions which differ by 4 | * their output size; this implementation defines Luffa for output 5 | * sizes 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_luffa.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_LUFFA_H__ 37 | #define SPH_LUFFA_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for Luffa-224. 48 | */ 49 | #define SPH_SIZE_luffa224 224 50 | 51 | /** 52 | * Output size (in bits) for Luffa-256. 53 | */ 54 | #define SPH_SIZE_luffa256 256 55 | 56 | /** 57 | * Output size (in bits) for Luffa-384. 58 | */ 59 | #define SPH_SIZE_luffa384 384 60 | 61 | /** 62 | * Output size (in bits) for Luffa-512. 63 | */ 64 | #define SPH_SIZE_luffa512 512 65 | 66 | /** 67 | * This structure is a context for Luffa-224 computations: it contains 68 | * the intermediate values and some data from the last entered block. 69 | * Once a Luffa computation has been performed, the context can be 70 | * reused for another computation. 71 | * 72 | * The contents of this structure are private. A running Luffa 73 | * computation can be cloned by copying the context (e.g. with a simple 74 | * memcpy()). 75 | */ 76 | typedef struct { 77 | #ifndef DOXYGEN_IGNORE 78 | unsigned char buf[32]; /* first field, for alignment */ 79 | size_t ptr; 80 | sph_u32 V[3][8]; 81 | #endif 82 | } sph_luffa224_context; 83 | 84 | /** 85 | * This structure is a context for Luffa-256 computations. It is 86 | * identical to sph_luffa224_context. 87 | */ 88 | typedef sph_luffa224_context sph_luffa256_context; 89 | 90 | /** 91 | * This structure is a context for Luffa-384 computations. 92 | */ 93 | typedef struct { 94 | #ifndef DOXYGEN_IGNORE 95 | unsigned char buf[32]; /* first field, for alignment */ 96 | size_t ptr; 97 | sph_u32 V[4][8]; 98 | #endif 99 | } sph_luffa384_context; 100 | 101 | /** 102 | * This structure is a context for Luffa-512 computations. 103 | */ 104 | typedef struct { 105 | #ifndef DOXYGEN_IGNORE 106 | unsigned char buf[32]; /* first field, for alignment */ 107 | size_t ptr; 108 | sph_u32 V[5][8]; 109 | #endif 110 | } sph_luffa512_context; 111 | 112 | /** 113 | * Initialize a Luffa-224 context. This process performs no memory allocation. 114 | * 115 | * @param cc the Luffa-224 context (pointer to a 116 | * sph_luffa224_context) 117 | */ 118 | void sph_luffa224_init(void *cc); 119 | 120 | /** 121 | * Process some data bytes. It is acceptable that len is zero 122 | * (in which case this function does nothing). 123 | * 124 | * @param cc the Luffa-224 context 125 | * @param data the input data 126 | * @param len the input data length (in bytes) 127 | */ 128 | void sph_luffa224(void *cc, const void *data, size_t len); 129 | 130 | /** 131 | * Terminate the current Luffa-224 computation and output the result into 132 | * the provided buffer. The destination buffer must be wide enough to 133 | * accomodate the result (28 bytes). The context is automatically 134 | * reinitialized. 135 | * 136 | * @param cc the Luffa-224 context 137 | * @param dst the destination buffer 138 | */ 139 | void sph_luffa224_close(void *cc, void *dst); 140 | 141 | /** 142 | * Add a few additional bits (0 to 7) to the current computation, then 143 | * terminate it and output the result in the provided buffer, which must 144 | * be wide enough to accomodate the result (28 bytes). If bit number i 145 | * in ub has value 2^i, then the extra bits are those 146 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 147 | * level). The context is automatically reinitialized. 148 | * 149 | * @param cc the Luffa-224 context 150 | * @param ub the extra bits 151 | * @param n the number of extra bits (0 to 7) 152 | * @param dst the destination buffer 153 | */ 154 | void sph_luffa224_addbits_and_close( 155 | void *cc, unsigned ub, unsigned n, void *dst); 156 | 157 | /** 158 | * Initialize a Luffa-256 context. This process performs no memory allocation. 159 | * 160 | * @param cc the Luffa-256 context (pointer to a 161 | * sph_luffa256_context) 162 | */ 163 | void sph_luffa256_init(void *cc); 164 | 165 | /** 166 | * Process some data bytes. It is acceptable that len is zero 167 | * (in which case this function does nothing). 168 | * 169 | * @param cc the Luffa-256 context 170 | * @param data the input data 171 | * @param len the input data length (in bytes) 172 | */ 173 | void sph_luffa256(void *cc, const void *data, size_t len); 174 | 175 | /** 176 | * Terminate the current Luffa-256 computation and output the result into 177 | * the provided buffer. The destination buffer must be wide enough to 178 | * accomodate the result (32 bytes). The context is automatically 179 | * reinitialized. 180 | * 181 | * @param cc the Luffa-256 context 182 | * @param dst the destination buffer 183 | */ 184 | void sph_luffa256_close(void *cc, void *dst); 185 | 186 | /** 187 | * Add a few additional bits (0 to 7) to the current computation, then 188 | * terminate it and output the result in the provided buffer, which must 189 | * be wide enough to accomodate the result (32 bytes). If bit number i 190 | * in ub has value 2^i, then the extra bits are those 191 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 192 | * level). The context is automatically reinitialized. 193 | * 194 | * @param cc the Luffa-256 context 195 | * @param ub the extra bits 196 | * @param n the number of extra bits (0 to 7) 197 | * @param dst the destination buffer 198 | */ 199 | void sph_luffa256_addbits_and_close( 200 | void *cc, unsigned ub, unsigned n, void *dst); 201 | 202 | /** 203 | * Initialize a Luffa-384 context. This process performs no memory allocation. 204 | * 205 | * @param cc the Luffa-384 context (pointer to a 206 | * sph_luffa384_context) 207 | */ 208 | void sph_luffa384_init(void *cc); 209 | 210 | /** 211 | * Process some data bytes. It is acceptable that len is zero 212 | * (in which case this function does nothing). 213 | * 214 | * @param cc the Luffa-384 context 215 | * @param data the input data 216 | * @param len the input data length (in bytes) 217 | */ 218 | void sph_luffa384(void *cc, const void *data, size_t len); 219 | 220 | /** 221 | * Terminate the current Luffa-384 computation and output the result into 222 | * the provided buffer. The destination buffer must be wide enough to 223 | * accomodate the result (48 bytes). The context is automatically 224 | * reinitialized. 225 | * 226 | * @param cc the Luffa-384 context 227 | * @param dst the destination buffer 228 | */ 229 | void sph_luffa384_close(void *cc, void *dst); 230 | 231 | /** 232 | * Add a few additional bits (0 to 7) to the current computation, then 233 | * terminate it and output the result in the provided buffer, which must 234 | * be wide enough to accomodate the result (48 bytes). If bit number i 235 | * in ub has value 2^i, then the extra bits are those 236 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 237 | * level). The context is automatically reinitialized. 238 | * 239 | * @param cc the Luffa-384 context 240 | * @param ub the extra bits 241 | * @param n the number of extra bits (0 to 7) 242 | * @param dst the destination buffer 243 | */ 244 | void sph_luffa384_addbits_and_close( 245 | void *cc, unsigned ub, unsigned n, void *dst); 246 | 247 | /** 248 | * Initialize a Luffa-512 context. This process performs no memory allocation. 249 | * 250 | * @param cc the Luffa-512 context (pointer to a 251 | * sph_luffa512_context) 252 | */ 253 | void sph_luffa512_init(void *cc); 254 | 255 | /** 256 | * Process some data bytes. It is acceptable that len is zero 257 | * (in which case this function does nothing). 258 | * 259 | * @param cc the Luffa-512 context 260 | * @param data the input data 261 | * @param len the input data length (in bytes) 262 | */ 263 | void sph_luffa512(void *cc, const void *data, size_t len); 264 | 265 | /** 266 | * Terminate the current Luffa-512 computation and output the result into 267 | * the provided buffer. The destination buffer must be wide enough to 268 | * accomodate the result (64 bytes). The context is automatically 269 | * reinitialized. 270 | * 271 | * @param cc the Luffa-512 context 272 | * @param dst the destination buffer 273 | */ 274 | void sph_luffa512_close(void *cc, void *dst); 275 | 276 | /** 277 | * Add a few additional bits (0 to 7) to the current computation, then 278 | * terminate it and output the result in the provided buffer, which must 279 | * be wide enough to accomodate the result (64 bytes). If bit number i 280 | * in ub has value 2^i, then the extra bits are those 281 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 282 | * level). The context is automatically reinitialized. 283 | * 284 | * @param cc the Luffa-512 context 285 | * @param ub the extra bits 286 | * @param n the number of extra bits (0 to 7) 287 | * @param dst the destination buffer 288 | */ 289 | void sph_luffa512_addbits_and_close( 290 | void *cc, unsigned ub, unsigned n, void *dst); 291 | 292 | #ifdef __cplusplus 293 | } 294 | #endif 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_cubehash.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_cubehash.h 180 2010-05-08 02:29:25Z tp $ */ 2 | /** 3 | * CubeHash interface. CubeHash is a family of functions which differ by 4 | * their output size; this implementation defines CubeHash for output 5 | * sizes 224, 256, 384 and 512 bits, with the "standard parameters" 6 | * (CubeHash16/32 with the CubeHash specification notations). 7 | * 8 | * ==========================(LICENSE BEGIN)============================ 9 | * 10 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 11 | * 12 | * Permission is hereby granted, free of charge, to any person obtaining 13 | * a copy of this software and associated documentation files (the 14 | * "Software"), to deal in the Software without restriction, including 15 | * without limitation the rights to use, copy, modify, merge, publish, 16 | * distribute, sublicense, and/or sell copies of the Software, and to 17 | * permit persons to whom the Software is furnished to do so, subject to 18 | * the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be 21 | * included in all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 26 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 27 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 28 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 29 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | * 31 | * ===========================(LICENSE END)============================= 32 | * 33 | * @file sph_cubehash.h 34 | * @author Thomas Pornin 35 | */ 36 | 37 | #ifndef SPH_CUBEHASH_H__ 38 | #define SPH_CUBEHASH_H__ 39 | 40 | #ifdef __cplusplus 41 | extern "C"{ 42 | #endif 43 | 44 | #include 45 | #include "sph_types.h" 46 | 47 | /** 48 | * Output size (in bits) for CubeHash-224. 49 | */ 50 | #define SPH_SIZE_cubehash224 224 51 | 52 | /** 53 | * Output size (in bits) for CubeHash-256. 54 | */ 55 | #define SPH_SIZE_cubehash256 256 56 | 57 | /** 58 | * Output size (in bits) for CubeHash-384. 59 | */ 60 | #define SPH_SIZE_cubehash384 384 61 | 62 | /** 63 | * Output size (in bits) for CubeHash-512. 64 | */ 65 | #define SPH_SIZE_cubehash512 512 66 | 67 | /** 68 | * This structure is a context for CubeHash computations: it contains the 69 | * intermediate values and some data from the last entered block. Once 70 | * a CubeHash computation has been performed, the context can be reused for 71 | * another computation. 72 | * 73 | * The contents of this structure are private. A running CubeHash computation 74 | * can be cloned by copying the context (e.g. with a simple 75 | * memcpy()). 76 | */ 77 | typedef struct { 78 | #ifndef DOXYGEN_IGNORE 79 | unsigned char buf[32]; /* first field, for alignment */ 80 | size_t ptr; 81 | sph_u32 state[32]; 82 | #endif 83 | } sph_cubehash_context; 84 | 85 | /** 86 | * Type for a CubeHash-224 context (identical to the common context). 87 | */ 88 | typedef sph_cubehash_context sph_cubehash224_context; 89 | 90 | /** 91 | * Type for a CubeHash-256 context (identical to the common context). 92 | */ 93 | typedef sph_cubehash_context sph_cubehash256_context; 94 | 95 | /** 96 | * Type for a CubeHash-384 context (identical to the common context). 97 | */ 98 | typedef sph_cubehash_context sph_cubehash384_context; 99 | 100 | /** 101 | * Type for a CubeHash-512 context (identical to the common context). 102 | */ 103 | typedef sph_cubehash_context sph_cubehash512_context; 104 | 105 | /** 106 | * Initialize a CubeHash-224 context. This process performs no memory 107 | * allocation. 108 | * 109 | * @param cc the CubeHash-224 context (pointer to a 110 | * sph_cubehash224_context) 111 | */ 112 | void sph_cubehash224_init(void *cc); 113 | 114 | /** 115 | * Process some data bytes. It is acceptable that len is zero 116 | * (in which case this function does nothing). 117 | * 118 | * @param cc the CubeHash-224 context 119 | * @param data the input data 120 | * @param len the input data length (in bytes) 121 | */ 122 | void sph_cubehash224(void *cc, const void *data, size_t len); 123 | 124 | /** 125 | * Terminate the current CubeHash-224 computation and output the result into 126 | * the provided buffer. The destination buffer must be wide enough to 127 | * accomodate the result (28 bytes). The context is automatically 128 | * reinitialized. 129 | * 130 | * @param cc the CubeHash-224 context 131 | * @param dst the destination buffer 132 | */ 133 | void sph_cubehash224_close(void *cc, void *dst); 134 | 135 | /** 136 | * Add a few additional bits (0 to 7) to the current computation, then 137 | * terminate it and output the result in the provided buffer, which must 138 | * be wide enough to accomodate the result (28 bytes). If bit number i 139 | * in ub has value 2^i, then the extra bits are those 140 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 141 | * level). The context is automatically reinitialized. 142 | * 143 | * @param cc the CubeHash-224 context 144 | * @param ub the extra bits 145 | * @param n the number of extra bits (0 to 7) 146 | * @param dst the destination buffer 147 | */ 148 | void sph_cubehash224_addbits_and_close( 149 | void *cc, unsigned ub, unsigned n, void *dst); 150 | 151 | /** 152 | * Initialize a CubeHash-256 context. This process performs no memory 153 | * allocation. 154 | * 155 | * @param cc the CubeHash-256 context (pointer to a 156 | * sph_cubehash256_context) 157 | */ 158 | void sph_cubehash256_init(void *cc); 159 | 160 | /** 161 | * Process some data bytes. It is acceptable that len is zero 162 | * (in which case this function does nothing). 163 | * 164 | * @param cc the CubeHash-256 context 165 | * @param data the input data 166 | * @param len the input data length (in bytes) 167 | */ 168 | void sph_cubehash256(void *cc, const void *data, size_t len); 169 | 170 | /** 171 | * Terminate the current CubeHash-256 computation and output the result into 172 | * the provided buffer. The destination buffer must be wide enough to 173 | * accomodate the result (32 bytes). The context is automatically 174 | * reinitialized. 175 | * 176 | * @param cc the CubeHash-256 context 177 | * @param dst the destination buffer 178 | */ 179 | void sph_cubehash256_close(void *cc, void *dst); 180 | 181 | /** 182 | * Add a few additional bits (0 to 7) to the current computation, then 183 | * terminate it and output the result in the provided buffer, which must 184 | * be wide enough to accomodate the result (32 bytes). If bit number i 185 | * in ub has value 2^i, then the extra bits are those 186 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 187 | * level). The context is automatically reinitialized. 188 | * 189 | * @param cc the CubeHash-256 context 190 | * @param ub the extra bits 191 | * @param n the number of extra bits (0 to 7) 192 | * @param dst the destination buffer 193 | */ 194 | void sph_cubehash256_addbits_and_close( 195 | void *cc, unsigned ub, unsigned n, void *dst); 196 | 197 | /** 198 | * Initialize a CubeHash-384 context. This process performs no memory 199 | * allocation. 200 | * 201 | * @param cc the CubeHash-384 context (pointer to a 202 | * sph_cubehash384_context) 203 | */ 204 | void sph_cubehash384_init(void *cc); 205 | 206 | /** 207 | * Process some data bytes. It is acceptable that len is zero 208 | * (in which case this function does nothing). 209 | * 210 | * @param cc the CubeHash-384 context 211 | * @param data the input data 212 | * @param len the input data length (in bytes) 213 | */ 214 | void sph_cubehash384(void *cc, const void *data, size_t len); 215 | 216 | /** 217 | * Terminate the current CubeHash-384 computation and output the result into 218 | * the provided buffer. The destination buffer must be wide enough to 219 | * accomodate the result (48 bytes). The context is automatically 220 | * reinitialized. 221 | * 222 | * @param cc the CubeHash-384 context 223 | * @param dst the destination buffer 224 | */ 225 | void sph_cubehash384_close(void *cc, void *dst); 226 | 227 | /** 228 | * Add a few additional bits (0 to 7) to the current computation, then 229 | * terminate it and output the result in the provided buffer, which must 230 | * be wide enough to accomodate the result (48 bytes). If bit number i 231 | * in ub has value 2^i, then the extra bits are those 232 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 233 | * level). The context is automatically reinitialized. 234 | * 235 | * @param cc the CubeHash-384 context 236 | * @param ub the extra bits 237 | * @param n the number of extra bits (0 to 7) 238 | * @param dst the destination buffer 239 | */ 240 | void sph_cubehash384_addbits_and_close( 241 | void *cc, unsigned ub, unsigned n, void *dst); 242 | 243 | /** 244 | * Initialize a CubeHash-512 context. This process performs no memory 245 | * allocation. 246 | * 247 | * @param cc the CubeHash-512 context (pointer to a 248 | * sph_cubehash512_context) 249 | */ 250 | void sph_cubehash512_init(void *cc); 251 | 252 | /** 253 | * Process some data bytes. It is acceptable that len is zero 254 | * (in which case this function does nothing). 255 | * 256 | * @param cc the CubeHash-512 context 257 | * @param data the input data 258 | * @param len the input data length (in bytes) 259 | */ 260 | void sph_cubehash512(void *cc, const void *data, size_t len); 261 | 262 | /** 263 | * Terminate the current CubeHash-512 computation and output the result into 264 | * the provided buffer. The destination buffer must be wide enough to 265 | * accomodate the result (64 bytes). The context is automatically 266 | * reinitialized. 267 | * 268 | * @param cc the CubeHash-512 context 269 | * @param dst the destination buffer 270 | */ 271 | void sph_cubehash512_close(void *cc, void *dst); 272 | 273 | /** 274 | * Add a few additional bits (0 to 7) to the current computation, then 275 | * terminate it and output the result in the provided buffer, which must 276 | * be wide enough to accomodate the result (64 bytes). If bit number i 277 | * in ub has value 2^i, then the extra bits are those 278 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 279 | * level). The context is automatically reinitialized. 280 | * 281 | * @param cc the CubeHash-512 context 282 | * @param ub the extra bits 283 | * @param n the number of extra bits (0 to 7) 284 | * @param dst the destination buffer 285 | */ 286 | void sph_cubehash512_addbits_and_close( 287 | void *cc, unsigned ub, unsigned n, void *dst); 288 | #ifdef __cplusplus 289 | } 290 | #endif 291 | 292 | #endif 293 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_skein.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_skein.h 253 2011-06-07 18:33:10Z tp $ */ 2 | /** 3 | * Skein interface. The Skein specification defines three main 4 | * functions, called Skein-256, Skein-512 and Skein-1024, which can be 5 | * further parameterized with an output length. For the SHA-3 6 | * competition, Skein-512 is used for output sizes of 224, 256, 384 and 7 | * 512 bits; this is what this code implements. Thus, we hereafter call 8 | * Skein-224, Skein-256, Skein-384 and Skein-512 what the Skein 9 | * specification defines as Skein-512-224, Skein-512-256, Skein-512-384 10 | * and Skein-512-512, respectively. 11 | * 12 | * ==========================(LICENSE BEGIN)============================ 13 | * 14 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining 17 | * a copy of this software and associated documentation files (the 18 | * "Software"), to deal in the Software without restriction, including 19 | * without limitation the rights to use, copy, modify, merge, publish, 20 | * distribute, sublicense, and/or sell copies of the Software, and to 21 | * permit persons to whom the Software is furnished to do so, subject to 22 | * the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be 25 | * included in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 30 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 31 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 32 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 33 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | * 35 | * ===========================(LICENSE END)============================= 36 | * 37 | * @file sph_skein.h 38 | * @author Thomas Pornin 39 | */ 40 | 41 | #ifndef SPH_SKEIN_H__ 42 | #define SPH_SKEIN_H__ 43 | 44 | #ifdef __cplusplus 45 | extern "C"{ 46 | #endif 47 | 48 | #include 49 | #include "sph_types.h" 50 | 51 | #if SPH_64 52 | 53 | /** 54 | * Output size (in bits) for Skein-224. 55 | */ 56 | #define SPH_SIZE_skein224 224 57 | 58 | /** 59 | * Output size (in bits) for Skein-256. 60 | */ 61 | #define SPH_SIZE_skein256 256 62 | 63 | /** 64 | * Output size (in bits) for Skein-384. 65 | */ 66 | #define SPH_SIZE_skein384 384 67 | 68 | /** 69 | * Output size (in bits) for Skein-512. 70 | */ 71 | #define SPH_SIZE_skein512 512 72 | 73 | /** 74 | * This structure is a context for Skein computations (with a 384- or 75 | * 512-bit output): it contains the intermediate values and some data 76 | * from the last entered block. Once a Skein computation has been 77 | * performed, the context can be reused for another computation. 78 | * 79 | * The contents of this structure are private. A running Skein computation 80 | * can be cloned by copying the context (e.g. with a simple 81 | * memcpy()). 82 | */ 83 | typedef struct { 84 | #ifndef DOXYGEN_IGNORE 85 | unsigned char buf[64]; /* first field, for alignment */ 86 | size_t ptr; 87 | sph_u64 h0, h1, h2, h3, h4, h5, h6, h7; 88 | sph_u64 bcount; 89 | #endif 90 | } sph_skein_big_context; 91 | 92 | /** 93 | * Type for a Skein-224 context (identical to the common "big" context). 94 | */ 95 | typedef sph_skein_big_context sph_skein224_context; 96 | 97 | /** 98 | * Type for a Skein-256 context (identical to the common "big" context). 99 | */ 100 | typedef sph_skein_big_context sph_skein256_context; 101 | 102 | /** 103 | * Type for a Skein-384 context (identical to the common "big" context). 104 | */ 105 | typedef sph_skein_big_context sph_skein384_context; 106 | 107 | /** 108 | * Type for a Skein-512 context (identical to the common "big" context). 109 | */ 110 | typedef sph_skein_big_context sph_skein512_context; 111 | 112 | /** 113 | * Initialize a Skein-224 context. This process performs no memory allocation. 114 | * 115 | * @param cc the Skein-224 context (pointer to a 116 | * sph_skein224_context) 117 | */ 118 | void sph_skein224_init(void *cc); 119 | 120 | /** 121 | * Process some data bytes. It is acceptable that len is zero 122 | * (in which case this function does nothing). 123 | * 124 | * @param cc the Skein-224 context 125 | * @param data the input data 126 | * @param len the input data length (in bytes) 127 | */ 128 | void sph_skein224(void *cc, const void *data, size_t len); 129 | 130 | /** 131 | * Terminate the current Skein-224 computation and output the result into 132 | * the provided buffer. The destination buffer must be wide enough to 133 | * accomodate the result (28 bytes). The context is automatically 134 | * reinitialized. 135 | * 136 | * @param cc the Skein-224 context 137 | * @param dst the destination buffer 138 | */ 139 | void sph_skein224_close(void *cc, void *dst); 140 | 141 | /** 142 | * Add a few additional bits (0 to 7) to the current computation, then 143 | * terminate it and output the result in the provided buffer, which must 144 | * be wide enough to accomodate the result (28 bytes). If bit number i 145 | * in ub has value 2^i, then the extra bits are those 146 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 147 | * level). The context is automatically reinitialized. 148 | * 149 | * @param cc the Skein-224 context 150 | * @param ub the extra bits 151 | * @param n the number of extra bits (0 to 7) 152 | * @param dst the destination buffer 153 | */ 154 | void sph_skein224_addbits_and_close( 155 | void *cc, unsigned ub, unsigned n, void *dst); 156 | 157 | /** 158 | * Initialize a Skein-256 context. This process performs no memory allocation. 159 | * 160 | * @param cc the Skein-256 context (pointer to a 161 | * sph_skein256_context) 162 | */ 163 | void sph_skein256_init(void *cc); 164 | 165 | /** 166 | * Process some data bytes. It is acceptable that len is zero 167 | * (in which case this function does nothing). 168 | * 169 | * @param cc the Skein-256 context 170 | * @param data the input data 171 | * @param len the input data length (in bytes) 172 | */ 173 | void sph_skein256(void *cc, const void *data, size_t len); 174 | 175 | /** 176 | * Terminate the current Skein-256 computation and output the result into 177 | * the provided buffer. The destination buffer must be wide enough to 178 | * accomodate the result (32 bytes). The context is automatically 179 | * reinitialized. 180 | * 181 | * @param cc the Skein-256 context 182 | * @param dst the destination buffer 183 | */ 184 | void sph_skein256_close(void *cc, void *dst); 185 | 186 | /** 187 | * Add a few additional bits (0 to 7) to the current computation, then 188 | * terminate it and output the result in the provided buffer, which must 189 | * be wide enough to accomodate the result (32 bytes). If bit number i 190 | * in ub has value 2^i, then the extra bits are those 191 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 192 | * level). The context is automatically reinitialized. 193 | * 194 | * @param cc the Skein-256 context 195 | * @param ub the extra bits 196 | * @param n the number of extra bits (0 to 7) 197 | * @param dst the destination buffer 198 | */ 199 | void sph_skein256_addbits_and_close( 200 | void *cc, unsigned ub, unsigned n, void *dst); 201 | 202 | /** 203 | * Initialize a Skein-384 context. This process performs no memory allocation. 204 | * 205 | * @param cc the Skein-384 context (pointer to a 206 | * sph_skein384_context) 207 | */ 208 | void sph_skein384_init(void *cc); 209 | 210 | /** 211 | * Process some data bytes. It is acceptable that len is zero 212 | * (in which case this function does nothing). 213 | * 214 | * @param cc the Skein-384 context 215 | * @param data the input data 216 | * @param len the input data length (in bytes) 217 | */ 218 | void sph_skein384(void *cc, const void *data, size_t len); 219 | 220 | /** 221 | * Terminate the current Skein-384 computation and output the result into 222 | * the provided buffer. The destination buffer must be wide enough to 223 | * accomodate the result (48 bytes). The context is automatically 224 | * reinitialized. 225 | * 226 | * @param cc the Skein-384 context 227 | * @param dst the destination buffer 228 | */ 229 | void sph_skein384_close(void *cc, void *dst); 230 | 231 | /** 232 | * Add a few additional bits (0 to 7) to the current computation, then 233 | * terminate it and output the result in the provided buffer, which must 234 | * be wide enough to accomodate the result (48 bytes). If bit number i 235 | * in ub has value 2^i, then the extra bits are those 236 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 237 | * level). The context is automatically reinitialized. 238 | * 239 | * @param cc the Skein-384 context 240 | * @param ub the extra bits 241 | * @param n the number of extra bits (0 to 7) 242 | * @param dst the destination buffer 243 | */ 244 | void sph_skein384_addbits_and_close( 245 | void *cc, unsigned ub, unsigned n, void *dst); 246 | 247 | /** 248 | * Initialize a Skein-512 context. This process performs no memory allocation. 249 | * 250 | * @param cc the Skein-512 context (pointer to a 251 | * sph_skein512_context) 252 | */ 253 | void sph_skein512_init(void *cc); 254 | 255 | /** 256 | * Process some data bytes. It is acceptable that len is zero 257 | * (in which case this function does nothing). 258 | * 259 | * @param cc the Skein-512 context 260 | * @param data the input data 261 | * @param len the input data length (in bytes) 262 | */ 263 | void sph_skein512(void *cc, const void *data, size_t len); 264 | 265 | /** 266 | * Terminate the current Skein-512 computation and output the result into 267 | * the provided buffer. The destination buffer must be wide enough to 268 | * accomodate the result (64 bytes). The context is automatically 269 | * reinitialized. 270 | * 271 | * @param cc the Skein-512 context 272 | * @param dst the destination buffer 273 | */ 274 | void sph_skein512_close(void *cc, void *dst); 275 | 276 | /** 277 | * Add a few additional bits (0 to 7) to the current computation, then 278 | * terminate it and output the result in the provided buffer, which must 279 | * be wide enough to accomodate the result (64 bytes). If bit number i 280 | * in ub has value 2^i, then the extra bits are those 281 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 282 | * level). The context is automatically reinitialized. 283 | * 284 | * @param cc the Skein-512 context 285 | * @param ub the extra bits 286 | * @param n the number of extra bits (0 to 7) 287 | * @param dst the destination buffer 288 | */ 289 | void sph_skein512_addbits_and_close( 290 | void *cc, unsigned ub, unsigned n, void *dst); 291 | 292 | #endif 293 | 294 | #ifdef __cplusplus 295 | } 296 | #endif 297 | 298 | #endif 299 | -------------------------------------------------------------------------------- /mixhash/sha3/blake2s.c: -------------------------------------------------------------------------------- 1 | /** 2 | * BLAKE2 reference source code package - reference C implementations 3 | * 4 | * Written in 2012 by Samuel Neves 5 | * 6 | * To the extent possible under law, the author(s) have dedicated all copyright 7 | * and related and neighboring rights to this software to the public domain 8 | * worldwide. This software is distributed without any warranty. 9 | * 10 | * You should have received a copy of the CC0 Public Domain Dedication along with 11 | * this software. If not, see . 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "sph_types.h" 19 | 20 | #include "blake2s.h" 21 | 22 | static const uint32_t blake2s_IV[8] = 23 | { 24 | 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, 25 | 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL 26 | }; 27 | 28 | static const uint8_t blake2s_sigma[10][16] = 29 | { 30 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , 31 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , 32 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , 33 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , 34 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , 35 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , 36 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , 37 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , 38 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , 39 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , 40 | }; 41 | 42 | static inline int blake2s_set_lastnode( blake2s_state *S ) 43 | { 44 | S->f[1] = ~0U; 45 | return 0; 46 | } 47 | 48 | static inline int blake2s_clear_lastnode( blake2s_state *S ) 49 | { 50 | S->f[1] = 0U; 51 | return 0; 52 | } 53 | 54 | /* Some helper functions, not necessarily useful */ 55 | static inline int blake2s_set_lastblock( blake2s_state *S ) 56 | { 57 | if( S->last_node ) blake2s_set_lastnode( S ); 58 | 59 | S->f[0] = ~0U; 60 | return 0; 61 | } 62 | 63 | static inline int blake2s_clear_lastblock( blake2s_state *S ) 64 | { 65 | if( S->last_node ) blake2s_clear_lastnode( S ); 66 | 67 | S->f[0] = 0U; 68 | return 0; 69 | } 70 | 71 | static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) 72 | { 73 | S->t[0] += inc; 74 | S->t[1] += ( S->t[0] < inc ); 75 | return 0; 76 | } 77 | 78 | // Parameter-related functions 79 | static inline int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length ) 80 | { 81 | P->digest_length = digest_length; 82 | return 0; 83 | } 84 | 85 | static inline int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout ) 86 | { 87 | P->fanout = fanout; 88 | return 0; 89 | } 90 | 91 | static inline int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth ) 92 | { 93 | P->depth = depth; 94 | return 0; 95 | } 96 | 97 | static inline int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length ) 98 | { 99 | store32( &P->leaf_length, leaf_length ); 100 | return 0; 101 | } 102 | 103 | static inline int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset ) 104 | { 105 | store48( P->node_offset, node_offset ); 106 | return 0; 107 | } 108 | 109 | static inline int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth ) 110 | { 111 | P->node_depth = node_depth; 112 | return 0; 113 | } 114 | 115 | static inline int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length ) 116 | { 117 | P->inner_length = inner_length; 118 | return 0; 119 | } 120 | 121 | static inline int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] ) 122 | { 123 | memcpy( P->salt, salt, BLAKE2S_SALTBYTES ); 124 | return 0; 125 | } 126 | 127 | static inline int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] ) 128 | { 129 | memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES ); 130 | return 0; 131 | } 132 | 133 | static inline int blake2s_init0( blake2s_state *S ) 134 | { 135 | memset( S, 0, sizeof( blake2s_state ) ); 136 | 137 | for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i]; 138 | 139 | return 0; 140 | } 141 | 142 | /* init2 xors IV with input parameter block */ 143 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) 144 | { 145 | blake2s_init0( S ); 146 | uint32_t *p = ( uint32_t * )( P ); 147 | 148 | /* IV XOR ParamBlock */ 149 | for( size_t i = 0; i < 8; ++i ) 150 | S->h[i] ^= load32( &p[i] ); 151 | 152 | return 0; 153 | } 154 | 155 | 156 | // Sequential blake2s initialization 157 | int blake2s_init( blake2s_state *S, const uint8_t outlen ) 158 | { 159 | blake2s_param P[1]; 160 | 161 | /* Move interval verification here? */ 162 | if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; 163 | 164 | P->digest_length = outlen; 165 | P->key_length = 0; 166 | P->fanout = 1; 167 | P->depth = 1; 168 | store32( &P->leaf_length, 0 ); 169 | store48( &P->node_offset, 0 ); 170 | P->node_depth = 0; 171 | P->inner_length = 0; 172 | // memset(P->reserved, 0, sizeof(P->reserved) ); 173 | memset( P->salt, 0, sizeof( P->salt ) ); 174 | memset( P->personal, 0, sizeof( P->personal ) ); 175 | return blake2s_init_param( S, P ); 176 | } 177 | 178 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ) 179 | { 180 | blake2s_param P[1]; 181 | 182 | if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; 183 | 184 | if ( !key || !keylen || keylen > BLAKE2S_KEYBYTES ) return -1; 185 | 186 | P->digest_length = outlen; 187 | P->key_length = keylen; 188 | P->fanout = 1; 189 | P->depth = 1; 190 | store32( &P->leaf_length, 0 ); 191 | store48( &P->node_offset, 0 ); 192 | P->node_depth = 0; 193 | P->inner_length = 0; 194 | // memset(P->reserved, 0, sizeof(P->reserved) ); 195 | memset( P->salt, 0, sizeof( P->salt ) ); 196 | memset( P->personal, 0, sizeof( P->personal ) ); 197 | 198 | if( blake2s_init_param( S, P ) < 0 ) return -1; 199 | 200 | { 201 | uint8_t block[BLAKE2S_BLOCKBYTES]; 202 | memset( block, 0, BLAKE2S_BLOCKBYTES ); 203 | memcpy( block, key, keylen ); 204 | blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); 205 | secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ 206 | } 207 | return 0; 208 | } 209 | 210 | int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] ) 211 | { 212 | uint32_t m[16]; 213 | uint32_t v[16]; 214 | 215 | for( size_t i = 0; i < 16; ++i ) 216 | m[i] = load32( block + i * sizeof( m[i] ) ); 217 | 218 | for( size_t i = 0; i < 8; ++i ) 219 | v[i] = S->h[i]; 220 | 221 | v[ 8] = blake2s_IV[0]; 222 | v[ 9] = blake2s_IV[1]; 223 | v[10] = blake2s_IV[2]; 224 | v[11] = blake2s_IV[3]; 225 | v[12] = S->t[0] ^ blake2s_IV[4]; 226 | v[13] = S->t[1] ^ blake2s_IV[5]; 227 | v[14] = S->f[0] ^ blake2s_IV[6]; 228 | v[15] = S->f[1] ^ blake2s_IV[7]; 229 | #define G(r,i,a,b,c,d) \ 230 | do { \ 231 | a = a + b + m[blake2s_sigma[r][2*i+0]]; \ 232 | d = SPH_ROTR32(d ^ a, 16); \ 233 | c = c + d; \ 234 | b = SPH_ROTR32(b ^ c, 12); \ 235 | a = a + b + m[blake2s_sigma[r][2*i+1]]; \ 236 | d = SPH_ROTR32(d ^ a, 8); \ 237 | c = c + d; \ 238 | b = SPH_ROTR32(b ^ c, 7); \ 239 | } while(0) 240 | #define ROUND(r) \ 241 | do { \ 242 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ 243 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ 244 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \ 245 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \ 246 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \ 247 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \ 248 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ 249 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ 250 | } while(0) 251 | ROUND( 0 ); 252 | ROUND( 1 ); 253 | ROUND( 2 ); 254 | ROUND( 3 ); 255 | ROUND( 4 ); 256 | ROUND( 5 ); 257 | ROUND( 6 ); 258 | ROUND( 7 ); 259 | ROUND( 8 ); 260 | ROUND( 9 ); 261 | 262 | for( size_t i = 0; i < 8; ++i ) 263 | S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; 264 | 265 | #undef G 266 | #undef ROUND 267 | return 0; 268 | } 269 | 270 | 271 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ) 272 | { 273 | while( inlen > 0 ) 274 | { 275 | size_t left = S->buflen; 276 | size_t fill = 2 * BLAKE2S_BLOCKBYTES - left; 277 | 278 | if( inlen > fill ) 279 | { 280 | memcpy( S->buf + left, in, fill ); // Fill buffer 281 | S->buflen += fill; 282 | blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); 283 | blake2s_compress( S, S->buf ); // Compress 284 | memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); // Shift buffer left 285 | S->buflen -= BLAKE2S_BLOCKBYTES; 286 | in += fill; 287 | inlen -= fill; 288 | } 289 | else // inlen <= fill 290 | { 291 | memcpy(S->buf + left, in, (size_t) inlen); 292 | S->buflen += (size_t) inlen; // Be lazy, do not compress 293 | in += inlen; 294 | inlen -= inlen; 295 | } 296 | } 297 | 298 | return 0; 299 | } 300 | 301 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ) 302 | { 303 | uint8_t buffer[BLAKE2S_OUTBYTES]; 304 | 305 | if( S->buflen > BLAKE2S_BLOCKBYTES ) 306 | { 307 | blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); 308 | blake2s_compress( S, S->buf ); 309 | S->buflen -= BLAKE2S_BLOCKBYTES; 310 | memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen ); 311 | } 312 | 313 | blake2s_increment_counter( S, ( uint32_t )S->buflen ); 314 | blake2s_set_lastblock( S ); 315 | memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */ 316 | blake2s_compress( S, S->buf ); 317 | 318 | for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ 319 | store32( buffer + sizeof( S->h[i] ) * i, S->h[i] ); 320 | 321 | memcpy( out, buffer, outlen ); 322 | return 0; 323 | } 324 | 325 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 326 | { 327 | blake2s_state S[1]; 328 | 329 | /* Verify parameters */ 330 | if ( NULL == in ) return -1; 331 | 332 | if ( NULL == out ) return -1; 333 | 334 | if ( NULL == key ) keylen = 0; /* Fail here instead if keylen != 0 and key == NULL? */ 335 | 336 | if( keylen > 0 ) 337 | { 338 | if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; 339 | } 340 | else 341 | { 342 | if( blake2s_init( S, outlen ) < 0 ) return -1; 343 | } 344 | 345 | blake2s_update( S, ( uint8_t * )in, inlen ); 346 | blake2s_final( S, out, outlen ); 347 | return 0; 348 | } 349 | 350 | #if defined(BLAKE2S_SELFTEST) 351 | #include 352 | #include "blake2-kat.h" /* test data not included */ 353 | int main( int argc, char **argv ) 354 | { 355 | uint8_t key[BLAKE2S_KEYBYTES]; 356 | uint8_t buf[KAT_LENGTH]; 357 | 358 | for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i ) 359 | key[i] = ( uint8_t )i; 360 | 361 | for( size_t i = 0; i < KAT_LENGTH; ++i ) 362 | buf[i] = ( uint8_t )i; 363 | 364 | for( size_t i = 0; i < KAT_LENGTH; ++i ) 365 | { 366 | uint8_t hash[BLAKE2S_OUTBYTES]; 367 | blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES ); 368 | 369 | if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) ) 370 | { 371 | puts( "error" ); 372 | return -1; 373 | } 374 | } 375 | 376 | puts( "ok" ); 377 | return 0; 378 | } 379 | #endif 380 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_simd.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_simd.h 154 2010-04-26 17:00:24Z tp $ */ 2 | /** 3 | * SIMD interface. SIMD is a family of functions which differ by 4 | * their output size; this implementation defines SIMD for output 5 | * sizes 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_simd.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_SIMD_H__ 37 | #define SPH_SIMD_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for SIMD-224. 48 | */ 49 | #define SPH_SIZE_simd224 224 50 | 51 | /** 52 | * Output size (in bits) for SIMD-256. 53 | */ 54 | #define SPH_SIZE_simd256 256 55 | 56 | /** 57 | * Output size (in bits) for SIMD-384. 58 | */ 59 | #define SPH_SIZE_simd384 384 60 | 61 | /** 62 | * Output size (in bits) for SIMD-512. 63 | */ 64 | #define SPH_SIZE_simd512 512 65 | 66 | /** 67 | * This structure is a context for SIMD computations: it contains the 68 | * intermediate values and some data from the last entered block. Once 69 | * an SIMD computation has been performed, the context can be reused for 70 | * another computation. This specific structure is used for SIMD-224 71 | * and SIMD-256. 72 | * 73 | * The contents of this structure are private. A running SIMD computation 74 | * can be cloned by copying the context (e.g. with a simple 75 | * memcpy()). 76 | */ 77 | typedef struct { 78 | #ifndef DOXYGEN_IGNORE 79 | unsigned char buf[64]; /* first field, for alignment */ 80 | size_t ptr; 81 | sph_u32 state[16]; 82 | sph_u32 count_low, count_high; 83 | #endif 84 | } sph_simd_small_context; 85 | 86 | /** 87 | * This structure is a context for SIMD computations: it contains the 88 | * intermediate values and some data from the last entered block. Once 89 | * an SIMD computation has been performed, the context can be reused for 90 | * another computation. This specific structure is used for SIMD-384 91 | * and SIMD-512. 92 | * 93 | * The contents of this structure are private. A running SIMD computation 94 | * can be cloned by copying the context (e.g. with a simple 95 | * memcpy()). 96 | */ 97 | typedef struct { 98 | #ifndef DOXYGEN_IGNORE 99 | unsigned char buf[128]; /* first field, for alignment */ 100 | size_t ptr; 101 | sph_u32 state[32]; 102 | sph_u32 count_low, count_high; 103 | #endif 104 | } sph_simd_big_context; 105 | 106 | /** 107 | * Type for a SIMD-224 context (identical to the common "small" context). 108 | */ 109 | typedef sph_simd_small_context sph_simd224_context; 110 | 111 | /** 112 | * Type for a SIMD-256 context (identical to the common "small" context). 113 | */ 114 | typedef sph_simd_small_context sph_simd256_context; 115 | 116 | /** 117 | * Type for a SIMD-384 context (identical to the common "big" context). 118 | */ 119 | typedef sph_simd_big_context sph_simd384_context; 120 | 121 | /** 122 | * Type for a SIMD-512 context (identical to the common "big" context). 123 | */ 124 | typedef sph_simd_big_context sph_simd512_context; 125 | 126 | /** 127 | * Initialize an SIMD-224 context. This process performs no memory allocation. 128 | * 129 | * @param cc the SIMD-224 context (pointer to a 130 | * sph_simd224_context) 131 | */ 132 | void sph_simd224_init(void *cc); 133 | 134 | /** 135 | * Process some data bytes. It is acceptable that len is zero 136 | * (in which case this function does nothing). 137 | * 138 | * @param cc the SIMD-224 context 139 | * @param data the input data 140 | * @param len the input data length (in bytes) 141 | */ 142 | void sph_simd224(void *cc, const void *data, size_t len); 143 | 144 | /** 145 | * Terminate the current SIMD-224 computation and output the result into 146 | * the provided buffer. The destination buffer must be wide enough to 147 | * accomodate the result (28 bytes). The context is automatically 148 | * reinitialized. 149 | * 150 | * @param cc the SIMD-224 context 151 | * @param dst the destination buffer 152 | */ 153 | void sph_simd224_close(void *cc, void *dst); 154 | 155 | /** 156 | * Add a few additional bits (0 to 7) to the current computation, then 157 | * terminate it and output the result in the provided buffer, which must 158 | * be wide enough to accomodate the result (28 bytes). If bit number i 159 | * in ub has value 2^i, then the extra bits are those 160 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 161 | * level). The context is automatically reinitialized. 162 | * 163 | * @param cc the SIMD-224 context 164 | * @param ub the extra bits 165 | * @param n the number of extra bits (0 to 7) 166 | * @param dst the destination buffer 167 | */ 168 | void sph_simd224_addbits_and_close( 169 | void *cc, unsigned ub, unsigned n, void *dst); 170 | 171 | /** 172 | * Initialize an SIMD-256 context. This process performs no memory allocation. 173 | * 174 | * @param cc the SIMD-256 context (pointer to a 175 | * sph_simd256_context) 176 | */ 177 | void sph_simd256_init(void *cc); 178 | 179 | /** 180 | * Process some data bytes. It is acceptable that len is zero 181 | * (in which case this function does nothing). 182 | * 183 | * @param cc the SIMD-256 context 184 | * @param data the input data 185 | * @param len the input data length (in bytes) 186 | */ 187 | void sph_simd256(void *cc, const void *data, size_t len); 188 | 189 | /** 190 | * Terminate the current SIMD-256 computation and output the result into 191 | * the provided buffer. The destination buffer must be wide enough to 192 | * accomodate the result (32 bytes). The context is automatically 193 | * reinitialized. 194 | * 195 | * @param cc the SIMD-256 context 196 | * @param dst the destination buffer 197 | */ 198 | void sph_simd256_close(void *cc, void *dst); 199 | 200 | /** 201 | * Add a few additional bits (0 to 7) to the current computation, then 202 | * terminate it and output the result in the provided buffer, which must 203 | * be wide enough to accomodate the result (32 bytes). If bit number i 204 | * in ub has value 2^i, then the extra bits are those 205 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 206 | * level). The context is automatically reinitialized. 207 | * 208 | * @param cc the SIMD-256 context 209 | * @param ub the extra bits 210 | * @param n the number of extra bits (0 to 7) 211 | * @param dst the destination buffer 212 | */ 213 | void sph_simd256_addbits_and_close( 214 | void *cc, unsigned ub, unsigned n, void *dst); 215 | 216 | /** 217 | * Initialize an SIMD-384 context. This process performs no memory allocation. 218 | * 219 | * @param cc the SIMD-384 context (pointer to a 220 | * sph_simd384_context) 221 | */ 222 | void sph_simd384_init(void *cc); 223 | 224 | /** 225 | * Process some data bytes. It is acceptable that len is zero 226 | * (in which case this function does nothing). 227 | * 228 | * @param cc the SIMD-384 context 229 | * @param data the input data 230 | * @param len the input data length (in bytes) 231 | */ 232 | void sph_simd384(void *cc, const void *data, size_t len); 233 | 234 | /** 235 | * Terminate the current SIMD-384 computation and output the result into 236 | * the provided buffer. The destination buffer must be wide enough to 237 | * accomodate the result (48 bytes). The context is automatically 238 | * reinitialized. 239 | * 240 | * @param cc the SIMD-384 context 241 | * @param dst the destination buffer 242 | */ 243 | void sph_simd384_close(void *cc, void *dst); 244 | 245 | /** 246 | * Add a few additional bits (0 to 7) to the current computation, then 247 | * terminate it and output the result in the provided buffer, which must 248 | * be wide enough to accomodate the result (48 bytes). If bit number i 249 | * in ub has value 2^i, then the extra bits are those 250 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 251 | * level). The context is automatically reinitialized. 252 | * 253 | * @param cc the SIMD-384 context 254 | * @param ub the extra bits 255 | * @param n the number of extra bits (0 to 7) 256 | * @param dst the destination buffer 257 | */ 258 | void sph_simd384_addbits_and_close( 259 | void *cc, unsigned ub, unsigned n, void *dst); 260 | 261 | /** 262 | * Initialize an SIMD-512 context. This process performs no memory allocation. 263 | * 264 | * @param cc the SIMD-512 context (pointer to a 265 | * sph_simd512_context) 266 | */ 267 | void sph_simd512_init(void *cc); 268 | 269 | /** 270 | * Process some data bytes. It is acceptable that len is zero 271 | * (in which case this function does nothing). 272 | * 273 | * @param cc the SIMD-512 context 274 | * @param data the input data 275 | * @param len the input data length (in bytes) 276 | */ 277 | void sph_simd512(void *cc, const void *data, size_t len); 278 | 279 | /** 280 | * Terminate the current SIMD-512 computation and output the result into 281 | * the provided buffer. The destination buffer must be wide enough to 282 | * accomodate the result (64 bytes). The context is automatically 283 | * reinitialized. 284 | * 285 | * @param cc the SIMD-512 context 286 | * @param dst the destination buffer 287 | */ 288 | void sph_simd512_close(void *cc, void *dst); 289 | 290 | /** 291 | * Add a few additional bits (0 to 7) to the current computation, then 292 | * terminate it and output the result in the provided buffer, which must 293 | * be wide enough to accomodate the result (64 bytes). If bit number i 294 | * in ub has value 2^i, then the extra bits are those 295 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 296 | * level). The context is automatically reinitialized. 297 | * 298 | * @param cc the SIMD-512 context 299 | * @param ub the extra bits 300 | * @param n the number of extra bits (0 to 7) 301 | * @param dst the destination buffer 302 | */ 303 | void sph_simd512_addbits_and_close( 304 | void *cc, unsigned ub, unsigned n, void *dst); 305 | #ifdef __cplusplus 306 | } 307 | #endif 308 | 309 | #endif 310 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_echo.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_echo.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * ECHO interface. ECHO is a family of functions which differ by 4 | * their output size; this implementation defines ECHO for output 5 | * sizes 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_echo.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_ECHO_H__ 37 | #define SPH_ECHO_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for ECHO-224. 48 | */ 49 | #define SPH_SIZE_echo224 224 50 | 51 | /** 52 | * Output size (in bits) for ECHO-256. 53 | */ 54 | #define SPH_SIZE_echo256 256 55 | 56 | /** 57 | * Output size (in bits) for ECHO-384. 58 | */ 59 | #define SPH_SIZE_echo384 384 60 | 61 | /** 62 | * Output size (in bits) for ECHO-512. 63 | */ 64 | #define SPH_SIZE_echo512 512 65 | 66 | /** 67 | * This structure is a context for ECHO computations: it contains the 68 | * intermediate values and some data from the last entered block. Once 69 | * an ECHO computation has been performed, the context can be reused for 70 | * another computation. This specific structure is used for ECHO-224 71 | * and ECHO-256. 72 | * 73 | * The contents of this structure are private. A running ECHO computation 74 | * can be cloned by copying the context (e.g. with a simple 75 | * memcpy()). 76 | */ 77 | typedef struct { 78 | #ifndef DOXYGEN_IGNORE 79 | unsigned char buf[192]; /* first field, for alignment */ 80 | size_t ptr; 81 | union { 82 | sph_u32 Vs[4][4]; 83 | #if SPH_64 84 | sph_u64 Vb[4][2]; 85 | #endif 86 | } u; 87 | sph_u32 C0, C1, C2, C3; 88 | #endif 89 | } sph_echo_small_context; 90 | 91 | /** 92 | * This structure is a context for ECHO computations: it contains the 93 | * intermediate values and some data from the last entered block. Once 94 | * an ECHO computation has been performed, the context can be reused for 95 | * another computation. This specific structure is used for ECHO-384 96 | * and ECHO-512. 97 | * 98 | * The contents of this structure are private. A running ECHO computation 99 | * can be cloned by copying the context (e.g. with a simple 100 | * memcpy()). 101 | */ 102 | typedef struct { 103 | #ifndef DOXYGEN_IGNORE 104 | unsigned char buf[128]; /* first field, for alignment */ 105 | size_t ptr; 106 | union { 107 | sph_u32 Vs[8][4]; 108 | #if SPH_64 109 | sph_u64 Vb[8][2]; 110 | #endif 111 | } u; 112 | sph_u32 C0, C1, C2, C3; 113 | #endif 114 | } sph_echo_big_context; 115 | 116 | /** 117 | * Type for a ECHO-224 context (identical to the common "small" context). 118 | */ 119 | typedef sph_echo_small_context sph_echo224_context; 120 | 121 | /** 122 | * Type for a ECHO-256 context (identical to the common "small" context). 123 | */ 124 | typedef sph_echo_small_context sph_echo256_context; 125 | 126 | /** 127 | * Type for a ECHO-384 context (identical to the common "big" context). 128 | */ 129 | typedef sph_echo_big_context sph_echo384_context; 130 | 131 | /** 132 | * Type for a ECHO-512 context (identical to the common "big" context). 133 | */ 134 | typedef sph_echo_big_context sph_echo512_context; 135 | 136 | /** 137 | * Initialize an ECHO-224 context. This process performs no memory allocation. 138 | * 139 | * @param cc the ECHO-224 context (pointer to a 140 | * sph_echo224_context) 141 | */ 142 | void sph_echo224_init(void *cc); 143 | 144 | /** 145 | * Process some data bytes. It is acceptable that len is zero 146 | * (in which case this function does nothing). 147 | * 148 | * @param cc the ECHO-224 context 149 | * @param data the input data 150 | * @param len the input data length (in bytes) 151 | */ 152 | void sph_echo224(void *cc, const void *data, size_t len); 153 | 154 | /** 155 | * Terminate the current ECHO-224 computation and output the result into 156 | * the provided buffer. The destination buffer must be wide enough to 157 | * accomodate the result (28 bytes). The context is automatically 158 | * reinitialized. 159 | * 160 | * @param cc the ECHO-224 context 161 | * @param dst the destination buffer 162 | */ 163 | void sph_echo224_close(void *cc, void *dst); 164 | 165 | /** 166 | * Add a few additional bits (0 to 7) to the current computation, then 167 | * terminate it and output the result in the provided buffer, which must 168 | * be wide enough to accomodate the result (28 bytes). If bit number i 169 | * in ub has value 2^i, then the extra bits are those 170 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 171 | * level). The context is automatically reinitialized. 172 | * 173 | * @param cc the ECHO-224 context 174 | * @param ub the extra bits 175 | * @param n the number of extra bits (0 to 7) 176 | * @param dst the destination buffer 177 | */ 178 | void sph_echo224_addbits_and_close( 179 | void *cc, unsigned ub, unsigned n, void *dst); 180 | 181 | /** 182 | * Initialize an ECHO-256 context. This process performs no memory allocation. 183 | * 184 | * @param cc the ECHO-256 context (pointer to a 185 | * sph_echo256_context) 186 | */ 187 | void sph_echo256_init(void *cc); 188 | 189 | /** 190 | * Process some data bytes. It is acceptable that len is zero 191 | * (in which case this function does nothing). 192 | * 193 | * @param cc the ECHO-256 context 194 | * @param data the input data 195 | * @param len the input data length (in bytes) 196 | */ 197 | void sph_echo256(void *cc, const void *data, size_t len); 198 | 199 | /** 200 | * Terminate the current ECHO-256 computation and output the result into 201 | * the provided buffer. The destination buffer must be wide enough to 202 | * accomodate the result (32 bytes). The context is automatically 203 | * reinitialized. 204 | * 205 | * @param cc the ECHO-256 context 206 | * @param dst the destination buffer 207 | */ 208 | void sph_echo256_close(void *cc, void *dst); 209 | 210 | /** 211 | * Add a few additional bits (0 to 7) to the current computation, then 212 | * terminate it and output the result in the provided buffer, which must 213 | * be wide enough to accomodate the result (32 bytes). If bit number i 214 | * in ub has value 2^i, then the extra bits are those 215 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 216 | * level). The context is automatically reinitialized. 217 | * 218 | * @param cc the ECHO-256 context 219 | * @param ub the extra bits 220 | * @param n the number of extra bits (0 to 7) 221 | * @param dst the destination buffer 222 | */ 223 | void sph_echo256_addbits_and_close( 224 | void *cc, unsigned ub, unsigned n, void *dst); 225 | 226 | /** 227 | * Initialize an ECHO-384 context. This process performs no memory allocation. 228 | * 229 | * @param cc the ECHO-384 context (pointer to a 230 | * sph_echo384_context) 231 | */ 232 | void sph_echo384_init(void *cc); 233 | 234 | /** 235 | * Process some data bytes. It is acceptable that len is zero 236 | * (in which case this function does nothing). 237 | * 238 | * @param cc the ECHO-384 context 239 | * @param data the input data 240 | * @param len the input data length (in bytes) 241 | */ 242 | void sph_echo384(void *cc, const void *data, size_t len); 243 | 244 | /** 245 | * Terminate the current ECHO-384 computation and output the result into 246 | * the provided buffer. The destination buffer must be wide enough to 247 | * accomodate the result (48 bytes). The context is automatically 248 | * reinitialized. 249 | * 250 | * @param cc the ECHO-384 context 251 | * @param dst the destination buffer 252 | */ 253 | void sph_echo384_close(void *cc, void *dst); 254 | 255 | /** 256 | * Add a few additional bits (0 to 7) to the current computation, then 257 | * terminate it and output the result in the provided buffer, which must 258 | * be wide enough to accomodate the result (48 bytes). If bit number i 259 | * in ub has value 2^i, then the extra bits are those 260 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 261 | * level). The context is automatically reinitialized. 262 | * 263 | * @param cc the ECHO-384 context 264 | * @param ub the extra bits 265 | * @param n the number of extra bits (0 to 7) 266 | * @param dst the destination buffer 267 | */ 268 | void sph_echo384_addbits_and_close( 269 | void *cc, unsigned ub, unsigned n, void *dst); 270 | 271 | /** 272 | * Initialize an ECHO-512 context. This process performs no memory allocation. 273 | * 274 | * @param cc the ECHO-512 context (pointer to a 275 | * sph_echo512_context) 276 | */ 277 | void sph_echo512_init(void *cc); 278 | 279 | /** 280 | * Process some data bytes. It is acceptable that len is zero 281 | * (in which case this function does nothing). 282 | * 283 | * @param cc the ECHO-512 context 284 | * @param data the input data 285 | * @param len the input data length (in bytes) 286 | */ 287 | void sph_echo512(void *cc, const void *data, size_t len); 288 | 289 | /** 290 | * Terminate the current ECHO-512 computation and output the result into 291 | * the provided buffer. The destination buffer must be wide enough to 292 | * accomodate the result (64 bytes). The context is automatically 293 | * reinitialized. 294 | * 295 | * @param cc the ECHO-512 context 296 | * @param dst the destination buffer 297 | */ 298 | void sph_echo512_close(void *cc, void *dst); 299 | 300 | /** 301 | * Add a few additional bits (0 to 7) to the current computation, then 302 | * terminate it and output the result in the provided buffer, which must 303 | * be wide enough to accomodate the result (64 bytes). If bit number i 304 | * in ub has value 2^i, then the extra bits are those 305 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 306 | * level). The context is automatically reinitialized. 307 | * 308 | * @param cc the ECHO-512 context 309 | * @param ub the extra bits 310 | * @param n the number of extra bits (0 to 7) 311 | * @param dst the destination buffer 312 | */ 313 | void sph_echo512_addbits_and_close( 314 | void *cc, unsigned ub, unsigned n, void *dst); 315 | 316 | #ifdef __cplusplus 317 | } 318 | #endif 319 | 320 | #endif 321 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_bmw.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_bmw.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * BMW interface. BMW (aka "Blue Midnight Wish") is a family of 4 | * functions which differ by their output size; this implementation 5 | * defines BMW for output sizes 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_bmw.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_BMW_H__ 37 | #define SPH_BMW_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for BMW-224. 48 | */ 49 | #define SPH_SIZE_bmw224 224 50 | 51 | /** 52 | * Output size (in bits) for BMW-256. 53 | */ 54 | #define SPH_SIZE_bmw256 256 55 | 56 | #if SPH_64 57 | 58 | /** 59 | * Output size (in bits) for BMW-384. 60 | */ 61 | #define SPH_SIZE_bmw384 384 62 | 63 | /** 64 | * Output size (in bits) for BMW-512. 65 | */ 66 | #define SPH_SIZE_bmw512 512 67 | 68 | #endif 69 | 70 | /** 71 | * This structure is a context for BMW-224 and BMW-256 computations: 72 | * it contains the intermediate values and some data from the last 73 | * entered block. Once a BMW computation has been performed, the 74 | * context can be reused for another computation. 75 | * 76 | * The contents of this structure are private. A running BMW 77 | * computation can be cloned by copying the context (e.g. with a simple 78 | * memcpy()). 79 | */ 80 | typedef struct { 81 | #ifndef DOXYGEN_IGNORE 82 | unsigned char buf[64]; /* first field, for alignment */ 83 | size_t ptr; 84 | sph_u32 H[16]; 85 | #if SPH_64 86 | sph_u64 bit_count; 87 | #else 88 | sph_u32 bit_count_high, bit_count_low; 89 | #endif 90 | #endif 91 | } sph_bmw_small_context; 92 | 93 | /** 94 | * This structure is a context for BMW-224 computations. It is 95 | * identical to the common sph_bmw_small_context. 96 | */ 97 | typedef sph_bmw_small_context sph_bmw224_context; 98 | 99 | /** 100 | * This structure is a context for BMW-256 computations. It is 101 | * identical to the common sph_bmw_small_context. 102 | */ 103 | typedef sph_bmw_small_context sph_bmw256_context; 104 | 105 | #if SPH_64 106 | 107 | /** 108 | * This structure is a context for BMW-384 and BMW-512 computations: 109 | * it contains the intermediate values and some data from the last 110 | * entered block. Once a BMW computation has been performed, the 111 | * context can be reused for another computation. 112 | * 113 | * The contents of this structure are private. A running BMW 114 | * computation can be cloned by copying the context (e.g. with a simple 115 | * memcpy()). 116 | */ 117 | typedef struct { 118 | #ifndef DOXYGEN_IGNORE 119 | unsigned char buf[128]; /* first field, for alignment */ 120 | size_t ptr; 121 | sph_u64 H[16]; 122 | sph_u64 bit_count; 123 | #endif 124 | } sph_bmw_big_context; 125 | 126 | /** 127 | * This structure is a context for BMW-384 computations. It is 128 | * identical to the common sph_bmw_small_context. 129 | */ 130 | typedef sph_bmw_big_context sph_bmw384_context; 131 | 132 | /** 133 | * This structure is a context for BMW-512 computations. It is 134 | * identical to the common sph_bmw_small_context. 135 | */ 136 | typedef sph_bmw_big_context sph_bmw512_context; 137 | 138 | #endif 139 | 140 | /** 141 | * Initialize a BMW-224 context. This process performs no memory allocation. 142 | * 143 | * @param cc the BMW-224 context (pointer to a 144 | * sph_bmw224_context) 145 | */ 146 | void sph_bmw224_init(void *cc); 147 | 148 | /** 149 | * Process some data bytes. It is acceptable that len is zero 150 | * (in which case this function does nothing). 151 | * 152 | * @param cc the BMW-224 context 153 | * @param data the input data 154 | * @param len the input data length (in bytes) 155 | */ 156 | void sph_bmw224(void *cc, const void *data, size_t len); 157 | 158 | /** 159 | * Terminate the current BMW-224 computation and output the result into 160 | * the provided buffer. The destination buffer must be wide enough to 161 | * accomodate the result (28 bytes). The context is automatically 162 | * reinitialized. 163 | * 164 | * @param cc the BMW-224 context 165 | * @param dst the destination buffer 166 | */ 167 | void sph_bmw224_close(void *cc, void *dst); 168 | 169 | /** 170 | * Add a few additional bits (0 to 7) to the current computation, then 171 | * terminate it and output the result in the provided buffer, which must 172 | * be wide enough to accomodate the result (28 bytes). If bit number i 173 | * in ub has value 2^i, then the extra bits are those 174 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 175 | * level). The context is automatically reinitialized. 176 | * 177 | * @param cc the BMW-224 context 178 | * @param ub the extra bits 179 | * @param n the number of extra bits (0 to 7) 180 | * @param dst the destination buffer 181 | */ 182 | void sph_bmw224_addbits_and_close( 183 | void *cc, unsigned ub, unsigned n, void *dst); 184 | 185 | /** 186 | * Initialize a BMW-256 context. This process performs no memory allocation. 187 | * 188 | * @param cc the BMW-256 context (pointer to a 189 | * sph_bmw256_context) 190 | */ 191 | void sph_bmw256_init(void *cc); 192 | 193 | /** 194 | * Process some data bytes. It is acceptable that len is zero 195 | * (in which case this function does nothing). 196 | * 197 | * @param cc the BMW-256 context 198 | * @param data the input data 199 | * @param len the input data length (in bytes) 200 | */ 201 | void sph_bmw256(void *cc, const void *data, size_t len); 202 | 203 | /** 204 | * Terminate the current BMW-256 computation and output the result into 205 | * the provided buffer. The destination buffer must be wide enough to 206 | * accomodate the result (32 bytes). The context is automatically 207 | * reinitialized. 208 | * 209 | * @param cc the BMW-256 context 210 | * @param dst the destination buffer 211 | */ 212 | void sph_bmw256_close(void *cc, void *dst); 213 | 214 | /** 215 | * Add a few additional bits (0 to 7) to the current computation, then 216 | * terminate it and output the result in the provided buffer, which must 217 | * be wide enough to accomodate the result (32 bytes). If bit number i 218 | * in ub has value 2^i, then the extra bits are those 219 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 220 | * level). The context is automatically reinitialized. 221 | * 222 | * @param cc the BMW-256 context 223 | * @param ub the extra bits 224 | * @param n the number of extra bits (0 to 7) 225 | * @param dst the destination buffer 226 | */ 227 | void sph_bmw256_addbits_and_close( 228 | void *cc, unsigned ub, unsigned n, void *dst); 229 | 230 | #if SPH_64 231 | 232 | /** 233 | * Initialize a BMW-384 context. This process performs no memory allocation. 234 | * 235 | * @param cc the BMW-384 context (pointer to a 236 | * sph_bmw384_context) 237 | */ 238 | void sph_bmw384_init(void *cc); 239 | 240 | /** 241 | * Process some data bytes. It is acceptable that len is zero 242 | * (in which case this function does nothing). 243 | * 244 | * @param cc the BMW-384 context 245 | * @param data the input data 246 | * @param len the input data length (in bytes) 247 | */ 248 | void sph_bmw384(void *cc, const void *data, size_t len); 249 | 250 | /** 251 | * Terminate the current BMW-384 computation and output the result into 252 | * the provided buffer. The destination buffer must be wide enough to 253 | * accomodate the result (48 bytes). The context is automatically 254 | * reinitialized. 255 | * 256 | * @param cc the BMW-384 context 257 | * @param dst the destination buffer 258 | */ 259 | void sph_bmw384_close(void *cc, void *dst); 260 | 261 | /** 262 | * Add a few additional bits (0 to 7) to the current computation, then 263 | * terminate it and output the result in the provided buffer, which must 264 | * be wide enough to accomodate the result (48 bytes). If bit number i 265 | * in ub has value 2^i, then the extra bits are those 266 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 267 | * level). The context is automatically reinitialized. 268 | * 269 | * @param cc the BMW-384 context 270 | * @param ub the extra bits 271 | * @param n the number of extra bits (0 to 7) 272 | * @param dst the destination buffer 273 | */ 274 | void sph_bmw384_addbits_and_close( 275 | void *cc, unsigned ub, unsigned n, void *dst); 276 | 277 | /** 278 | * Initialize a BMW-512 context. This process performs no memory allocation. 279 | * 280 | * @param cc the BMW-512 context (pointer to a 281 | * sph_bmw512_context) 282 | */ 283 | void sph_bmw512_init(void *cc); 284 | 285 | /** 286 | * Process some data bytes. It is acceptable that len is zero 287 | * (in which case this function does nothing). 288 | * 289 | * @param cc the BMW-512 context 290 | * @param data the input data 291 | * @param len the input data length (in bytes) 292 | */ 293 | void sph_bmw512(void *cc, const void *data, size_t len); 294 | 295 | /** 296 | * Terminate the current BMW-512 computation and output the result into 297 | * the provided buffer. The destination buffer must be wide enough to 298 | * accomodate the result (64 bytes). The context is automatically 299 | * reinitialized. 300 | * 301 | * @param cc the BMW-512 context 302 | * @param dst the destination buffer 303 | */ 304 | void sph_bmw512_close(void *cc, void *dst); 305 | 306 | /** 307 | * Add a few additional bits (0 to 7) to the current computation, then 308 | * terminate it and output the result in the provided buffer, which must 309 | * be wide enough to accomodate the result (64 bytes). If bit number i 310 | * in ub has value 2^i, then the extra bits are those 311 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 312 | * level). The context is automatically reinitialized. 313 | * 314 | * @param cc the BMW-512 context 315 | * @param ub the extra bits 316 | * @param n the number of extra bits (0 to 7) 317 | * @param dst the destination buffer 318 | */ 319 | void sph_bmw512_addbits_and_close( 320 | void *cc, unsigned ub, unsigned n, void *dst); 321 | 322 | #endif 323 | 324 | #ifdef __cplusplus 325 | } 326 | #endif 327 | 328 | #endif 329 | -------------------------------------------------------------------------------- /mixhash/sha3/sph_hamsi.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_hamsi.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * Hamsi interface. This code implements Hamsi with the recommended 4 | * parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits. 5 | * 6 | * ==========================(LICENSE BEGIN)============================ 7 | * 8 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining 11 | * a copy of this software and associated documentation files (the 12 | * "Software"), to deal in the Software without restriction, including 13 | * without limitation the rights to use, copy, modify, merge, publish, 14 | * distribute, sublicense, and/or sell copies of the Software, and to 15 | * permit persons to whom the Software is furnished to do so, subject to 16 | * the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be 19 | * included in all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * ===========================(LICENSE END)============================= 30 | * 31 | * @file sph_hamsi.h 32 | * @author Thomas Pornin 33 | */ 34 | 35 | #ifndef SPH_HAMSI_H__ 36 | #define SPH_HAMSI_H__ 37 | 38 | #include 39 | #include "sph_types.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C"{ 43 | #endif 44 | 45 | /** 46 | * Output size (in bits) for Hamsi-224. 47 | */ 48 | #define SPH_SIZE_hamsi224 224 49 | 50 | /** 51 | * Output size (in bits) for Hamsi-256. 52 | */ 53 | #define SPH_SIZE_hamsi256 256 54 | 55 | /** 56 | * Output size (in bits) for Hamsi-384. 57 | */ 58 | #define SPH_SIZE_hamsi384 384 59 | 60 | /** 61 | * Output size (in bits) for Hamsi-512. 62 | */ 63 | #define SPH_SIZE_hamsi512 512 64 | 65 | /** 66 | * This structure is a context for Hamsi-224 and Hamsi-256 computations: 67 | * it contains the intermediate values and some data from the last 68 | * entered block. Once a Hamsi computation has been performed, the 69 | * context can be reused for another computation. 70 | * 71 | * The contents of this structure are private. A running Hamsi 72 | * computation can be cloned by copying the context (e.g. with a simple 73 | * memcpy()). 74 | */ 75 | typedef struct { 76 | #ifndef DOXYGEN_IGNORE 77 | unsigned char partial[4]; 78 | size_t partial_len; 79 | sph_u32 h[8]; 80 | #if SPH_64 81 | sph_u64 count; 82 | #else 83 | sph_u32 count_high, count_low; 84 | #endif 85 | #endif 86 | } sph_hamsi_small_context; 87 | 88 | /** 89 | * This structure is a context for Hamsi-224 computations. It is 90 | * identical to the common sph_hamsi_small_context. 91 | */ 92 | typedef sph_hamsi_small_context sph_hamsi224_context; 93 | 94 | /** 95 | * This structure is a context for Hamsi-256 computations. It is 96 | * identical to the common sph_hamsi_small_context. 97 | */ 98 | typedef sph_hamsi_small_context sph_hamsi256_context; 99 | 100 | /** 101 | * This structure is a context for Hamsi-384 and Hamsi-512 computations: 102 | * it contains the intermediate values and some data from the last 103 | * entered block. Once a Hamsi computation has been performed, the 104 | * context can be reused for another computation. 105 | * 106 | * The contents of this structure are private. A running Hamsi 107 | * computation can be cloned by copying the context (e.g. with a simple 108 | * memcpy()). 109 | */ 110 | typedef struct { 111 | #ifndef DOXYGEN_IGNORE 112 | unsigned char partial[8]; 113 | size_t partial_len; 114 | sph_u32 h[16]; 115 | #if SPH_64 116 | sph_u64 count; 117 | #else 118 | sph_u32 count_high, count_low; 119 | #endif 120 | #endif 121 | } sph_hamsi_big_context; 122 | 123 | /** 124 | * This structure is a context for Hamsi-384 computations. It is 125 | * identical to the common sph_hamsi_small_context. 126 | */ 127 | typedef sph_hamsi_big_context sph_hamsi384_context; 128 | 129 | /** 130 | * This structure is a context for Hamsi-512 computations. It is 131 | * identical to the common sph_hamsi_small_context. 132 | */ 133 | typedef sph_hamsi_big_context sph_hamsi512_context; 134 | 135 | /** 136 | * Initialize a Hamsi-224 context. This process performs no memory allocation. 137 | * 138 | * @param cc the Hamsi-224 context (pointer to a 139 | * sph_hamsi224_context) 140 | */ 141 | void sph_hamsi224_init(void *cc); 142 | 143 | /** 144 | * Process some data bytes. It is acceptable that len is zero 145 | * (in which case this function does nothing). 146 | * 147 | * @param cc the Hamsi-224 context 148 | * @param data the input data 149 | * @param len the input data length (in bytes) 150 | */ 151 | void sph_hamsi224(void *cc, const void *data, size_t len); 152 | 153 | /** 154 | * Terminate the current Hamsi-224 computation and output the result into 155 | * the provided buffer. The destination buffer must be wide enough to 156 | * accomodate the result (28 bytes). The context is automatically 157 | * reinitialized. 158 | * 159 | * @param cc the Hamsi-224 context 160 | * @param dst the destination buffer 161 | */ 162 | void sph_hamsi224_close(void *cc, void *dst); 163 | 164 | /** 165 | * Add a few additional bits (0 to 7) to the current computation, then 166 | * terminate it and output the result in the provided buffer, which must 167 | * be wide enough to accomodate the result (28 bytes). If bit number i 168 | * in ub has value 2^i, then the extra bits are those 169 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 170 | * level). The context is automatically reinitialized. 171 | * 172 | * @param cc the Hamsi-224 context 173 | * @param ub the extra bits 174 | * @param n the number of extra bits (0 to 7) 175 | * @param dst the destination buffer 176 | */ 177 | void sph_hamsi224_addbits_and_close( 178 | void *cc, unsigned ub, unsigned n, void *dst); 179 | 180 | /** 181 | * Initialize a Hamsi-256 context. This process performs no memory allocation. 182 | * 183 | * @param cc the Hamsi-256 context (pointer to a 184 | * sph_hamsi256_context) 185 | */ 186 | void sph_hamsi256_init(void *cc); 187 | 188 | /** 189 | * Process some data bytes. It is acceptable that len is zero 190 | * (in which case this function does nothing). 191 | * 192 | * @param cc the Hamsi-256 context 193 | * @param data the input data 194 | * @param len the input data length (in bytes) 195 | */ 196 | void sph_hamsi256(void *cc, const void *data, size_t len); 197 | 198 | /** 199 | * Terminate the current Hamsi-256 computation and output the result into 200 | * the provided buffer. The destination buffer must be wide enough to 201 | * accomodate the result (32 bytes). The context is automatically 202 | * reinitialized. 203 | * 204 | * @param cc the Hamsi-256 context 205 | * @param dst the destination buffer 206 | */ 207 | void sph_hamsi256_close(void *cc, void *dst); 208 | 209 | /** 210 | * Add a few additional bits (0 to 7) to the current computation, then 211 | * terminate it and output the result in the provided buffer, which must 212 | * be wide enough to accomodate the result (32 bytes). If bit number i 213 | * in ub has value 2^i, then the extra bits are those 214 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 215 | * level). The context is automatically reinitialized. 216 | * 217 | * @param cc the Hamsi-256 context 218 | * @param ub the extra bits 219 | * @param n the number of extra bits (0 to 7) 220 | * @param dst the destination buffer 221 | */ 222 | void sph_hamsi256_addbits_and_close( 223 | void *cc, unsigned ub, unsigned n, void *dst); 224 | 225 | /** 226 | * Initialize a Hamsi-384 context. This process performs no memory allocation. 227 | * 228 | * @param cc the Hamsi-384 context (pointer to a 229 | * sph_hamsi384_context) 230 | */ 231 | void sph_hamsi384_init(void *cc); 232 | 233 | /** 234 | * Process some data bytes. It is acceptable that len is zero 235 | * (in which case this function does nothing). 236 | * 237 | * @param cc the Hamsi-384 context 238 | * @param data the input data 239 | * @param len the input data length (in bytes) 240 | */ 241 | void sph_hamsi384(void *cc, const void *data, size_t len); 242 | 243 | /** 244 | * Terminate the current Hamsi-384 computation and output the result into 245 | * the provided buffer. The destination buffer must be wide enough to 246 | * accomodate the result (48 bytes). The context is automatically 247 | * reinitialized. 248 | * 249 | * @param cc the Hamsi-384 context 250 | * @param dst the destination buffer 251 | */ 252 | void sph_hamsi384_close(void *cc, void *dst); 253 | 254 | /** 255 | * Add a few additional bits (0 to 7) to the current computation, then 256 | * terminate it and output the result in the provided buffer, which must 257 | * be wide enough to accomodate the result (48 bytes). If bit number i 258 | * in ub has value 2^i, then the extra bits are those 259 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 260 | * level). The context is automatically reinitialized. 261 | * 262 | * @param cc the Hamsi-384 context 263 | * @param ub the extra bits 264 | * @param n the number of extra bits (0 to 7) 265 | * @param dst the destination buffer 266 | */ 267 | void sph_hamsi384_addbits_and_close( 268 | void *cc, unsigned ub, unsigned n, void *dst); 269 | 270 | /** 271 | * Initialize a Hamsi-512 context. This process performs no memory allocation. 272 | * 273 | * @param cc the Hamsi-512 context (pointer to a 274 | * sph_hamsi512_context) 275 | */ 276 | void sph_hamsi512_init(void *cc); 277 | 278 | /** 279 | * Process some data bytes. It is acceptable that len is zero 280 | * (in which case this function does nothing). 281 | * 282 | * @param cc the Hamsi-512 context 283 | * @param data the input data 284 | * @param len the input data length (in bytes) 285 | */ 286 | void sph_hamsi512(void *cc, const void *data, size_t len); 287 | 288 | /** 289 | * Terminate the current Hamsi-512 computation and output the result into 290 | * the provided buffer. The destination buffer must be wide enough to 291 | * accomodate the result (64 bytes). The context is automatically 292 | * reinitialized. 293 | * 294 | * @param cc the Hamsi-512 context 295 | * @param dst the destination buffer 296 | */ 297 | void sph_hamsi512_close(void *cc, void *dst); 298 | 299 | /** 300 | * Add a few additional bits (0 to 7) to the current computation, then 301 | * terminate it and output the result in the provided buffer, which must 302 | * be wide enough to accomodate the result (64 bytes). If bit number i 303 | * in ub has value 2^i, then the extra bits are those 304 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 305 | * level). The context is automatically reinitialized. 306 | * 307 | * @param cc the Hamsi-512 context 308 | * @param ub the extra bits 309 | * @param n the number of extra bits (0 to 7) 310 | * @param dst the destination buffer 311 | */ 312 | void sph_hamsi512_addbits_and_close( 313 | void *cc, unsigned ub, unsigned n, void *dst); 314 | 315 | 316 | 317 | #ifdef __cplusplus 318 | } 319 | #endif 320 | 321 | #endif 322 | 323 | -------------------------------------------------------------------------------- /mixhash/sha3/md_helper.c: -------------------------------------------------------------------------------- 1 | /* $Id: md_helper.c 216 2010-06-08 09:46:57Z tp $ */ 2 | /* 3 | * This file contains some functions which implement the external data 4 | * handling and padding for Merkle-Damgard hash functions which follow 5 | * the conventions set out by MD4 (little-endian) or SHA-1 (big-endian). 6 | * 7 | * API: this file is meant to be included, not compiled as a stand-alone 8 | * file. Some macros must be defined: 9 | * RFUN name for the round function 10 | * HASH "short name" for the hash function 11 | * BE32 defined for big-endian, 32-bit based (e.g. SHA-1) 12 | * LE32 defined for little-endian, 32-bit based (e.g. MD5) 13 | * BE64 defined for big-endian, 64-bit based (e.g. SHA-512) 14 | * LE64 defined for little-endian, 64-bit based (no example yet) 15 | * PW01 if defined, append 0x01 instead of 0x80 (for Tiger) 16 | * BLEN if defined, length of a message block (in bytes) 17 | * PLW1 if defined, length is defined on one 64-bit word only (for Tiger) 18 | * PLW4 if defined, length is defined on four 64-bit words (for WHIRLPOOL) 19 | * SVAL if defined, reference to the context state information 20 | * 21 | * BLEN is used when a message block is not 16 (32-bit or 64-bit) words: 22 | * this is used for instance for Tiger, which works on 64-bit words but 23 | * uses 512-bit message blocks (eight 64-bit words). PLW1 and PLW4 are 24 | * ignored if 32-bit words are used; if 64-bit words are used and PLW1 is 25 | * set, then only one word (64 bits) will be used to encode the input 26 | * message length (in bits), otherwise two words will be used (as in 27 | * SHA-384 and SHA-512). If 64-bit words are used and PLW4 is defined (but 28 | * not PLW1), four 64-bit words will be used to encode the message length 29 | * (in bits). Note that regardless of those settings, only 64-bit message 30 | * lengths are supported (in bits): messages longer than 2 Exabytes will be 31 | * improperly hashed (this is unlikely to happen soon: 2 Exabytes is about 32 | * 2 millions Terabytes, which is huge). 33 | * 34 | * If CLOSE_ONLY is defined, then this file defines only the sph_XXX_close() 35 | * function. This is used for Tiger2, which is identical to Tiger except 36 | * when it comes to the padding (Tiger2 uses the standard 0x80 byte instead 37 | * of the 0x01 from original Tiger). 38 | * 39 | * The RFUN function is invoked with two arguments, the first pointing to 40 | * aligned data (as a "const void *"), the second being state information 41 | * from the context structure. By default, this state information is the 42 | * "val" field from the context, and this field is assumed to be an array 43 | * of words ("sph_u32" or "sph_u64", depending on BE32/LE32/BE64/LE64). 44 | * from the context structure. The "val" field can have any type, except 45 | * for the output encoding which assumes that it is an array of "sph_u32" 46 | * values. By defining NO_OUTPUT, this last step is deactivated; the 47 | * includer code is then responsible for writing out the hash result. When 48 | * NO_OUTPUT is defined, the third parameter to the "close()" function is 49 | * ignored. 50 | * 51 | * ==========================(LICENSE BEGIN)============================ 52 | * 53 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 54 | * 55 | * Permission is hereby granted, free of charge, to any person obtaining 56 | * a copy of this software and associated documentation files (the 57 | * "Software"), to deal in the Software without restriction, including 58 | * without limitation the rights to use, copy, modify, merge, publish, 59 | * distribute, sublicense, and/or sell copies of the Software, and to 60 | * permit persons to whom the Software is furnished to do so, subject to 61 | * the following conditions: 62 | * 63 | * The above copyright notice and this permission notice shall be 64 | * included in all copies or substantial portions of the Software. 65 | * 66 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 67 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 68 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 69 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 70 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 71 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 72 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 73 | * 74 | * ===========================(LICENSE END)============================= 75 | * 76 | * @author Thomas Pornin 77 | */ 78 | 79 | 80 | #ifdef _MSC_VER 81 | #pragma warning (disable: 4146) 82 | #endif 83 | 84 | #undef SPH_XCAT 85 | #define SPH_XCAT(a, b) SPH_XCAT_(a, b) 86 | #undef SPH_XCAT_ 87 | #define SPH_XCAT_(a, b) a ## b 88 | 89 | #undef SPH_BLEN 90 | #undef SPH_WLEN 91 | #if defined BE64 || defined LE64 92 | #define SPH_BLEN 128U 93 | #define SPH_WLEN 8U 94 | #else 95 | #define SPH_BLEN 64U 96 | #define SPH_WLEN 4U 97 | #endif 98 | 99 | #ifdef BLEN 100 | #undef SPH_BLEN 101 | #define SPH_BLEN BLEN 102 | #endif 103 | 104 | #undef SPH_MAXPAD 105 | #if defined PLW1 106 | #define SPH_MAXPAD (SPH_BLEN - SPH_WLEN) 107 | #elif defined PLW4 108 | #define SPH_MAXPAD (SPH_BLEN - (SPH_WLEN << 2)) 109 | #else 110 | #define SPH_MAXPAD (SPH_BLEN - (SPH_WLEN << 1)) 111 | #endif 112 | 113 | #undef SPH_VAL 114 | #undef SPH_NO_OUTPUT 115 | #ifdef SVAL 116 | #define SPH_VAL SVAL 117 | #define SPH_NO_OUTPUT 1 118 | #else 119 | #define SPH_VAL sc->val 120 | #endif 121 | 122 | #ifndef CLOSE_ONLY 123 | 124 | #ifdef SPH_UPTR 125 | static void 126 | SPH_XCAT(HASH, _short)(void *cc, const void *data, size_t len) 127 | #else 128 | void 129 | SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len) 130 | #endif 131 | { 132 | SPH_XCAT(sph_, SPH_XCAT(HASH, _context)) *sc; 133 | unsigned current; 134 | 135 | sc = cc; 136 | #if SPH_64 137 | current = (unsigned)sc->count & (SPH_BLEN - 1U); 138 | #else 139 | current = (unsigned)sc->count_low & (SPH_BLEN - 1U); 140 | #endif 141 | while (len > 0) { 142 | unsigned clen; 143 | #if !SPH_64 144 | sph_u32 clow, clow2; 145 | #endif 146 | 147 | clen = SPH_BLEN - current; 148 | if (clen > len) 149 | clen = len; 150 | memcpy(sc->buf + current, data, clen); 151 | data = (const unsigned char *)data + clen; 152 | current += clen; 153 | len -= clen; 154 | if (current == SPH_BLEN) { 155 | RFUN(sc->buf, SPH_VAL); 156 | current = 0; 157 | } 158 | #if SPH_64 159 | sc->count += clen; 160 | #else 161 | clow = sc->count_low; 162 | clow2 = SPH_T32(clow + clen); 163 | sc->count_low = clow2; 164 | if (clow2 < clow) 165 | sc->count_high ++; 166 | #endif 167 | } 168 | } 169 | 170 | #ifdef SPH_UPTR 171 | void 172 | SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len) 173 | { 174 | SPH_XCAT(sph_, SPH_XCAT(HASH, _context)) *sc; 175 | unsigned current; 176 | size_t orig_len; 177 | #if !SPH_64 178 | sph_u32 clow, clow2; 179 | #endif 180 | 181 | if (len < (2 * SPH_BLEN)) { 182 | SPH_XCAT(HASH, _short)(cc, data, len); 183 | return; 184 | } 185 | sc = cc; 186 | #if SPH_64 187 | current = (unsigned)sc->count & (SPH_BLEN - 1U); 188 | #else 189 | current = (unsigned)sc->count_low & (SPH_BLEN - 1U); 190 | #endif 191 | if (current > 0) { 192 | unsigned t; 193 | 194 | t = SPH_BLEN - current; 195 | SPH_XCAT(HASH, _short)(cc, data, t); 196 | data = (const unsigned char *)data + t; 197 | len -= t; 198 | } 199 | #if !SPH_UNALIGNED 200 | if (((SPH_UPTR)data & (SPH_WLEN - 1U)) != 0) { 201 | SPH_XCAT(HASH, _short)(cc, data, len); 202 | return; 203 | } 204 | #endif 205 | orig_len = len; 206 | while (len >= SPH_BLEN) { 207 | RFUN(data, SPH_VAL); 208 | len -= SPH_BLEN; 209 | data = (const unsigned char *)data + SPH_BLEN; 210 | } 211 | if (len > 0) 212 | memcpy(sc->buf, data, len); 213 | #if SPH_64 214 | sc->count += (sph_u64)orig_len; 215 | #else 216 | clow = sc->count_low; 217 | clow2 = SPH_T32(clow + orig_len); 218 | sc->count_low = clow2; 219 | if (clow2 < clow) 220 | sc->count_high ++; 221 | /* 222 | * This code handles the improbable situation where "size_t" is 223 | * greater than 32 bits, and yet we do not have a 64-bit type. 224 | */ 225 | orig_len >>= 12; 226 | orig_len >>= 10; 227 | orig_len >>= 10; 228 | sc->count_high += orig_len; 229 | #endif 230 | } 231 | #endif 232 | 233 | #endif 234 | 235 | /* 236 | * Perform padding and produce result. The context is NOT reinitialized 237 | * by this function. 238 | */ 239 | static void 240 | SPH_XCAT(HASH, _addbits_and_close)(void *cc, 241 | unsigned ub, unsigned n, void *dst, unsigned rnum) 242 | { 243 | SPH_XCAT(sph_, SPH_XCAT(HASH, _context)) *sc; 244 | unsigned current, u; 245 | #if !SPH_64 246 | sph_u32 low, high; 247 | #endif 248 | 249 | sc = cc; 250 | #if SPH_64 251 | current = (unsigned)sc->count & (SPH_BLEN - 1U); 252 | #else 253 | current = (unsigned)sc->count_low & (SPH_BLEN - 1U); 254 | #endif 255 | #ifdef PW01 256 | sc->buf[current ++] = (0x100 | (ub & 0xFF)) >> (8 - n); 257 | #else 258 | { 259 | unsigned z; 260 | 261 | z = 0x80 >> n; 262 | sc->buf[current ++] = ((ub & -z) | z) & 0xFF; 263 | } 264 | #endif 265 | if (current > SPH_MAXPAD) { 266 | memset(sc->buf + current, 0, SPH_BLEN - current); 267 | RFUN(sc->buf, SPH_VAL); 268 | memset(sc->buf, 0, SPH_MAXPAD); 269 | } else { 270 | memset(sc->buf + current, 0, SPH_MAXPAD - current); 271 | } 272 | #if defined BE64 273 | #if defined PLW1 274 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD, 275 | SPH_T64(sc->count << 3) + (sph_u64)n); 276 | #elif defined PLW4 277 | memset(sc->buf + SPH_MAXPAD, 0, 2 * SPH_WLEN); 278 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD + 2 * SPH_WLEN, 279 | sc->count >> 61); 280 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD + 3 * SPH_WLEN, 281 | SPH_T64(sc->count << 3) + (sph_u64)n); 282 | #else 283 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD, sc->count >> 61); 284 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD + SPH_WLEN, 285 | SPH_T64(sc->count << 3) + (sph_u64)n); 286 | #endif 287 | #elif defined LE64 288 | #if defined PLW1 289 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD, 290 | SPH_T64(sc->count << 3) + (sph_u64)n); 291 | #elif defined PLW1 292 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD, 293 | SPH_T64(sc->count << 3) + (sph_u64)n); 294 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD + SPH_WLEN, sc->count >> 61); 295 | memset(sc->buf + SPH_MAXPAD + 2 * SPH_WLEN, 0, 2 * SPH_WLEN); 296 | #else 297 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD, 298 | SPH_T64(sc->count << 3) + (sph_u64)n); 299 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD + SPH_WLEN, sc->count >> 61); 300 | #endif 301 | #else 302 | #if SPH_64 303 | #ifdef BE32 304 | sph_enc64be_aligned(sc->buf + SPH_MAXPAD, 305 | SPH_T64(sc->count << 3) + (sph_u64)n); 306 | #else 307 | sph_enc64le_aligned(sc->buf + SPH_MAXPAD, 308 | SPH_T64(sc->count << 3) + (sph_u64)n); 309 | #endif 310 | #else 311 | low = sc->count_low; 312 | high = SPH_T32((sc->count_high << 3) | (low >> 29)); 313 | low = SPH_T32(low << 3) + (sph_u32)n; 314 | #ifdef BE32 315 | sph_enc32be(sc->buf + SPH_MAXPAD, high); 316 | sph_enc32be(sc->buf + SPH_MAXPAD + SPH_WLEN, low); 317 | #else 318 | sph_enc32le(sc->buf + SPH_MAXPAD, low); 319 | sph_enc32le(sc->buf + SPH_MAXPAD + SPH_WLEN, high); 320 | #endif 321 | #endif 322 | #endif 323 | RFUN(sc->buf, SPH_VAL); 324 | #ifdef SPH_NO_OUTPUT 325 | (void)dst; 326 | (void)rnum; 327 | (void)u; 328 | #else 329 | for (u = 0; u < rnum; u ++) { 330 | #if defined BE64 331 | sph_enc64be((unsigned char *)dst + 8 * u, sc->val[u]); 332 | #elif defined LE64 333 | sph_enc64le((unsigned char *)dst + 8 * u, sc->val[u]); 334 | #elif defined BE32 335 | sph_enc32be((unsigned char *)dst + 4 * u, sc->val[u]); 336 | #else 337 | sph_enc32le((unsigned char *)dst + 4 * u, sc->val[u]); 338 | #endif 339 | } 340 | #endif 341 | } 342 | 343 | static void 344 | SPH_XCAT(HASH, _close)(void *cc, void *dst, unsigned rnum) 345 | { 346 | SPH_XCAT(HASH, _addbits_and_close)(cc, 0, 0, dst, rnum); 347 | } -------------------------------------------------------------------------------- /mixhash/sha3/sph_shavite.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_shavite.h 208 2010-06-02 20:33:00Z tp $ */ 2 | /** 3 | * SHAvite-3 interface. This code implements SHAvite-3 with the 4 | * recommended parameters for SHA-3, with outputs of 224, 256, 384 and 5 | * 512 bits. In the following, we call the function "SHAvite" (without 6 | * the "-3" suffix), thus "SHAvite-224" is "SHAvite-3 with a 224-bit 7 | * output". 8 | * 9 | * ==========================(LICENSE BEGIN)============================ 10 | * 11 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining 14 | * a copy of this software and associated documentation files (the 15 | * "Software"), to deal in the Software without restriction, including 16 | * without limitation the rights to use, copy, modify, merge, publish, 17 | * distribute, sublicense, and/or sell copies of the Software, and to 18 | * permit persons to whom the Software is furnished to do so, subject to 19 | * the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be 22 | * included in all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 28 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 29 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 30 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | * 32 | * ===========================(LICENSE END)============================= 33 | * 34 | * @file sph_shavite.h 35 | * @author Thomas Pornin 36 | */ 37 | 38 | #ifndef SPH_SHAVITE_H__ 39 | #define SPH_SHAVITE_H__ 40 | 41 | #include 42 | #include "sph_types.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C"{ 46 | #endif 47 | 48 | /** 49 | * Output size (in bits) for SHAvite-224. 50 | */ 51 | #define SPH_SIZE_shavite224 224 52 | 53 | /** 54 | * Output size (in bits) for SHAvite-256. 55 | */ 56 | #define SPH_SIZE_shavite256 256 57 | 58 | /** 59 | * Output size (in bits) for SHAvite-384. 60 | */ 61 | #define SPH_SIZE_shavite384 384 62 | 63 | /** 64 | * Output size (in bits) for SHAvite-512. 65 | */ 66 | #define SPH_SIZE_shavite512 512 67 | 68 | /** 69 | * This structure is a context for SHAvite-224 and SHAvite-256 computations: 70 | * it contains the intermediate values and some data from the last 71 | * entered block. Once a SHAvite computation has been performed, the 72 | * context can be reused for another computation. 73 | * 74 | * The contents of this structure are private. A running SHAvite 75 | * computation can be cloned by copying the context (e.g. with a simple 76 | * memcpy()). 77 | */ 78 | typedef struct { 79 | #ifndef DOXYGEN_IGNORE 80 | unsigned char buf[64]; /* first field, for alignment */ 81 | size_t ptr; 82 | sph_u32 h[8]; 83 | sph_u32 count0, count1; 84 | #endif 85 | } sph_shavite_small_context; 86 | 87 | /** 88 | * This structure is a context for SHAvite-224 computations. It is 89 | * identical to the common sph_shavite_small_context. 90 | */ 91 | typedef sph_shavite_small_context sph_shavite224_context; 92 | 93 | /** 94 | * This structure is a context for SHAvite-256 computations. It is 95 | * identical to the common sph_shavite_small_context. 96 | */ 97 | typedef sph_shavite_small_context sph_shavite256_context; 98 | 99 | /** 100 | * This structure is a context for SHAvite-384 and SHAvite-512 computations: 101 | * it contains the intermediate values and some data from the last 102 | * entered block. Once a SHAvite computation has been performed, the 103 | * context can be reused for another computation. 104 | * 105 | * The contents of this structure are private. A running SHAvite 106 | * computation can be cloned by copying the context (e.g. with a simple 107 | * memcpy()). 108 | */ 109 | typedef struct { 110 | #ifndef DOXYGEN_IGNORE 111 | unsigned char buf[128]; /* first field, for alignment */ 112 | size_t ptr; 113 | sph_u32 h[16]; 114 | sph_u32 count0, count1, count2, count3; 115 | #endif 116 | } sph_shavite_big_context; 117 | 118 | /** 119 | * This structure is a context for SHAvite-384 computations. It is 120 | * identical to the common sph_shavite_small_context. 121 | */ 122 | typedef sph_shavite_big_context sph_shavite384_context; 123 | 124 | /** 125 | * This structure is a context for SHAvite-512 computations. It is 126 | * identical to the common sph_shavite_small_context. 127 | */ 128 | typedef sph_shavite_big_context sph_shavite512_context; 129 | 130 | /** 131 | * Initialize a SHAvite-224 context. This process performs no memory allocation. 132 | * 133 | * @param cc the SHAvite-224 context (pointer to a 134 | * sph_shavite224_context) 135 | */ 136 | void sph_shavite224_init(void *cc); 137 | 138 | /** 139 | * Process some data bytes. It is acceptable that len is zero 140 | * (in which case this function does nothing). 141 | * 142 | * @param cc the SHAvite-224 context 143 | * @param data the input data 144 | * @param len the input data length (in bytes) 145 | */ 146 | void sph_shavite224(void *cc, const void *data, size_t len); 147 | 148 | /** 149 | * Terminate the current SHAvite-224 computation and output the result into 150 | * the provided buffer. The destination buffer must be wide enough to 151 | * accomodate the result (28 bytes). The context is automatically 152 | * reinitialized. 153 | * 154 | * @param cc the SHAvite-224 context 155 | * @param dst the destination buffer 156 | */ 157 | void sph_shavite224_close(void *cc, void *dst); 158 | 159 | /** 160 | * Add a few additional bits (0 to 7) to the current computation, then 161 | * terminate it and output the result in the provided buffer, which must 162 | * be wide enough to accomodate the result (28 bytes). If bit number i 163 | * in ub has value 2^i, then the extra bits are those 164 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 165 | * level). The context is automatically reinitialized. 166 | * 167 | * @param cc the SHAvite-224 context 168 | * @param ub the extra bits 169 | * @param n the number of extra bits (0 to 7) 170 | * @param dst the destination buffer 171 | */ 172 | void sph_shavite224_addbits_and_close( 173 | void *cc, unsigned ub, unsigned n, void *dst); 174 | 175 | /** 176 | * Initialize a SHAvite-256 context. This process performs no memory allocation. 177 | * 178 | * @param cc the SHAvite-256 context (pointer to a 179 | * sph_shavite256_context) 180 | */ 181 | void sph_shavite256_init(void *cc); 182 | 183 | /** 184 | * Process some data bytes. It is acceptable that len is zero 185 | * (in which case this function does nothing). 186 | * 187 | * @param cc the SHAvite-256 context 188 | * @param data the input data 189 | * @param len the input data length (in bytes) 190 | */ 191 | void sph_shavite256(void *cc, const void *data, size_t len); 192 | 193 | /** 194 | * Terminate the current SHAvite-256 computation and output the result into 195 | * the provided buffer. The destination buffer must be wide enough to 196 | * accomodate the result (32 bytes). The context is automatically 197 | * reinitialized. 198 | * 199 | * @param cc the SHAvite-256 context 200 | * @param dst the destination buffer 201 | */ 202 | void sph_shavite256_close(void *cc, void *dst); 203 | 204 | /** 205 | * Add a few additional bits (0 to 7) to the current computation, then 206 | * terminate it and output the result in the provided buffer, which must 207 | * be wide enough to accomodate the result (32 bytes). If bit number i 208 | * in ub has value 2^i, then the extra bits are those 209 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 210 | * level). The context is automatically reinitialized. 211 | * 212 | * @param cc the SHAvite-256 context 213 | * @param ub the extra bits 214 | * @param n the number of extra bits (0 to 7) 215 | * @param dst the destination buffer 216 | */ 217 | void sph_shavite256_addbits_and_close( 218 | void *cc, unsigned ub, unsigned n, void *dst); 219 | 220 | /** 221 | * Initialize a SHAvite-384 context. This process performs no memory allocation. 222 | * 223 | * @param cc the SHAvite-384 context (pointer to a 224 | * sph_shavite384_context) 225 | */ 226 | void sph_shavite384_init(void *cc); 227 | 228 | /** 229 | * Process some data bytes. It is acceptable that len is zero 230 | * (in which case this function does nothing). 231 | * 232 | * @param cc the SHAvite-384 context 233 | * @param data the input data 234 | * @param len the input data length (in bytes) 235 | */ 236 | void sph_shavite384(void *cc, const void *data, size_t len); 237 | 238 | /** 239 | * Terminate the current SHAvite-384 computation and output the result into 240 | * the provided buffer. The destination buffer must be wide enough to 241 | * accomodate the result (48 bytes). The context is automatically 242 | * reinitialized. 243 | * 244 | * @param cc the SHAvite-384 context 245 | * @param dst the destination buffer 246 | */ 247 | void sph_shavite384_close(void *cc, void *dst); 248 | 249 | /** 250 | * Add a few additional bits (0 to 7) to the current computation, then 251 | * terminate it and output the result in the provided buffer, which must 252 | * be wide enough to accomodate the result (48 bytes). If bit number i 253 | * in ub has value 2^i, then the extra bits are those 254 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 255 | * level). The context is automatically reinitialized. 256 | * 257 | * @param cc the SHAvite-384 context 258 | * @param ub the extra bits 259 | * @param n the number of extra bits (0 to 7) 260 | * @param dst the destination buffer 261 | */ 262 | void sph_shavite384_addbits_and_close( 263 | void *cc, unsigned ub, unsigned n, void *dst); 264 | 265 | /** 266 | * Initialize a SHAvite-512 context. This process performs no memory allocation. 267 | * 268 | * @param cc the SHAvite-512 context (pointer to a 269 | * sph_shavite512_context) 270 | */ 271 | void sph_shavite512_init(void *cc); 272 | 273 | /** 274 | * Process some data bytes. It is acceptable that len is zero 275 | * (in which case this function does nothing). 276 | * 277 | * @param cc the SHAvite-512 context 278 | * @param data the input data 279 | * @param len the input data length (in bytes) 280 | */ 281 | void sph_shavite512(void *cc, const void *data, size_t len); 282 | 283 | /** 284 | * Terminate the current SHAvite-512 computation and output the result into 285 | * the provided buffer. The destination buffer must be wide enough to 286 | * accomodate the result (64 bytes). The context is automatically 287 | * reinitialized. 288 | * 289 | * @param cc the SHAvite-512 context 290 | * @param dst the destination buffer 291 | */ 292 | void sph_shavite512_close(void *cc, void *dst); 293 | 294 | /** 295 | * Add a few additional bits (0 to 7) to the current computation, then 296 | * terminate it and output the result in the provided buffer, which must 297 | * be wide enough to accomodate the result (64 bytes). If bit number i 298 | * in ub has value 2^i, then the extra bits are those 299 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 300 | * level). The context is automatically reinitialized. 301 | * 302 | * @param cc the SHAvite-512 context 303 | * @param ub the extra bits 304 | * @param n the number of extra bits (0 to 7) 305 | * @param dst the destination buffer 306 | */ 307 | void sph_shavite512_addbits_and_close( 308 | void *cc, unsigned ub, unsigned n, void *dst); 309 | 310 | #ifdef __cplusplus 311 | } 312 | #endif 313 | 314 | #endif 315 | --------------------------------------------------------------------------------