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)))
29 #if defined(__cplusplus)
35 BLAKE2B_BLOCKBYTES
= 128,
36 BLAKE2B_OUTBYTES
= 64,
37 BLAKE2B_KEYBYTES
= 64,
38 BLAKE2B_SALTBYTES
= 16,
39 BLAKE2B_PERSONALBYTES
= 16
43 typedef struct __blake2b_param
45 uint8_t digest_length
; // 1
46 uint8_t key_length
; // 2
49 uint32_t leaf_length
; // 8
50 uint64_t node_offset
; // 16
51 uint8_t node_depth
; // 17
52 uint8_t inner_length
; // 18
53 uint8_t reserved
[14]; // 32
54 uint8_t salt
[BLAKE2B_SALTBYTES
]; // 48
55 uint8_t personal
[BLAKE2B_PERSONALBYTES
]; // 64
58 ALIGN( 64 ) typedef struct __blake2b_state
63 uint8_t buf
[2 * BLAKE2B_BLOCKBYTES
];
70 int blake2b_init( blake2b_state
*S
, const uint8_t outlen
);
71 int blake2b_init_key( blake2b_state
*S
, const uint8_t outlen
, const void *key
, const uint8_t keylen
);
72 int blake2b_init_param( blake2b_state
*S
, const blake2b_param
*P
);
73 int blake2b_update( blake2b_state
*S
, const uint8_t *in
, uint64_t inlen
);
74 int blake2b_final( blake2b_state
*S
, uint8_t *out
, uint8_t outlen
);
77 int blake2b( uint8_t *out
, const void *in
, const void *key
, const uint8_t outlen
, const uint64_t inlen
, uint8_t keylen
);
79 static inline int blake2( uint8_t *out
, const void *in
, const void *key
, const uint8_t outlen
, const uint64_t inlen
, uint8_t keylen
)
81 return blake2b( out
, in
, key
, outlen
, inlen
, keylen
);
84 #if defined(__cplusplus)