2 BLAKE2 reference source code package - reference C implementations
4 Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
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.
10 You should have received a copy of the CC0 Public Domain Dedication along with
11 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
21 #define ALIGN(x) __declspec(align(x))
23 #define inline __inline
26 #define ALIGN(x) __attribute__((aligned(x)))
39 BLAKE2B_BLOCKBYTES = 128,
40 BLAKE2B_OUTBYTES = 64,
41 BLAKE2B_KEYBYTES = 64,
42 BLAKE2B_SALTBYTES = 16,
43 BLAKE2B_PERSONALBYTES = 16
47 typedef struct __blake2b_param
49 uint8_t digest_length; // 1
50 uint8_t key_length; // 2
53 uint32_t leaf_length; // 8
54 uint64_t node_offset; // 16
55 uint8_t node_depth; // 17
56 uint8_t inner_length; // 18
57 uint8_t reserved[14]; // 32
58 uint8_t salt[BLAKE2B_SALTBYTES]; // 48
59 uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64
62 ALIGN( 64 ) typedef struct __blake2b_state
67 uint8_t buf[2 * BLAKE2B_BLOCKBYTES];
74 int blake2b_init( blake2b_state *S, const uint8_t outlen );
75 int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
76 int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
77 int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen );
78 int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen );
81 int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
83 static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
85 return blake2b( out, in, key, outlen, inlen, keylen );