Skip to content

Commit 6336160

Browse files
committed
Pull HACL* HMAC.
HACL* is at revision fc2e38f4d899ba28665c5b91caedaf35b3b37452.
1 parent 556dc9b commit 6336160

File tree

12 files changed

+1935
-10
lines changed

12 files changed

+1935
-10
lines changed

Modules/_hacl/Hacl_HMAC.c

Lines changed: 1609 additions & 0 deletions
Large diffs are not rendered by default.

Modules/_hacl/Hacl_HMAC.h

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/* MIT License
2+
*
3+
* Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
4+
* Copyright (c) 2022-2023 HACL* Contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
26+
#ifndef __Hacl_HMAC_H
27+
#define __Hacl_HMAC_H
28+
29+
#if defined(__cplusplus)
30+
extern "C" {
31+
#endif
32+
33+
#include <string.h>
34+
#include "python_hacl_namespaces.h"
35+
#include "krml/types.h"
36+
#include "krml/lowstar_endianness.h"
37+
#include "krml/internal/target.h"
38+
39+
#include "Hacl_Streaming_Types.h"
40+
41+
#include "Hacl_Hash_SHA3.h"
42+
#include "Hacl_Hash_SHA2.h"
43+
#include "Hacl_Hash_Blake2s.h"
44+
#include "Hacl_Hash_Blake2b.h"
45+
46+
/**
47+
Write the HMAC-MD5 MAC of a message (`data`) by using a key (`key`) into `dst`.
48+
49+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 byte.
50+
`dst` must point to 16 bytes of memory.
51+
*/
52+
void
53+
Hacl_HMAC_compute_md5(
54+
uint8_t *dst,
55+
uint8_t *key,
56+
uint32_t key_len,
57+
uint8_t *data,
58+
uint32_t data_len
59+
);
60+
61+
/**
62+
Write the HMAC-SHA-1 MAC of a message (`data`) by using a key (`key`) into `dst`.
63+
64+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 byte.
65+
`dst` must point to 20 bytes of memory.
66+
*/
67+
void
68+
Hacl_HMAC_compute_sha1(
69+
uint8_t *dst,
70+
uint8_t *key,
71+
uint32_t key_len,
72+
uint8_t *data,
73+
uint32_t data_len
74+
);
75+
76+
/**
77+
Write the HMAC-SHA-2-224 MAC of a message (`data`) by using a key (`key`) into `dst`.
78+
79+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 bytes.
80+
`dst` must point to 28 bytes of memory.
81+
*/
82+
void
83+
Hacl_HMAC_compute_sha2_224(
84+
uint8_t *dst,
85+
uint8_t *key,
86+
uint32_t key_len,
87+
uint8_t *data,
88+
uint32_t data_len
89+
);
90+
91+
/**
92+
Write the HMAC-SHA-2-256 MAC of a message (`data`) by using a key (`key`) into `dst`.
93+
94+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 bytes.
95+
`dst` must point to 32 bytes of memory.
96+
*/
97+
void
98+
Hacl_HMAC_compute_sha2_256(
99+
uint8_t *dst,
100+
uint8_t *key,
101+
uint32_t key_len,
102+
uint8_t *data,
103+
uint32_t data_len
104+
);
105+
106+
/**
107+
Write the HMAC-SHA-2-384 MAC of a message (`data`) by using a key (`key`) into `dst`.
108+
109+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 128 bytes.
110+
`dst` must point to 48 bytes of memory.
111+
*/
112+
void
113+
Hacl_HMAC_compute_sha2_384(
114+
uint8_t *dst,
115+
uint8_t *key,
116+
uint32_t key_len,
117+
uint8_t *data,
118+
uint32_t data_len
119+
);
120+
121+
/**
122+
Write the HMAC-SHA-2-512 MAC of a message (`data`) by using a key (`key`) into `dst`.
123+
124+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 128 bytes.
125+
`dst` must point to 64 bytes of memory.
126+
*/
127+
void
128+
Hacl_HMAC_compute_sha2_512(
129+
uint8_t *dst,
130+
uint8_t *key,
131+
uint32_t key_len,
132+
uint8_t *data,
133+
uint32_t data_len
134+
);
135+
136+
/**
137+
Write the HMAC-SHA-3-224 MAC of a message (`data`) by using a key (`key`) into `dst`.
138+
139+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 144 bytes.
140+
`dst` must point to 28 bytes of memory.
141+
*/
142+
void
143+
Hacl_HMAC_compute_sha3_224(
144+
uint8_t *dst,
145+
uint8_t *key,
146+
uint32_t key_len,
147+
uint8_t *data,
148+
uint32_t data_len
149+
);
150+
151+
/**
152+
Write the HMAC-SHA-3-256 MAC of a message (`data`) by using a key (`key`) into `dst`.
153+
154+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 136 bytes.
155+
`dst` must point to 32 bytes of memory.
156+
*/
157+
void
158+
Hacl_HMAC_compute_sha3_256(
159+
uint8_t *dst,
160+
uint8_t *key,
161+
uint32_t key_len,
162+
uint8_t *data,
163+
uint32_t data_len
164+
);
165+
166+
/**
167+
Write the HMAC-SHA-3-384 MAC of a message (`data`) by using a key (`key`) into `dst`.
168+
169+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 104 bytes.
170+
`dst` must point to 48 bytes of memory.
171+
*/
172+
void
173+
Hacl_HMAC_compute_sha3_384(
174+
uint8_t *dst,
175+
uint8_t *key,
176+
uint32_t key_len,
177+
uint8_t *data,
178+
uint32_t data_len
179+
);
180+
181+
/**
182+
Write the HMAC-SHA-3-512 MAC of a message (`data`) by using a key (`key`) into `dst`.
183+
184+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 72 bytes.
185+
`dst` must point to 64 bytes of memory.
186+
*/
187+
void
188+
Hacl_HMAC_compute_sha3_512(
189+
uint8_t *dst,
190+
uint8_t *key,
191+
uint32_t key_len,
192+
uint8_t *data,
193+
uint32_t data_len
194+
);
195+
196+
/**
197+
Write the HMAC-BLAKE2s MAC of a message (`data`) by using a key (`key`) into `dst`.
198+
199+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 64 bytes.
200+
`dst` must point to 32 bytes of memory.
201+
*/
202+
void
203+
Hacl_HMAC_compute_blake2s_32(
204+
uint8_t *dst,
205+
uint8_t *key,
206+
uint32_t key_len,
207+
uint8_t *data,
208+
uint32_t data_len
209+
);
210+
211+
/**
212+
Write the HMAC-BLAKE2b MAC of a message (`data`) by using a key (`key`) into `dst`.
213+
214+
The key can be any length and will be hashed if it is longer and padded if it is shorter than 128 bytes.
215+
`dst` must point to 64 bytes of memory.
216+
*/
217+
void
218+
Hacl_HMAC_compute_blake2b_32(
219+
uint8_t *dst,
220+
uint8_t *key,
221+
uint32_t key_len,
222+
uint8_t *data,
223+
uint32_t data_len
224+
);
225+
226+
#if defined(__cplusplus)
227+
}
228+
#endif
229+
230+
#define __Hacl_HMAC_H_DEFINED
231+
#endif

Modules/_hacl/Hacl_Hash_Blake2b.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ Hacl_Hash_Blake2b_reset_with_key_and_params(
10291029
uint8_t *k
10301030
)
10311031
{
1032-
index_of_state(s);
1032+
Hacl_Hash_Blake2b_index i1 = index_of_state(s);
1033+
KRML_MAYBE_UNUSED_VAR(i1);
10331034
reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k }));
10341035
}
10351036

Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
855855
uint8_t *k
856856
)
857857
{
858-
index_of_state(s);
858+
Hacl_Hash_Blake2b_index i1 = index_of_state(s);
859+
KRML_MAYBE_UNUSED_VAR(i1);
859860
reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k }));
860861
}
861862

Modules/_hacl/Hacl_Hash_Blake2s.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,8 @@ Hacl_Hash_Blake2s_reset_with_key_and_params(
10111011
uint8_t *k
10121012
)
10131013
{
1014-
index_of_state(s);
1014+
Hacl_Hash_Blake2b_index i1 = index_of_state(s);
1015+
KRML_MAYBE_UNUSED_VAR(i1);
10151016
reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k }));
10161017
}
10171018

Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params(
842842
uint8_t *k
843843
)
844844
{
845-
index_of_state(s);
845+
Hacl_Hash_Blake2b_index i1 = index_of_state(s);
846+
KRML_MAYBE_UNUSED_VAR(i1);
846847
reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k }));
847848
}
848849

Modules/_hacl/Hacl_Hash_SHA2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void Hacl_Hash_SHA2_sha224_init(uint32_t *hash)
211211
os[i] = x;);
212212
}
213213

214-
static inline void sha224_update_nblocks(uint32_t len, uint8_t *b, uint32_t *st)
214+
void Hacl_Hash_SHA2_sha224_update_nblocks(uint32_t len, uint8_t *b, uint32_t *st)
215215
{
216216
Hacl_Hash_SHA2_sha256_update_nblocks(len, b, st);
217217
}
@@ -825,7 +825,7 @@ void Hacl_Hash_SHA2_digest_224(Hacl_Streaming_MD_state_32 *state, uint8_t *outpu
825825
}
826826
uint8_t *buf_last = buf_1 + r - ite;
827827
uint8_t *buf_multi = buf_1;
828-
sha224_update_nblocks(0U, buf_multi, tmp_block_state);
828+
Hacl_Hash_SHA2_sha224_update_nblocks(0U, buf_multi, tmp_block_state);
829829
uint64_t prev_len_last = total_len - (uint64_t)r;
830830
Hacl_Hash_SHA2_sha224_update_last(prev_len_last + (uint64_t)r, r, buf_last, tmp_block_state);
831831
Hacl_Hash_SHA2_sha224_finish(tmp_block_state, output);
@@ -847,7 +847,7 @@ void Hacl_Hash_SHA2_hash_224(uint8_t *output, uint8_t *input, uint32_t input_len
847847
Hacl_Hash_SHA2_sha224_init(st);
848848
uint32_t rem = input_len % 64U;
849849
uint64_t len_ = (uint64_t)input_len;
850-
sha224_update_nblocks(input_len, ib, st);
850+
Hacl_Hash_SHA2_sha224_update_nblocks(input_len, ib, st);
851851
uint32_t rem1 = input_len % 64U;
852852
uint8_t *b0 = ib;
853853
uint8_t *lb = b0 + input_len - rem1;

Modules/_hacl/Hacl_Hash_SHA3.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ Hacl_Hash_SHA3_update_multi_sha3(
251251
uint8_t *bl0 = b_;
252252
uint8_t *uu____0 = b0 + i * block_len(a);
253253
memcpy(bl0, uu____0, block_len(a) * sizeof (uint8_t));
254-
block_len(a);
254+
uint32_t unused = block_len(a);
255+
KRML_MAYBE_UNUSED_VAR(unused);
255256
absorb_inner_32(b_, s);
256257
}
257258
}

Modules/_hacl/internal/Hacl_HMAC.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* MIT License
2+
*
3+
* Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
4+
* Copyright (c) 2022-2023 HACL* Contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
26+
#ifndef __internal_Hacl_HMAC_H
27+
#define __internal_Hacl_HMAC_H
28+
29+
#if defined(__cplusplus)
30+
extern "C" {
31+
#endif
32+
33+
#include <string.h>
34+
#include "krml/types.h"
35+
#include "krml/lowstar_endianness.h"
36+
#include "krml/internal/target.h"
37+
38+
39+
#include "internal/Hacl_Hash_SHA3.h"
40+
#include "internal/Hacl_Hash_SHA2.h"
41+
#include "internal/Hacl_Hash_SHA1.h"
42+
#include "internal/Hacl_Hash_MD5.h"
43+
#include "internal/Hacl_Hash_Blake2s.h"
44+
#include "internal/Hacl_Hash_Blake2b.h"
45+
#include "../Hacl_HMAC.h"
46+
47+
typedef struct K___uint32_t_uint32_t_s
48+
{
49+
uint32_t fst;
50+
uint32_t snd;
51+
}
52+
K___uint32_t_uint32_t;
53+
54+
#if defined(__cplusplus)
55+
}
56+
#endif
57+
58+
#define __internal_Hacl_HMAC_H_DEFINED
59+
#endif

Modules/_hacl/internal/Hacl_Hash_SHA2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ void Hacl_Hash_SHA2_sha256_finish(uint32_t *st, uint8_t *h);
123123

124124
void Hacl_Hash_SHA2_sha224_init(uint32_t *hash);
125125

126+
void Hacl_Hash_SHA2_sha224_update_nblocks(uint32_t len, uint8_t *b, uint32_t *st);
127+
126128
void
127129
Hacl_Hash_SHA2_sha224_update_last(uint64_t totlen, uint32_t len, uint8_t *b, uint32_t *st);
128130

0 commit comments

Comments
 (0)