Project Alice
Loading...
Searching...
No Matches
blake2.h
Go to the documentation of this file.
1/*
2 BLAKE2 reference source code package - reference C implementations
3
4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 your option. The terms of these licenses can be found at:
7
8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 - OpenSSL license : https://www.openssl.org/source/license.html
10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
12 More information about the BLAKE2 hash function can be found at
13 https://blake2.net.
14*/
15#ifndef BLAKE2_H
16#define BLAKE2_H
17
18#include <stddef.h>
19#include <stdint.h>
20
21#if defined(_MSC_VER)
22#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
23#else
24#define BLAKE2_PACKED(x) x __attribute__((packed))
25#endif
26
27#if defined(__cplusplus)
28extern "C" {
29#endif
30
37 };
38
45 };
46
47 typedef struct blake2s_state__ {
52 size_t buflen;
53 size_t outlen;
56
57 typedef struct blake2b_state__ {
62 size_t buflen;
63 size_t outlen;
66
67 typedef struct blake2sp_state__ {
71 size_t buflen;
72 size_t outlen;
74
75 typedef struct blake2bp_state__ {
79 size_t buflen;
80 size_t outlen;
82
83
84 BLAKE2_PACKED(struct blake2s_param__ {
85 uint8_t digest_length; /* 1 */
86 uint8_t key_length; /* 2 */
87 uint8_t fanout; /* 3 */
88 uint8_t depth; /* 4 */
89 uint32_t leaf_length; /* 8 */
90 uint32_t node_offset; /* 12 */
91 uint16_t xof_length; /* 14 */
92 uint8_t node_depth; /* 15 */
93 uint8_t inner_length; /* 16 */
94 /* uint8_t reserved[0]; */
95 uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
96 uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
97 });
98
99 typedef struct blake2s_param__ blake2s_param;
100
101 BLAKE2_PACKED(struct blake2b_param__ {
102 uint8_t digest_length; /* 1 */
103 uint8_t key_length; /* 2 */
104 uint8_t fanout; /* 3 */
105 uint8_t depth; /* 4 */
106 uint32_t leaf_length; /* 8 */
107 uint32_t node_offset; /* 12 */
108 uint32_t xof_length; /* 16 */
109 uint8_t node_depth; /* 17 */
110 uint8_t inner_length; /* 18 */
111 uint8_t reserved[14]; /* 32 */
112 uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
113 uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
114 });
115
116 typedef struct blake2b_param__ blake2b_param;
117
118 typedef struct blake2xs_state__ {
122
123 typedef struct blake2xb_state__ {
127
128 /* Padded structs result in a compile-time error */
129 enum {
131 BLAKE2_DUMMY_2 = 1 / (int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
132 };
133
134 /* Streaming API */
135 int blake2s_init(blake2s_state* S, size_t outlen);
136 int blake2s_init_key(blake2s_state* S, size_t outlen, const void* key, size_t keylen);
138 int blake2s_update(blake2s_state* S, const void* in, size_t inlen);
139 int blake2s_final(blake2s_state* S, void* out, size_t outlen);
140
141 int blake2b_init(blake2b_state* S, size_t outlen);
142 int blake2b_init_key(blake2b_state* S, size_t outlen, const void* key, size_t keylen);
144 int blake2b_update(blake2b_state* S, const void* in, size_t inlen);
145 int blake2b_final(blake2b_state* S, void* out, size_t outlen);
146
147 int blake2sp_init(blake2sp_state* S, size_t outlen);
148 int blake2sp_init_key(blake2sp_state* S, size_t outlen, const void* key, size_t keylen);
149 int blake2sp_update(blake2sp_state* S, const void* in, size_t inlen);
150 int blake2sp_final(blake2sp_state* S, void* out, size_t outlen);
151
152 int blake2bp_init(blake2bp_state* S, size_t outlen);
153 int blake2bp_init_key(blake2bp_state* S, size_t outlen, const void* key, size_t keylen);
154 int blake2bp_update(blake2bp_state* S, const void* in, size_t inlen);
155 int blake2bp_final(blake2bp_state* S, void* out, size_t outlen);
156
157 /* Variable output length API */
158 int blake2xs_init(blake2xs_state* S, const size_t outlen);
159 int blake2xs_init_key(blake2xs_state* S, const size_t outlen, const void* key, size_t keylen);
160 int blake2xs_update(blake2xs_state* S, const void* in, size_t inlen);
161 int blake2xs_final(blake2xs_state* S, void* out, size_t outlen);
162
163 int blake2xb_init(blake2xb_state* S, const size_t outlen);
164 int blake2xb_init_key(blake2xb_state* S, const size_t outlen, const void* key, size_t keylen);
165 int blake2xb_update(blake2xb_state* S, const void* in, size_t inlen);
166 int blake2xb_final(blake2xb_state* S, void* out, size_t outlen);
167
168 /* Simple API */
169 int blake2s(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
170 int blake2b(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
171
172 int blake2sp(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
173 int blake2bp(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
174
175 int blake2xs(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
176 int blake2xb(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
177
178 /* This is simply an alias for blake2b */
179 int blake2(void* out, size_t outlen, const void* in, size_t inlen, const void* key, size_t keylen);
180
181#if defined(__cplusplus)
182}
183#endif
184
185#endif
int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t keylen)
Definition: blake2.c:112
@ BLAKE2_DUMMY_2
Definition: blake2.h:131
@ BLAKE2_DUMMY_1
Definition: blake2.h:130
int blake2bp(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
struct blake2sp_state__ blake2sp_state
int blake2bp_final(blake2bp_state *S, void *out, size_t outlen)
int blake2xs_init(blake2xs_state *S, const size_t outlen)
int blake2s_init_param(blake2s_state *S, const blake2s_param *P)
struct blake2bp_state__ blake2bp_state
int blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
int blake2b_update(blake2b_state *S, const void *in, size_t inlen)
Definition: blake2.c:211
int blake2xb_init(blake2xb_state *S, const size_t outlen)
int blake2xb_init_key(blake2xb_state *S, const size_t outlen, const void *key, size_t keylen)
struct blake2b_param__ blake2b_param
Definition: blake2.h:116
struct blake2xs_state__ blake2xs_state
int blake2s_init(blake2s_state *S, size_t outlen)
int blake2sp_init(blake2sp_state *S, size_t outlen)
struct blake2s_state__ blake2s_state
blake2b_constant
Definition: blake2.h:39
@ BLAKE2B_PERSONALBYTES
Definition: blake2.h:44
@ BLAKE2B_KEYBYTES
Definition: blake2.h:42
@ BLAKE2B_OUTBYTES
Definition: blake2.h:41
@ BLAKE2B_SALTBYTES
Definition: blake2.h:43
@ BLAKE2B_BLOCKBYTES
Definition: blake2.h:40
int blake2b(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
Definition: blake2.c:259
int blake2bp_init(blake2bp_state *S, size_t outlen)
struct blake2b_state__ blake2b_state
int blake2xs_update(blake2xs_state *S, const void *in, size_t inlen)
int blake2sp(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
int blake2b_init(blake2b_state *S, size_t outlen)
Definition: blake2.c:91
int blake2bp_init_key(blake2bp_state *S, size_t outlen, const void *key, size_t keylen)
int blake2(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
Definition: blake2.c:284
int blake2xb_update(blake2xb_state *S, const void *in, size_t inlen)
int blake2s_update(blake2s_state *S, const void *in, size_t inlen)
int blake2sp_update(blake2sp_state *S, const void *in, size_t inlen)
int blake2s_init_key(blake2s_state *S, size_t outlen, const void *key, size_t keylen)
int blake2xs_init_key(blake2xs_state *S, const size_t outlen, const void *key, size_t keylen)
#define BLAKE2_PACKED(x)
Definition: blake2.h:24
blake2s_constant
Definition: blake2.h:31
@ BLAKE2S_PERSONALBYTES
Definition: blake2.h:36
@ BLAKE2S_KEYBYTES
Definition: blake2.h:34
@ BLAKE2S_OUTBYTES
Definition: blake2.h:33
@ BLAKE2S_SALTBYTES
Definition: blake2.h:35
@ BLAKE2S_BLOCKBYTES
Definition: blake2.h:32
int blake2b_final(blake2b_state *S, void *out, size_t outlen)
Definition: blake2.c:235
int blake2s(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
int blake2b_init_param(blake2b_state *S, const blake2b_param *P)
Definition: blake2.c:77
struct blake2xb_state__ blake2xb_state
struct blake2s_param__ blake2s_param
Definition: blake2.h:99
int blake2bp_update(blake2bp_state *S, const void *in, size_t inlen)
int blake2sp_final(blake2sp_state *S, void *out, size_t outlen)
int blake2sp_init_key(blake2sp_state *S, size_t outlen, const void *key, size_t keylen)
int blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
int blake2xs_final(blake2xs_state *S, void *out, size_t outlen)
int blake2s_final(blake2s_state *S, void *out, size_t outlen)
int blake2xb_final(blake2xb_state *S, void *out, size_t outlen)
uint uint32_t
ulong uint64_t
uchar uint8_t
uint64_t h[8]
Definition: blake2.h:58
uint64_t t[2]
Definition: blake2.h:59
size_t buflen
Definition: blake2.h:62
uint8_t buf[BLAKE2B_BLOCKBYTES]
Definition: blake2.h:61
size_t outlen
Definition: blake2.h:63
uint8_t last_node
Definition: blake2.h:64
uint64_t f[2]
Definition: blake2.h:60
size_t outlen
Definition: blake2.h:80
blake2b_state S[4][1]
Definition: blake2.h:76
size_t buflen
Definition: blake2.h:79
blake2b_state R[1]
Definition: blake2.h:77
uint8_t buf[4 *BLAKE2B_BLOCKBYTES]
Definition: blake2.h:78
size_t outlen
Definition: blake2.h:53
size_t buflen
Definition: blake2.h:52
uint32_t f[2]
Definition: blake2.h:50
uint8_t buf[BLAKE2S_BLOCKBYTES]
Definition: blake2.h:51
uint32_t t[2]
Definition: blake2.h:49
uint32_t h[8]
Definition: blake2.h:48
uint8_t last_node
Definition: blake2.h:54
size_t outlen
Definition: blake2.h:72
blake2s_state S[8][1]
Definition: blake2.h:68
uint8_t buf[8 *BLAKE2S_BLOCKBYTES]
Definition: blake2.h:70
blake2s_state R[1]
Definition: blake2.h:69
size_t buflen
Definition: blake2.h:71
blake2b_param P[1]
Definition: blake2.h:125
blake2b_state S[1]
Definition: blake2.h:124
blake2s_param P[1]
Definition: blake2.h:120
blake2s_state S[1]
Definition: blake2.h:119