Branch data Line data Source code
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 : : #include "internal/Hacl_Hash_SHA1.h"
27 : :
28 : : static uint32_t
29 : : _h0[5U] =
30 : : {
31 : : (uint32_t)0x67452301U, (uint32_t)0xefcdab89U, (uint32_t)0x98badcfeU, (uint32_t)0x10325476U,
32 : : (uint32_t)0xc3d2e1f0U
33 : : };
34 : :
35 : 0 : void Hacl_Hash_Core_SHA1_legacy_init(uint32_t *s)
36 : : {
37 : 0 : KRML_MAYBE_FOR5(i, (uint32_t)0U, (uint32_t)5U, (uint32_t)1U, s[i] = _h0[i];);
38 : 0 : }
39 : :
40 : 0 : static void legacy_update(uint32_t *h, uint8_t *l)
41 : : {
42 : 0 : uint32_t ha = h[0U];
43 : 0 : uint32_t hb = h[1U];
44 : 0 : uint32_t hc = h[2U];
45 : 0 : uint32_t hd = h[3U];
46 : 0 : uint32_t he = h[4U];
47 : 0 : uint32_t _w[80U] = { 0U };
48 [ # # ]: 0 : for (uint32_t i = (uint32_t)0U; i < (uint32_t)80U; i++)
49 : : {
50 : : uint32_t v;
51 [ # # ]: 0 : if (i < (uint32_t)16U)
52 : : {
53 : 0 : uint8_t *b = l + i * (uint32_t)4U;
54 : 0 : uint32_t u = load32_be(b);
55 : 0 : v = u;
56 : : }
57 : : else
58 : : {
59 : 0 : uint32_t wmit3 = _w[i - (uint32_t)3U];
60 : 0 : uint32_t wmit8 = _w[i - (uint32_t)8U];
61 : 0 : uint32_t wmit14 = _w[i - (uint32_t)14U];
62 : 0 : uint32_t wmit16 = _w[i - (uint32_t)16U];
63 : 0 : v =
64 : 0 : (wmit3 ^ (wmit8 ^ (wmit14 ^ wmit16)))
65 : : << (uint32_t)1U
66 : : | (wmit3 ^ (wmit8 ^ (wmit14 ^ wmit16))) >> (uint32_t)31U;
67 : : }
68 : 0 : _w[i] = v;
69 : : }
70 [ # # ]: 0 : for (uint32_t i = (uint32_t)0U; i < (uint32_t)80U; i++)
71 : : {
72 : 0 : uint32_t _a = h[0U];
73 : 0 : uint32_t _b = h[1U];
74 : 0 : uint32_t _c = h[2U];
75 : 0 : uint32_t _d = h[3U];
76 : 0 : uint32_t _e = h[4U];
77 : 0 : uint32_t wmit = _w[i];
78 : : uint32_t ite0;
79 [ # # ]: 0 : if (i < (uint32_t)20U)
80 : : {
81 : 0 : ite0 = (_b & _c) ^ (~_b & _d);
82 : : }
83 [ # # # # ]: 0 : else if ((uint32_t)39U < i && i < (uint32_t)60U)
84 : : {
85 : 0 : ite0 = (_b & _c) ^ ((_b & _d) ^ (_c & _d));
86 : : }
87 : : else
88 : : {
89 : 0 : ite0 = _b ^ (_c ^ _d);
90 : : }
91 : : uint32_t ite;
92 [ # # ]: 0 : if (i < (uint32_t)20U)
93 : : {
94 : 0 : ite = (uint32_t)0x5a827999U;
95 : : }
96 [ # # ]: 0 : else if (i < (uint32_t)40U)
97 : : {
98 : 0 : ite = (uint32_t)0x6ed9eba1U;
99 : : }
100 [ # # ]: 0 : else if (i < (uint32_t)60U)
101 : : {
102 : 0 : ite = (uint32_t)0x8f1bbcdcU;
103 : : }
104 : : else
105 : : {
106 : 0 : ite = (uint32_t)0xca62c1d6U;
107 : : }
108 : 0 : uint32_t _T = (_a << (uint32_t)5U | _a >> (uint32_t)27U) + ite0 + _e + ite + wmit;
109 : 0 : h[0U] = _T;
110 : 0 : h[1U] = _a;
111 : 0 : h[2U] = _b << (uint32_t)30U | _b >> (uint32_t)2U;
112 : 0 : h[3U] = _c;
113 : 0 : h[4U] = _d;
114 : : }
115 [ # # ]: 0 : for (uint32_t i = (uint32_t)0U; i < (uint32_t)80U; i++)
116 : : {
117 : 0 : _w[i] = (uint32_t)0U;
118 : : }
119 : 0 : uint32_t sta = h[0U];
120 : 0 : uint32_t stb = h[1U];
121 : 0 : uint32_t stc = h[2U];
122 : 0 : uint32_t std = h[3U];
123 : 0 : uint32_t ste = h[4U];
124 : 0 : h[0U] = sta + ha;
125 : 0 : h[1U] = stb + hb;
126 : 0 : h[2U] = stc + hc;
127 : 0 : h[3U] = std + hd;
128 : 0 : h[4U] = ste + he;
129 : 0 : }
130 : :
131 : 0 : static void legacy_pad(uint64_t len, uint8_t *dst)
132 : : {
133 : 0 : uint8_t *dst1 = dst;
134 : 0 : dst1[0U] = (uint8_t)0x80U;
135 : 0 : uint8_t *dst2 = dst + (uint32_t)1U;
136 : 0 : for
137 : : (uint32_t
138 : 0 : i = (uint32_t)0U;
139 : : i
140 [ # # ]: 0 : < ((uint32_t)128U - ((uint32_t)9U + (uint32_t)(len % (uint64_t)(uint32_t)64U))) % (uint32_t)64U;
141 : 0 : i++)
142 : : {
143 : 0 : dst2[i] = (uint8_t)0U;
144 : : }
145 : : uint8_t
146 : 0 : *dst3 =
147 : : dst
148 : : +
149 : : (uint32_t)1U
150 : 0 : +
151 : 0 : ((uint32_t)128U - ((uint32_t)9U + (uint32_t)(len % (uint64_t)(uint32_t)64U)))
152 : 0 : % (uint32_t)64U;
153 : 0 : store64_be(dst3, len << (uint32_t)3U);
154 : 0 : }
155 : :
156 : 0 : void Hacl_Hash_Core_SHA1_legacy_finish(uint32_t *s, uint8_t *dst)
157 : : {
158 : 0 : KRML_MAYBE_FOR5(i,
159 : : (uint32_t)0U,
160 : : (uint32_t)5U,
161 : : (uint32_t)1U,
162 : : store32_be(dst + i * (uint32_t)4U, s[i]););
163 : 0 : }
164 : :
165 : 0 : void Hacl_Hash_SHA1_legacy_update_multi(uint32_t *s, uint8_t *blocks, uint32_t n_blocks)
166 : : {
167 [ # # ]: 0 : for (uint32_t i = (uint32_t)0U; i < n_blocks; i++)
168 : : {
169 : 0 : uint32_t sz = (uint32_t)64U;
170 : 0 : uint8_t *block = blocks + sz * i;
171 : 0 : legacy_update(s, block);
172 : : }
173 : 0 : }
174 : :
175 : : void
176 : 0 : Hacl_Hash_SHA1_legacy_update_last(
177 : : uint32_t *s,
178 : : uint64_t prev_len,
179 : : uint8_t *input,
180 : : uint32_t input_len
181 : : )
182 : : {
183 : 0 : uint32_t blocks_n = input_len / (uint32_t)64U;
184 : 0 : uint32_t blocks_len = blocks_n * (uint32_t)64U;
185 : 0 : uint8_t *blocks = input;
186 : 0 : uint32_t rest_len = input_len - blocks_len;
187 : 0 : uint8_t *rest = input + blocks_len;
188 : 0 : Hacl_Hash_SHA1_legacy_update_multi(s, blocks, blocks_n);
189 : 0 : uint64_t total_input_len = prev_len + (uint64_t)input_len;
190 : : uint32_t
191 : 0 : pad_len =
192 : : (uint32_t)1U
193 : : +
194 : 0 : ((uint32_t)128U - ((uint32_t)9U + (uint32_t)(total_input_len % (uint64_t)(uint32_t)64U)))
195 : 0 : % (uint32_t)64U
196 : : + (uint32_t)8U;
197 : 0 : uint32_t tmp_len = rest_len + pad_len;
198 : 0 : uint8_t tmp_twoblocks[128U] = { 0U };
199 : 0 : uint8_t *tmp = tmp_twoblocks;
200 : 0 : uint8_t *tmp_rest = tmp;
201 : 0 : uint8_t *tmp_pad = tmp + rest_len;
202 : 0 : memcpy(tmp_rest, rest, rest_len * sizeof (uint8_t));
203 : 0 : legacy_pad(total_input_len, tmp_pad);
204 : 0 : Hacl_Hash_SHA1_legacy_update_multi(s, tmp, tmp_len / (uint32_t)64U);
205 : 0 : }
206 : :
207 : 0 : void Hacl_Hash_SHA1_legacy_hash(uint8_t *input, uint32_t input_len, uint8_t *dst)
208 : : {
209 : : uint32_t
210 : 0 : s[5U] =
211 : : {
212 : : (uint32_t)0x67452301U, (uint32_t)0xefcdab89U, (uint32_t)0x98badcfeU, (uint32_t)0x10325476U,
213 : : (uint32_t)0xc3d2e1f0U
214 : : };
215 : 0 : uint32_t blocks_n0 = input_len / (uint32_t)64U;
216 : : uint32_t blocks_n1;
217 [ # # # # ]: 0 : if (input_len % (uint32_t)64U == (uint32_t)0U && blocks_n0 > (uint32_t)0U)
218 : : {
219 : 0 : blocks_n1 = blocks_n0 - (uint32_t)1U;
220 : : }
221 : : else
222 : : {
223 : 0 : blocks_n1 = blocks_n0;
224 : : }
225 : 0 : uint32_t blocks_len0 = blocks_n1 * (uint32_t)64U;
226 : 0 : uint8_t *blocks0 = input;
227 : 0 : uint32_t rest_len0 = input_len - blocks_len0;
228 : 0 : uint8_t *rest0 = input + blocks_len0;
229 : 0 : uint32_t blocks_n = blocks_n1;
230 : 0 : uint32_t blocks_len = blocks_len0;
231 : 0 : uint8_t *blocks = blocks0;
232 : 0 : uint32_t rest_len = rest_len0;
233 : 0 : uint8_t *rest = rest0;
234 : 0 : Hacl_Hash_SHA1_legacy_update_multi(s, blocks, blocks_n);
235 : 0 : Hacl_Hash_SHA1_legacy_update_last(s, (uint64_t)blocks_len, rest, rest_len);
236 : 0 : Hacl_Hash_Core_SHA1_legacy_finish(s, dst);
237 : 0 : }
238 : :
239 : 0 : Hacl_Streaming_MD_state_32 *Hacl_Streaming_SHA1_legacy_create_in(void)
240 : : {
241 : 0 : uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC((uint32_t)64U, sizeof (uint8_t));
242 : 0 : uint32_t *block_state = (uint32_t *)KRML_HOST_CALLOC((uint32_t)5U, sizeof (uint32_t));
243 : : Hacl_Streaming_MD_state_32
244 : 0 : s = { .block_state = block_state, .buf = buf, .total_len = (uint64_t)(uint32_t)0U };
245 : : Hacl_Streaming_MD_state_32
246 : 0 : *p = (Hacl_Streaming_MD_state_32 *)KRML_HOST_MALLOC(sizeof (Hacl_Streaming_MD_state_32));
247 : 0 : p[0U] = s;
248 : 0 : Hacl_Hash_Core_SHA1_legacy_init(block_state);
249 : 0 : return p;
250 : : }
251 : :
252 : 0 : void Hacl_Streaming_SHA1_legacy_init(Hacl_Streaming_MD_state_32 *s)
253 : : {
254 : 0 : Hacl_Streaming_MD_state_32 scrut = *s;
255 : 0 : uint8_t *buf = scrut.buf;
256 : 0 : uint32_t *block_state = scrut.block_state;
257 : 0 : Hacl_Hash_Core_SHA1_legacy_init(block_state);
258 : : Hacl_Streaming_MD_state_32
259 : 0 : tmp = { .block_state = block_state, .buf = buf, .total_len = (uint64_t)(uint32_t)0U };
260 : 0 : s[0U] = tmp;
261 : 0 : }
262 : :
263 : : /**
264 : : 0 = success, 1 = max length exceeded
265 : : */
266 : : uint32_t
267 : 0 : Hacl_Streaming_SHA1_legacy_update(Hacl_Streaming_MD_state_32 *p, uint8_t *data, uint32_t len)
268 : : {
269 : 0 : Hacl_Streaming_MD_state_32 s = *p;
270 : 0 : uint64_t total_len = s.total_len;
271 [ # # ]: 0 : if ((uint64_t)len > (uint64_t)2305843009213693951U - total_len)
272 : : {
273 : 0 : return (uint32_t)1U;
274 : : }
275 : : uint32_t sz;
276 [ # # # # ]: 0 : if (total_len % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len > (uint64_t)0U)
277 : : {
278 : 0 : sz = (uint32_t)64U;
279 : : }
280 : : else
281 : : {
282 : 0 : sz = (uint32_t)(total_len % (uint64_t)(uint32_t)64U);
283 : : }
284 [ # # ]: 0 : if (len <= (uint32_t)64U - sz)
285 : : {
286 : 0 : Hacl_Streaming_MD_state_32 s1 = *p;
287 : 0 : uint32_t *block_state1 = s1.block_state;
288 : 0 : uint8_t *buf = s1.buf;
289 : 0 : uint64_t total_len1 = s1.total_len;
290 : : uint32_t sz1;
291 [ # # # # ]: 0 : if (total_len1 % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len1 > (uint64_t)0U)
292 : : {
293 : 0 : sz1 = (uint32_t)64U;
294 : : }
295 : : else
296 : : {
297 : 0 : sz1 = (uint32_t)(total_len1 % (uint64_t)(uint32_t)64U);
298 : : }
299 : 0 : uint8_t *buf2 = buf + sz1;
300 : 0 : memcpy(buf2, data, len * sizeof (uint8_t));
301 : 0 : uint64_t total_len2 = total_len1 + (uint64_t)len;
302 : : *p
303 : 0 : =
304 : : (
305 : : (Hacl_Streaming_MD_state_32){
306 : : .block_state = block_state1,
307 : : .buf = buf,
308 : : .total_len = total_len2
309 : : }
310 : : );
311 : : }
312 [ # # ]: 0 : else if (sz == (uint32_t)0U)
313 : : {
314 : 0 : Hacl_Streaming_MD_state_32 s1 = *p;
315 : 0 : uint32_t *block_state1 = s1.block_state;
316 : 0 : uint8_t *buf = s1.buf;
317 : 0 : uint64_t total_len1 = s1.total_len;
318 : : uint32_t sz1;
319 [ # # # # ]: 0 : if (total_len1 % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len1 > (uint64_t)0U)
320 : : {
321 : 0 : sz1 = (uint32_t)64U;
322 : : }
323 : : else
324 : : {
325 : 0 : sz1 = (uint32_t)(total_len1 % (uint64_t)(uint32_t)64U);
326 : : }
327 [ # # ]: 0 : if (!(sz1 == (uint32_t)0U))
328 : : {
329 : 0 : Hacl_Hash_SHA1_legacy_update_multi(block_state1, buf, (uint32_t)1U);
330 : : }
331 : : uint32_t ite;
332 [ # # # # ]: 0 : if ((uint64_t)len % (uint64_t)(uint32_t)64U == (uint64_t)0U && (uint64_t)len > (uint64_t)0U)
333 : : {
334 : 0 : ite = (uint32_t)64U;
335 : : }
336 : : else
337 : : {
338 : 0 : ite = (uint32_t)((uint64_t)len % (uint64_t)(uint32_t)64U);
339 : : }
340 : 0 : uint32_t n_blocks = (len - ite) / (uint32_t)64U;
341 : 0 : uint32_t data1_len = n_blocks * (uint32_t)64U;
342 : 0 : uint32_t data2_len = len - data1_len;
343 : 0 : uint8_t *data1 = data;
344 : 0 : uint8_t *data2 = data + data1_len;
345 : 0 : Hacl_Hash_SHA1_legacy_update_multi(block_state1, data1, data1_len / (uint32_t)64U);
346 : 0 : uint8_t *dst = buf;
347 : 0 : memcpy(dst, data2, data2_len * sizeof (uint8_t));
348 : : *p
349 : 0 : =
350 : : (
351 : : (Hacl_Streaming_MD_state_32){
352 : : .block_state = block_state1,
353 : : .buf = buf,
354 : 0 : .total_len = total_len1 + (uint64_t)len
355 : : }
356 : : );
357 : : }
358 : : else
359 : : {
360 : 0 : uint32_t diff = (uint32_t)64U - sz;
361 : 0 : uint8_t *data1 = data;
362 : 0 : uint8_t *data2 = data + diff;
363 : 0 : Hacl_Streaming_MD_state_32 s1 = *p;
364 : 0 : uint32_t *block_state10 = s1.block_state;
365 : 0 : uint8_t *buf0 = s1.buf;
366 : 0 : uint64_t total_len10 = s1.total_len;
367 : : uint32_t sz10;
368 [ # # # # ]: 0 : if (total_len10 % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len10 > (uint64_t)0U)
369 : : {
370 : 0 : sz10 = (uint32_t)64U;
371 : : }
372 : : else
373 : : {
374 : 0 : sz10 = (uint32_t)(total_len10 % (uint64_t)(uint32_t)64U);
375 : : }
376 : 0 : uint8_t *buf2 = buf0 + sz10;
377 : 0 : memcpy(buf2, data1, diff * sizeof (uint8_t));
378 : 0 : uint64_t total_len2 = total_len10 + (uint64_t)diff;
379 : : *p
380 : 0 : =
381 : : (
382 : : (Hacl_Streaming_MD_state_32){
383 : : .block_state = block_state10,
384 : : .buf = buf0,
385 : : .total_len = total_len2
386 : : }
387 : : );
388 : 0 : Hacl_Streaming_MD_state_32 s10 = *p;
389 : 0 : uint32_t *block_state1 = s10.block_state;
390 : 0 : uint8_t *buf = s10.buf;
391 : 0 : uint64_t total_len1 = s10.total_len;
392 : : uint32_t sz1;
393 [ # # # # ]: 0 : if (total_len1 % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len1 > (uint64_t)0U)
394 : : {
395 : 0 : sz1 = (uint32_t)64U;
396 : : }
397 : : else
398 : : {
399 : 0 : sz1 = (uint32_t)(total_len1 % (uint64_t)(uint32_t)64U);
400 : : }
401 [ # # ]: 0 : if (!(sz1 == (uint32_t)0U))
402 : : {
403 : 0 : Hacl_Hash_SHA1_legacy_update_multi(block_state1, buf, (uint32_t)1U);
404 : : }
405 : : uint32_t ite;
406 : : if
407 : 0 : (
408 : 0 : (uint64_t)(len - diff)
409 : : % (uint64_t)(uint32_t)64U
410 [ # # ]: 0 : == (uint64_t)0U
411 [ # # ]: 0 : && (uint64_t)(len - diff) > (uint64_t)0U
412 : : )
413 : : {
414 : 0 : ite = (uint32_t)64U;
415 : : }
416 : : else
417 : : {
418 : 0 : ite = (uint32_t)((uint64_t)(len - diff) % (uint64_t)(uint32_t)64U);
419 : : }
420 : 0 : uint32_t n_blocks = (len - diff - ite) / (uint32_t)64U;
421 : 0 : uint32_t data1_len = n_blocks * (uint32_t)64U;
422 : 0 : uint32_t data2_len = len - diff - data1_len;
423 : 0 : uint8_t *data11 = data2;
424 : 0 : uint8_t *data21 = data2 + data1_len;
425 : 0 : Hacl_Hash_SHA1_legacy_update_multi(block_state1, data11, data1_len / (uint32_t)64U);
426 : 0 : uint8_t *dst = buf;
427 : 0 : memcpy(dst, data21, data2_len * sizeof (uint8_t));
428 : : *p
429 : 0 : =
430 : : (
431 : : (Hacl_Streaming_MD_state_32){
432 : : .block_state = block_state1,
433 : : .buf = buf,
434 : 0 : .total_len = total_len1 + (uint64_t)(len - diff)
435 : : }
436 : : );
437 : : }
438 : 0 : return (uint32_t)0U;
439 : : }
440 : :
441 : 0 : void Hacl_Streaming_SHA1_legacy_finish(Hacl_Streaming_MD_state_32 *p, uint8_t *dst)
442 : : {
443 : 0 : Hacl_Streaming_MD_state_32 scrut = *p;
444 : 0 : uint32_t *block_state = scrut.block_state;
445 : 0 : uint8_t *buf_ = scrut.buf;
446 : 0 : uint64_t total_len = scrut.total_len;
447 : : uint32_t r;
448 [ # # # # ]: 0 : if (total_len % (uint64_t)(uint32_t)64U == (uint64_t)0U && total_len > (uint64_t)0U)
449 : : {
450 : 0 : r = (uint32_t)64U;
451 : : }
452 : : else
453 : : {
454 : 0 : r = (uint32_t)(total_len % (uint64_t)(uint32_t)64U);
455 : : }
456 : 0 : uint8_t *buf_1 = buf_;
457 : 0 : uint32_t tmp_block_state[5U] = { 0U };
458 : 0 : memcpy(tmp_block_state, block_state, (uint32_t)5U * sizeof (uint32_t));
459 : : uint32_t ite;
460 [ # # # # ]: 0 : if (r % (uint32_t)64U == (uint32_t)0U && r > (uint32_t)0U)
461 : : {
462 : 0 : ite = (uint32_t)64U;
463 : : }
464 : : else
465 : : {
466 : 0 : ite = r % (uint32_t)64U;
467 : : }
468 : 0 : uint8_t *buf_last = buf_1 + r - ite;
469 : 0 : uint8_t *buf_multi = buf_1;
470 : 0 : Hacl_Hash_SHA1_legacy_update_multi(tmp_block_state, buf_multi, (uint32_t)0U);
471 : 0 : uint64_t prev_len_last = total_len - (uint64_t)r;
472 : 0 : Hacl_Hash_SHA1_legacy_update_last(tmp_block_state, prev_len_last, buf_last, r);
473 : 0 : Hacl_Hash_Core_SHA1_legacy_finish(tmp_block_state, dst);
474 : 0 : }
475 : :
476 : 0 : void Hacl_Streaming_SHA1_legacy_free(Hacl_Streaming_MD_state_32 *s)
477 : : {
478 : 0 : Hacl_Streaming_MD_state_32 scrut = *s;
479 : 0 : uint8_t *buf = scrut.buf;
480 : 0 : uint32_t *block_state = scrut.block_state;
481 : 0 : KRML_HOST_FREE(block_state);
482 : 0 : KRML_HOST_FREE(buf);
483 : 0 : KRML_HOST_FREE(s);
484 : 0 : }
485 : :
486 : 0 : Hacl_Streaming_MD_state_32 *Hacl_Streaming_SHA1_legacy_copy(Hacl_Streaming_MD_state_32 *s0)
487 : : {
488 : 0 : Hacl_Streaming_MD_state_32 scrut = *s0;
489 : 0 : uint32_t *block_state0 = scrut.block_state;
490 : 0 : uint8_t *buf0 = scrut.buf;
491 : 0 : uint64_t total_len0 = scrut.total_len;
492 : 0 : uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC((uint32_t)64U, sizeof (uint8_t));
493 : 0 : memcpy(buf, buf0, (uint32_t)64U * sizeof (uint8_t));
494 : 0 : uint32_t *block_state = (uint32_t *)KRML_HOST_CALLOC((uint32_t)5U, sizeof (uint32_t));
495 : 0 : memcpy(block_state, block_state0, (uint32_t)5U * sizeof (uint32_t));
496 : : Hacl_Streaming_MD_state_32
497 : 0 : s = { .block_state = block_state, .buf = buf, .total_len = total_len0 };
498 : : Hacl_Streaming_MD_state_32
499 : 0 : *p = (Hacl_Streaming_MD_state_32 *)KRML_HOST_MALLOC(sizeof (Hacl_Streaming_MD_state_32));
500 : 0 : p[0U] = s;
501 : 0 : return p;
502 : : }
503 : :
504 : 0 : void Hacl_Streaming_SHA1_legacy_hash(uint8_t *input, uint32_t input_len, uint8_t *dst)
505 : : {
506 : 0 : Hacl_Hash_SHA1_legacy_hash(input, input_len, dst);
507 : 0 : }
508 : :
|