2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * Derived from the BLAKE2 reference implementation written by Samuel Neves.
12 * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
13 * More information about the BLAKE2 hash function and its implementations
14 * can be found at https://blake2.net.
19 #define BLAKE2S_BLOCKBYTES 64
20 #define BLAKE2S_OUTBYTES 32
21 #define BLAKE2S_KEYBYTES 32
22 #define BLAKE2S_SALTBYTES 8
23 #define BLAKE2S_PERSONALBYTES 8
25 #define BLAKE2B_BLOCKBYTES 128
26 #define BLAKE2B_OUTBYTES 64
27 #define BLAKE2B_KEYBYTES 64
28 #define BLAKE2B_SALTBYTES 16
29 #define BLAKE2B_PERSONALBYTES 16
31 struct blake2s_param_st {
32 uint8_t digest_length; /* 1 */
33 uint8_t key_length; /* 2 */
34 uint8_t fanout; /* 3 */
35 uint8_t depth; /* 4 */
36 uint8_t leaf_length[4];/* 8 */
37 uint8_t node_offset[6];/* 14 */
38 uint8_t node_depth; /* 15 */
39 uint8_t inner_length; /* 16 */
40 uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
41 uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
44 typedef struct blake2s_param_st BLAKE2S_PARAM;
46 struct blake2s_ctx_st {
50 uint8_t buf[BLAKE2S_BLOCKBYTES];
55 struct blake2b_param_st {
56 uint8_t digest_length; /* 1 */
57 uint8_t key_length; /* 2 */
58 uint8_t fanout; /* 3 */
59 uint8_t depth; /* 4 */
60 uint8_t leaf_length[4];/* 8 */
61 uint8_t node_offset[8];/* 16 */
62 uint8_t node_depth; /* 17 */
63 uint8_t inner_length; /* 18 */
64 uint8_t reserved[14]; /* 32 */
65 uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
66 uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
69 typedef struct blake2b_param_st BLAKE2B_PARAM;
71 struct blake2b_ctx_st {
75 uint8_t buf[BLAKE2B_BLOCKBYTES];
80 #define BLAKE2B_DIGEST_LENGTH 64
81 #define BLAKE2S_DIGEST_LENGTH 32
83 typedef struct blake2s_ctx_st BLAKE2S_CTX;
84 typedef struct blake2b_ctx_st BLAKE2B_CTX;
86 int BLAKE2b_Init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P);
87 int BLAKE2b_Init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key);
88 int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen);
89 int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c);
92 * These setters are internal and do not check the validity of their parameters.
93 * See blake2b_mac_ctrl for validation logic.
96 void blake2b_param_init(BLAKE2B_PARAM *P);
97 void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen);
98 void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen);
99 void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t length);
100 void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t length);
102 int BLAKE2s_Init(BLAKE2S_CTX *c);
103 int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen);
104 int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c);