1 /* 2 * Argon2 reference source code package - reference C implementations 3 * 4 * Copyright 2015 5 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 * 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: 10 * 11 * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 * 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. 16 */ 17 18 #ifndef PORTABLE_BLAKE2_H 19 #define PORTABLE_BLAKE2_H 20 21 #include <argon2.h> 22 23 #if defined(__cplusplus) 24 extern "C" { 25 #endif 26 27 enum blake2b_constant { 28 BLAKE2B_BLOCKBYTES = 128, 29 BLAKE2B_OUTBYTES = 64, 30 BLAKE2B_KEYBYTES = 64, 31 BLAKE2B_SALTBYTES = 16, 32 BLAKE2B_PERSONALBYTES = 16 33 }; 34 35 #pragma pack(push, 1) 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 */ 48 } blake2b_param; 49 #pragma pack(pop) 50 51 typedef struct __blake2b_state { 52 uint64_t h[8]; 53 uint64_t t[2]; 54 uint64_t f[2]; 55 uint8_t buf[BLAKE2B_BLOCKBYTES]; 56 unsigned buflen; 57 unsigned outlen; 58 uint8_t last_node; 59 } blake2b_state; 60 61 /* Ensure param structs have not been wrongly padded */ 62 /* Poor man's static_assert */ 63 enum { 64 blake2_size_check_0 = 1 / !!(CHAR_BIT == 8), 65 blake2_size_check_2 = 66 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT) 67 }; 68 69 /* Streaming API */ 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, 72 size_t keylen); 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); 76 77 /* Simple API */ 78 ARGON2_LOCAL int blake2b(void *out, size_t outlen, const void *in, size_t inlen, 79 const void *key, size_t keylen); 80 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 */ 84 85 #if defined(__cplusplus) 86 } 87 #endif 88 89 #endif 90