2 * Argon2 reference source code package - reference C implementations
5 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
7 * You may use this work under the terms of a Creative Commons CC0 1.0
8 * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9 * these licenses can be found at:
11 * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12 * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
14 * You should have received a copy of both of these licenses along with this
15 * software. If not, they may be obtained at the above URLs.
18 #ifndef PORTABLE_BLAKE2_H
19 #define PORTABLE_BLAKE2_H
21 #include "../argon2.h"
23 #if defined(__cplusplus)
27 enum blake2b_constant {
28 BLAKE2B_BLOCKBYTES = 128,
29 BLAKE2B_OUTBYTES = 64,
30 BLAKE2B_KEYBYTES = 64,
31 BLAKE2B_SALTBYTES = 16,
32 BLAKE2B_PERSONALBYTES = 16
36 typedef struct __blake2b_param {
37 uint8_t digest_length; /* 1 */
38 uint8_t key_length; /* 2 */
39 uint8_t fanout; /* 3 */
40 uint8_t depth; /* 4 */
41 uint32_t leaf_length; /* 8 */
42 uint64_t node_offset; /* 16 */
43 uint8_t node_depth; /* 17 */
44 uint8_t inner_length; /* 18 */
45 uint8_t reserved[14]; /* 32 */
46 uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
47 uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
51 typedef struct __blake2b_state {
55 uint8_t buf[BLAKE2B_BLOCKBYTES];
61 /* Ensure param structs have not been wrongly padded */
62 /* Poor man's static_assert */
64 blake2_size_check_0 = 1 / !!(CHAR_BIT == 8),
66 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT)
70 ARGON2_LOCAL int blake2b_init(blake2b_state *S, size_t outlen);
71 ARGON2_LOCAL int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key,
73 ARGON2_LOCAL int blake2b_init_param(blake2b_state *S, const blake2b_param *P);
74 ARGON2_LOCAL int blake2b_update(blake2b_state *S, const void *in, size_t inlen);
75 ARGON2_LOCAL int blake2b_final(blake2b_state *S, void *out, size_t outlen);
78 ARGON2_LOCAL int blake2b(void *out, size_t outlen, const void *in, size_t inlen,
79 const void *key, size_t keylen);
81 /* Argon2 Team - Begin Code */
82 ARGON2_LOCAL int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen);
83 /* Argon2 Team - End Code */
85 #if defined(__cplusplus)