2 BLAKE2 reference source code package - reference C implementations
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/>.
20 #include "crypto_generichash_blake2b.h"
22 #define blake2b_init_param crypto_generichash_blake2b__init_param
23 #define blake2b_init crypto_generichash_blake2b__init
24 #define blake2b_init_salt_personal crypto_generichash_blake2b__init_salt_personal
25 #define blake2b_init_key crypto_generichash_blake2b__init_key
26 #define blake2b_init_key_salt_personal crypto_generichash_blake2b__init_key_salt_personal
27 #define blake2b_update crypto_generichash_blake2b__update
28 #define blake2b_final crypto_generichash_blake2b__final
29 #define blake2b crypto_generichash_blake2b__blake2b
30 #define blake2b_salt_personal crypto_generichash_blake2b__blake2b_salt_personal
33 #define ALIGN(x) __declspec(align(x))
35 #define ALIGN(x) __attribute__((aligned(x)))
38 #if defined(__cplusplus)
44 BLAKE2S_BLOCKBYTES = 64,
45 BLAKE2S_OUTBYTES = 32,
46 BLAKE2S_KEYBYTES = 32,
47 BLAKE2S_SALTBYTES = 8,
48 BLAKE2S_PERSONALBYTES = 8
53 BLAKE2B_BLOCKBYTES = 128,
54 BLAKE2B_OUTBYTES = 64,
55 BLAKE2B_KEYBYTES = 64,
56 BLAKE2B_SALTBYTES = 16,
57 BLAKE2B_PERSONALBYTES = 16
61 typedef struct blake2s_param_
63 uint8_t digest_length; // 1
64 uint8_t key_length; // 2
67 uint32_t leaf_length; // 8
68 uint8_t node_offset[6];// 14
69 uint8_t node_depth; // 15
70 uint8_t inner_length; // 16
71 // uint8_t reserved[0];
72 uint8_t salt[BLAKE2S_SALTBYTES]; // 24
73 uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32
76 ALIGN( 64 ) typedef struct blake2s_state_
81 uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
86 typedef struct blake2b_param_
88 uint8_t digest_length; // 1
89 uint8_t key_length; // 2
92 uint32_t leaf_length; // 8
93 uint64_t node_offset; // 16
94 uint8_t node_depth; // 17
95 uint8_t inner_length; // 18
96 uint8_t reserved[14]; // 32
97 uint8_t salt[BLAKE2B_SALTBYTES]; // 48
98 uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64
101 #ifndef DEFINE_BLAKE2B_STATE
102 typedef crypto_generichash_blake2b_state blake2b_state;
104 ALIGN( 64 ) typedef struct blake2b_state_
109 uint8_t buf[2 * BLAKE2B_BLOCKBYTES];
115 typedef struct blake2sp_state_
117 blake2s_state S[8][1];
119 uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
123 typedef struct blake2bp_state_
125 blake2b_state S[4][1];
127 uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
133 int blake2s_init( blake2s_state *S, const uint8_t outlen );
134 int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
135 int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
136 int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
137 int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
139 int blake2b_init( blake2b_state *S, const uint8_t outlen );
140 int blake2b_init_salt_personal( blake2b_state *S, const uint8_t outlen,
141 const void *personal, const void *salt );
142 int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
143 int blake2b_init_key_salt_personal( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen,
144 const void *salt, const void *personal );
145 int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
146 int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen );
147 int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen );
149 int blake2sp_init( blake2sp_state *S, const uint8_t outlen );
150 int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
151 int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen );
152 int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen );
154 int blake2bp_init( blake2bp_state *S, const uint8_t outlen );
155 int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
156 int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen );
157 int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen );
160 int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
161 int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
162 int blake2b_salt_personal( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen, const void *salt, const void *personal );
164 int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
165 int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
167 static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
169 return blake2b( out, in, key, outlen, inlen, keylen );
172 #if defined(__cplusplus)