26 #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
28 #define BLAKE2_PACKED(x) x __attribute__((packed))
31 #if defined(__cplusplus)
34 enum blake2s_constant {
35 BLAKE2S_BLOCKBYTES = 64,
36 BLAKE2S_OUTBYTES = 32,
37 BLAKE2S_KEYBYTES = 32,
38 BLAKE2S_SALTBYTES = 8,
39 BLAKE2S_PERSONALBYTES = 8
52 typedef struct blake2s_state__ {
56 uint8_t buf[BLAKE2S_BLOCKBYTES];
75 typedef struct blake2sp_state__ {
76 blake2s_state S[8][1];
78 uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
83 typedef struct blake2bp_state__ {
84 blake2b_state S[4][1];
86 uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
91 BLAKE2_PACKED(
struct blake2s_param__ {
102 uint8_t salt[BLAKE2S_SALTBYTES];
103 uint8_t personal[BLAKE2S_PERSONALBYTES];
106 typedef struct blake2s_param__ blake2s_param;
108 BLAKE2_PACKED(
struct blake2b_param__ {
113 uint32_t leaf_length;
114 uint32_t node_offset;
119 uint8_t salt[BLAKE2B_SALTBYTES];
120 uint8_t personal[BLAKE2B_PERSONALBYTES];
123 typedef struct blake2b_param__ blake2b_param;
125 typedef struct blake2xs_state__ {
130 typedef struct blake2xb_state__ {
137 BLAKE2_DUMMY_1 = 1 / (
sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
138 BLAKE2_DUMMY_2 = 1 / (
sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
142 int blake2s_init(blake2s_state *S,
size_t outlen);
143 int blake2s_init_key(blake2s_state *S,
size_t outlen,
const void *key,
size_t keylen);
144 int blake2s_init_param(blake2s_state *S,
const blake2s_param *P);
145 int blake2s_update(blake2s_state *S,
const void *in,
size_t inlen);
146 int blake2s_final(blake2s_state *S,
void *out,
size_t outlen);
148 int blake2b_init(blake2b_state *S,
152 unsigned char *personal,
153 size_t personal_len);
154 int blake2b_init_key(blake2b_state *S,
size_t outlen,
const void *key,
size_t keylen);
155 int blake2b_init_param(blake2b_state *S,
const blake2b_param *P);
156 void blake2b_update(blake2b_state *S,
const void *in,
size_t inlen);
157 int blake2b_final(blake2b_state *S,
void *out,
size_t outlen);
159 int blake2sp_init(blake2sp_state *S,
size_t outlen);
160 int blake2sp_init_key(blake2sp_state *S,
size_t outlen,
const void *key,
size_t keylen);
161 int blake2sp_update(blake2sp_state *S,
const void *in,
size_t inlen);
162 int blake2sp_final(blake2sp_state *S,
void *out,
size_t outlen);
164 int blake2bp_init(blake2bp_state *S,
size_t outlen);
165 int blake2bp_init_key(blake2bp_state *S,
size_t outlen,
const void *key,
size_t keylen);
166 int blake2bp_update(blake2bp_state *S,
const void *in,
size_t inlen);
167 int blake2bp_final(blake2bp_state *S,
void *out,
size_t outlen);
170 int blake2xs_init(blake2xs_state *S,
const size_t outlen);
171 int blake2xs_init_key(blake2xs_state *S,
const size_t outlen,
const void *key,
size_t keylen);
172 int blake2xs_update(blake2xs_state *S,
const void *in,
size_t inlen);
173 int blake2xs_final(blake2xs_state *S,
void *out,
size_t outlen);
175 int blake2xb_init(blake2xb_state *S,
const size_t outlen);
176 int blake2xb_init_key(blake2xb_state *S,
const size_t outlen,
const void *key,
size_t keylen);
177 int blake2xb_update(blake2xb_state *S,
const void *in,
size_t inlen);
178 int blake2xb_final(blake2xb_state *S,
void *out,
size_t outlen);
181 int blake2s(
void *out,
size_t outlen,
const void *in,
size_t inlen,
const void *key,
size_t keylen);
182 int blake2b(
void *out,
size_t outlen,
const void *in,
size_t inlen,
const void *key,
size_t keylen);
184 int blake2sp(
void *out,
190 int blake2bp(
void *out,
197 int blake2xs(
void *out,
203 int blake2xb(
void *out,
211 int blake2(
void *out,
size_t outlen,
const void *in,
size_t inlen,
const void *key,
size_t keylen);
213 #if defined(__cplusplus)
BLAKE2 crypographic hash function.