Skip to content

Commit 2747f1f

Browse files
author
Hacl Bot
committed
[CI] update code
1 parent 05c3d8f commit 2747f1f

File tree

144 files changed

+6445
-2890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+6445
-2890
lines changed

include/Hacl_Bignum32.h

+242-140
Large diffs are not rendered by default.

include/Hacl_HMAC.h

+92
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,28 @@ extern "C" {
3535
#include "krml/lowstar_endianness.h"
3636
#include "krml/internal/target.h"
3737

38+
#include "Hacl_Streaming_Types.h"
3839
#include "Hacl_Krmllib.h"
40+
#include "Hacl_Hash_SHA3.h"
3941
#include "Hacl_Hash_SHA2.h"
4042
#include "Hacl_Hash_Blake2s.h"
4143
#include "Hacl_Hash_Blake2b.h"
4244

45+
/**
46+
Write the HMAC-MD5 MAC of a message (`data`) by using a key (`key`) into `dst`.
47+
48+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 byte.
49+
`dst` must point to 16 bytes of memory.
50+
*/
51+
void
52+
Hacl_HMAC_compute_md5(
53+
uint8_t *dst,
54+
uint8_t *key,
55+
uint32_t key_len,
56+
uint8_t *data,
57+
uint32_t data_len
58+
);
59+
4360
/**
4461
Write the HMAC-SHA-1 MAC of a message (`data`) by using a key (`key`) into `dst`.
4562
@@ -55,6 +72,21 @@ Hacl_HMAC_compute_sha1(
5572
uint32_t data_len
5673
);
5774

75+
/**
76+
Write the HMAC-SHA-2-224 MAC of a message (`data`) by using a key (`key`) into `dst`.
77+
78+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 bytes.
79+
`dst` must point to 28 bytes of memory.
80+
*/
81+
void
82+
Hacl_HMAC_compute_sha2_224(
83+
uint8_t *dst,
84+
uint8_t *key,
85+
uint32_t key_len,
86+
uint8_t *data,
87+
uint32_t data_len
88+
);
89+
5890
/**
5991
Write the HMAC-SHA-2-256 MAC of a message (`data`) by using a key (`key`) into `dst`.
6092
@@ -100,6 +132,66 @@ Hacl_HMAC_compute_sha2_512(
100132
uint32_t data_len
101133
);
102134

135+
/**
136+
Write the HMAC-SHA-3-224 MAC of a message (`data`) by using a key (`key`) into `dst`.
137+
138+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 144 bytes.
139+
`dst` must point to 28 bytes of memory.
140+
*/
141+
void
142+
Hacl_HMAC_compute_sha3_224(
143+
uint8_t *dst,
144+
uint8_t *key,
145+
uint32_t key_len,
146+
uint8_t *data,
147+
uint32_t data_len
148+
);
149+
150+
/**
151+
Write the HMAC-SHA-3-256 MAC of a message (`data`) by using a key (`key`) into `dst`.
152+
153+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 136 bytes.
154+
`dst` must point to 32 bytes of memory.
155+
*/
156+
void
157+
Hacl_HMAC_compute_sha3_256(
158+
uint8_t *dst,
159+
uint8_t *key,
160+
uint32_t key_len,
161+
uint8_t *data,
162+
uint32_t data_len
163+
);
164+
165+
/**
166+
Write the HMAC-SHA-3-384 MAC of a message (`data`) by using a key (`key`) into `dst`.
167+
168+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 104 bytes.
169+
`dst` must point to 48 bytes of memory.
170+
*/
171+
void
172+
Hacl_HMAC_compute_sha3_384(
173+
uint8_t *dst,
174+
uint8_t *key,
175+
uint32_t key_len,
176+
uint8_t *data,
177+
uint32_t data_len
178+
);
179+
180+
/**
181+
Write the HMAC-SHA-3-512 MAC of a message (`data`) by using a key (`key`) into `dst`.
182+
183+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 72 bytes.
184+
`dst` must point to 64 bytes of memory.
185+
*/
186+
void
187+
Hacl_HMAC_compute_sha3_512(
188+
uint8_t *dst,
189+
uint8_t *key,
190+
uint32_t key_len,
191+
uint8_t *data,
192+
uint32_t data_len
193+
);
194+
103195
/**
104196
Write the HMAC-BLAKE2s MAC of a message (`data`) by using a key (`key`) into `dst`.
105197

include/Hacl_Hash_Blake2b.h

+35-8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ typedef struct Hacl_Hash_Blake2b_blake2_params_s
5353
}
5454
Hacl_Hash_Blake2b_blake2_params;
5555

56+
typedef struct Hacl_Hash_Blake2b_index_s
57+
{
58+
uint8_t key_length;
59+
uint8_t digest_length;
60+
bool last_node;
61+
}
62+
Hacl_Hash_Blake2b_index;
63+
64+
#define HACL_HASH_BLAKE2B_BLOCK_BYTES (128U)
65+
66+
#define HACL_HASH_BLAKE2B_OUT_BYTES (64U)
67+
68+
#define HACL_HASH_BLAKE2B_KEY_BYTES (64U)
69+
70+
#define HACL_HASH_BLAKE2B_SALT_BYTES (16U)
71+
72+
#define HACL_HASH_BLAKE2B_PERSONAL_BYTES (16U)
73+
5674
typedef struct K____uint64_t___uint64_t__s
5775
{
5876
uint64_t *fst;
@@ -64,7 +82,8 @@ typedef struct Hacl_Hash_Blake2b_block_state_t_s
6482
{
6583
uint8_t fst;
6684
uint8_t snd;
67-
K____uint64_t___uint64_t_ thd;
85+
bool thd;
86+
K____uint64_t___uint64_t_ f3;
6887
}
6988
Hacl_Hash_Blake2b_block_state_t;
7089

@@ -92,7 +111,11 @@ The caller must satisfy the following requirements.
92111
93112
*/
94113
Hacl_Hash_Blake2b_state_t
95-
*Hacl_Hash_Blake2b_malloc_with_params_and_key(Hacl_Hash_Blake2b_blake2_params *p, uint8_t *k);
114+
*Hacl_Hash_Blake2b_malloc_with_params_and_key(
115+
Hacl_Hash_Blake2b_blake2_params *p,
116+
bool last_node,
117+
uint8_t *k
118+
);
96119

97120
/**
98121
Specialized allocation function that picks default values for all
@@ -116,7 +139,7 @@ Hacl_Hash_Blake2b_state_t *Hacl_Hash_Blake2b_malloc(void);
116139

117140
/**
118141
General-purpose re-initialization function with parameters and
119-
key. You cannot change digest_length or key_length, meaning those values in
142+
key. You cannot change digest_length, key_length, or last_node, meaning those values in
120143
the parameters object must be the same as originally decided via one of the
121144
malloc functions. All other values of the parameter can be changed. The behavior
122145
is unspecified if you violate this precondition.
@@ -159,10 +182,14 @@ at least `digest_length` bytes, where `digest_length` was determined by your
159182
choice of `malloc` function. Concretely, if you used `malloc` or
160183
`malloc_with_key`, then the expected length is 32 for S, or 64 for B (default
161184
digest length). If you used `malloc_with_params_and_key`, then the expected
162-
length is whatever you chose for the `digest_length` field of your
163-
parameters.
185+
length is whatever you chose for the `digest_length` field of your parameters.
186+
For convenience, this function returns `digest_length`. When in doubt, callers
187+
can pass an array of size HACL_BLAKE2B_32_OUT_BYTES, then use the return value
188+
to see how many bytes were actually written.
164189
*/
165-
void Hacl_Hash_Blake2b_digest(Hacl_Hash_Blake2b_state_t *state, uint8_t *output);
190+
uint8_t Hacl_Hash_Blake2b_digest(Hacl_Hash_Blake2b_state_t *s, uint8_t *dst);
191+
192+
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_info(Hacl_Hash_Blake2b_state_t *s);
166193

167194
/**
168195
Free state function when there is no key
@@ -198,10 +225,10 @@ Hacl_Hash_Blake2b_hash_with_key(
198225
Write the BLAKE2b digest of message `input` using key `key` and
199226
parameters `params` into `output`. The `key` array must be of length
200227
`params.key_length`. The `output` array must be of length
201-
`params.digest_length`.
228+
`params.digest_length`.
202229
*/
203230
void
204-
Hacl_Hash_Blake2b_hash_with_key_and_paramas(
231+
Hacl_Hash_Blake2b_hash_with_key_and_params(
205232
uint8_t *output,
206233
uint8_t *input,
207234
uint32_t input_len,

include/Hacl_Hash_Blake2b_Simd256.h

+75-23
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ extern "C" {
4040
#include "Hacl_Hash_Blake2b.h"
4141
#include "libintvector.h"
4242

43+
#define HACL_HASH_BLAKE2B_SIMD256_BLOCK_BYTES (128U)
44+
45+
#define HACL_HASH_BLAKE2B_SIMD256_OUT_BYTES (64U)
46+
47+
#define HACL_HASH_BLAKE2B_SIMD256_KEY_BYTES (64U)
48+
49+
#define HACL_HASH_BLAKE2B_SIMD256_SALT_BYTES (16U)
50+
51+
#define HACL_HASH_BLAKE2B_SIMD256_PERSONAL_BYTES (16U)
52+
4353
typedef struct K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256__s
4454
{
4555
Lib_IntVector_Intrinsics_vec256 *fst;
@@ -51,7 +61,8 @@ typedef struct Hacl_Hash_Blake2b_Simd256_block_state_t_s
5161
{
5262
uint8_t fst;
5363
uint8_t snd;
54-
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ thd;
64+
bool thd;
65+
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ f3;
5566
}
5667
Hacl_Hash_Blake2b_Simd256_block_state_t;
5768

@@ -64,34 +75,54 @@ typedef struct Hacl_Hash_Blake2b_Simd256_state_t_s
6475
Hacl_Hash_Blake2b_Simd256_state_t;
6576

6677
/**
67-
State allocation function when there are parameters and a key. The
68-
length of the key k MUST match the value of the field key_length in the
69-
parameters. Furthermore, there is a static (not dynamically checked) requirement
70-
that key_length does not exceed max_key (256 for S, 64 for B).)
78+
General-purpose allocation function that gives control over all
79+
Blake2 parameters, including the key. Further resettings of the state SHALL be
80+
done with `reset_with_params_and_key`, and SHALL feature the exact same values
81+
for the `key_length` and `digest_length` fields as passed here. In other words,
82+
once you commit to a digest and key length, the only way to change these
83+
parameters is to allocate a new object.
84+
85+
The caller must satisfy the following requirements.
86+
- The length of the key k MUST match the value of the field key_length in the
87+
parameters.
88+
- The key_length must not exceed 256 for S, 64 for B.
89+
- The digest_length must not exceed 256 for S, 64 for B.
90+
7191
*/
7292
Hacl_Hash_Blake2b_Simd256_state_t
7393
*Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key(
7494
Hacl_Hash_Blake2b_blake2_params *p,
95+
bool last_node,
7596
uint8_t *k
7697
);
7798

7899
/**
79-
State allocation function when there is just a custom key. All
80-
other parameters are set to their respective default values, meaning the output
81-
length is the maximum allowed output (256 for S, 64 for B).
100+
Specialized allocation function that picks default values for all
101+
parameters, except for the key_length. Further resettings of the state SHALL be
102+
done with `reset_with_key`, and SHALL feature the exact same key length `kk` as
103+
passed here. In other words, once you commit to a key length, the only way to
104+
change this parameter is to allocate a new object.
105+
106+
The caller must satisfy the following requirements.
107+
- The key_length must not exceed 256 for S, 64 for B.
108+
82109
*/
83110
Hacl_Hash_Blake2b_Simd256_state_t
84111
*Hacl_Hash_Blake2b_Simd256_malloc_with_key0(uint8_t *k, uint8_t kk);
85112

86113
/**
87-
State allocation function when there is no key
114+
Specialized allocation function that picks default values for all
115+
parameters, and has no key. Effectively, this is what you want if you intend to
116+
use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`.
88117
*/
89118
Hacl_Hash_Blake2b_Simd256_state_t *Hacl_Hash_Blake2b_Simd256_malloc(void);
90119

91120
/**
92-
Re-initialization function. The reinitialization API is tricky --
93-
you MUST reuse the same original parameters for digest (output) length and key
94-
length.
121+
General-purpose re-initialization function with parameters and
122+
key. You cannot change digest_length, key_length, or last_node, meaning those values in
123+
the parameters object must be the same as originally decided via one of the
124+
malloc functions. All other values of the parameter can be changed. The behavior
125+
is unspecified if you violate this precondition.
95126
*/
96127
void
97128
Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
@@ -101,21 +132,27 @@ Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
101132
);
102133

103134
/**
104-
Re-initialization function when there is a key. Note that the key
105-
size is not allowed to change, which is why this function does not take a key
106-
length -- the key has to be same key size that was originally passed to
107-
`malloc_with_key`
135+
Specialized-purpose re-initialization function with no parameters,
136+
and a key. The key length must be the same as originally decided via your choice
137+
of malloc function. All other parameters are reset to their default values. The
138+
original call to malloc MUST have set digest_length to the default value. The
139+
behavior is unspecified if you violate this precondition.
108140
*/
109141
void
110142
Hacl_Hash_Blake2b_Simd256_reset_with_key(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *k);
111143

112144
/**
113-
Re-initialization function when there is no key
145+
Specialized-purpose re-initialization function with no parameters
146+
and no key. This is what you want if you intend to use Blake2 as a hash
147+
function. The key length and digest length must have been set to their
148+
respective default values via your choice of malloc function (always true if you
149+
used `malloc`). All other parameters are reset to their default values. The
150+
behavior is unspecified if you violate this precondition.
114151
*/
115152
void Hacl_Hash_Blake2b_Simd256_reset(Hacl_Hash_Blake2b_Simd256_state_t *s);
116153

117154
/**
118-
Update function when there is no key; 0 = success, 1 = max length exceeded
155+
Update function; 0 = success, 1 = max length exceeded
119156
*/
120157
Hacl_Streaming_Types_error_code
121158
Hacl_Hash_Blake2b_Simd256_update(
@@ -125,18 +162,27 @@ Hacl_Hash_Blake2b_Simd256_update(
125162
);
126163

127164
/**
128-
Finish function when there is no key
165+
Digest function. This function expects the `output` array to hold
166+
at least `digest_length` bytes, where `digest_length` was determined by your
167+
choice of `malloc` function. Concretely, if you used `malloc` or
168+
`malloc_with_key`, then the expected length is 256 for S, or 64 for B (default
169+
digest length). If you used `malloc_with_params_and_key`, then the expected
170+
length is whatever you chose for the `digest_length` field of your parameters.
171+
For convenience, this function returns `digest_length`. When in doubt, callers
172+
can pass an array of size HACL_BLAKE2B_256_OUT_BYTES, then use the return value
173+
to see how many bytes were actually written.
129174
*/
130-
void
131-
Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *state, uint8_t *output);
175+
uint8_t Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *dst);
176+
177+
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(Hacl_Hash_Blake2b_Simd256_state_t *s);
132178

133179
/**
134180
Free state function when there is no key
135181
*/
136182
void Hacl_Hash_Blake2b_Simd256_free(Hacl_Hash_Blake2b_Simd256_state_t *state);
137183

138184
/**
139-
Copying. The key length (or absence thereof) must match between source and destination.
185+
Copying. This preserves all parameters.
140186
*/
141187
Hacl_Hash_Blake2b_Simd256_state_t
142188
*Hacl_Hash_Blake2b_Simd256_copy(Hacl_Hash_Blake2b_Simd256_state_t *state);
@@ -161,8 +207,14 @@ Hacl_Hash_Blake2b_Simd256_hash_with_key(
161207
uint32_t key_len
162208
);
163209

210+
/**
211+
Write the BLAKE2b digest of message `input` using key `key` and
212+
parameters `params` into `output`. The `key` array must be of length
213+
`params.key_length`. The `output` array must be of length
214+
`params.digest_length`.
215+
*/
164216
void
165-
Hacl_Hash_Blake2b_Simd256_hash_with_key_and_paramas(
217+
Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params(
166218
uint8_t *output,
167219
uint8_t *input,
168220
uint32_t input_len,

0 commit comments

Comments
 (0)