1 2 #include "crypto_generichash.h" 3 #include "randombytes.h" 4 5 size_t 6 crypto_generichash_bytes_min(void) 7 { 8 return crypto_generichash_BYTES_MIN; 9 } 10 11 size_t 12 crypto_generichash_bytes_max(void) 13 { 14 return crypto_generichash_BYTES_MAX; 15 } 16 17 size_t 18 crypto_generichash_bytes(void) 19 { 20 return crypto_generichash_BYTES; 21 } 22 23 size_t 24 crypto_generichash_keybytes_min(void) 25 { 26 return crypto_generichash_KEYBYTES_MIN; 27 } 28 29 size_t 30 crypto_generichash_keybytes_max(void) 31 { 32 return crypto_generichash_KEYBYTES_MAX; 33 } 34 35 size_t 36 crypto_generichash_keybytes(void) 37 { 38 return crypto_generichash_KEYBYTES; 39 } 40 41 const char * 42 crypto_generichash_primitive(void) 43 { 44 return crypto_generichash_PRIMITIVE; 45 } 46 47 size_t 48 crypto_generichash_statebytes(void) 49 { 50 return (sizeof(crypto_generichash_state) + (size_t) 63U) & ~(size_t) 63U; 51 } 52 53 int 54 crypto_generichash(unsigned char *out, size_t outlen, const unsigned char *in, 55 unsigned long long inlen, const unsigned char *key, 56 size_t keylen) 57 { 58 return crypto_generichash_blake2b(out, outlen, in, inlen, key, keylen); 59 } 60 61 int 62 crypto_generichash_init(crypto_generichash_state *state, 63 const unsigned char *key, 64 const size_t keylen, const size_t outlen) 65 { 66 return crypto_generichash_blake2b_init 67 ((crypto_generichash_blake2b_state *) state, key, keylen, outlen); 68 } 69 70 int 71 crypto_generichash_update(crypto_generichash_state *state, 72 const unsigned char *in, 73 unsigned long long inlen) 74 { 75 return crypto_generichash_blake2b_update 76 ((crypto_generichash_blake2b_state *) state, in, inlen); 77 } 78 79 int 80 crypto_generichash_final(crypto_generichash_state *state, 81 unsigned char *out, const size_t outlen) 82 { 83 return crypto_generichash_blake2b_final 84 ((crypto_generichash_blake2b_state *) state, out, outlen); 85 } 86 87 void 88 crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES]) 89 { 90 randombytes_buf(k, crypto_generichash_KEYBYTES); 91 } 92