source: azure_iot_hub_f767zi/trunk/wolfssl-4.4.0/wolfcrypt/src/sha512.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 34.3 KB
Line 
1/* sha512.c
2 *
3 * Copyright (C) 2006-2020 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23#ifdef HAVE_CONFIG_H
24 #include <config.h>
25#endif
26
27#include <wolfssl/wolfcrypt/settings.h>
28
29#if (defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)) && !defined(WOLFSSL_ARMASM)
30
31#if defined(HAVE_FIPS) && \
32 defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
33
34 /* set NO_WRAPPERS before headers, use direct internal f()s not wrappers */
35 #define FIPS_NO_WRAPPERS
36
37 #ifdef USE_WINDOWS_API
38 #pragma code_seg(".fipsA$k")
39 #pragma const_seg(".fipsB$k")
40 #endif
41#endif
42
43#include <wolfssl/wolfcrypt/sha512.h>
44#include <wolfssl/wolfcrypt/error-crypt.h>
45#include <wolfssl/wolfcrypt/cpuid.h>
46#include <wolfssl/wolfcrypt/hash.h>
47
48/* deprecated USE_SLOW_SHA2 (replaced with USE_SLOW_SHA512) */
49#if defined(USE_SLOW_SHA2) && !defined(USE_SLOW_SHA512)
50 #define USE_SLOW_SHA512
51#endif
52
53/* fips wrapper calls, user can call direct */
54#if defined(HAVE_FIPS) && \
55 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
56
57 #ifdef WOLFSSL_SHA512
58
59 int wc_InitSha512(wc_Sha512* sha)
60 {
61 if (sha == NULL) {
62 return BAD_FUNC_ARG;
63 }
64
65 return InitSha512_fips(sha);
66 }
67 int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devId)
68 {
69 (void)heap;
70 (void)devId;
71 if (sha == NULL) {
72 return BAD_FUNC_ARG;
73 }
74 return InitSha512_fips(sha);
75 }
76 int wc_Sha512Update(wc_Sha512* sha, const byte* data, word32 len)
77 {
78 if (sha == NULL || (data == NULL && len > 0)) {
79 return BAD_FUNC_ARG;
80 }
81
82 return Sha512Update_fips(sha, data, len);
83 }
84 int wc_Sha512Final(wc_Sha512* sha, byte* out)
85 {
86 if (sha == NULL || out == NULL) {
87 return BAD_FUNC_ARG;
88 }
89
90 return Sha512Final_fips(sha, out);
91 }
92 void wc_Sha512Free(wc_Sha512* sha)
93 {
94 (void)sha;
95 /* Not supported in FIPS */
96 }
97 #endif
98
99 #if defined(WOLFSSL_SHA384) || defined(HAVE_AESGCM)
100 int wc_InitSha384(wc_Sha384* sha)
101 {
102 if (sha == NULL) {
103 return BAD_FUNC_ARG;
104 }
105 return InitSha384_fips(sha);
106 }
107 int wc_InitSha384_ex(wc_Sha384* sha, void* heap, int devId)
108 {
109 (void)heap;
110 (void)devId;
111 if (sha == NULL) {
112 return BAD_FUNC_ARG;
113 }
114 return InitSha384_fips(sha);
115 }
116 int wc_Sha384Update(wc_Sha384* sha, const byte* data, word32 len)
117 {
118 if (sha == NULL || (data == NULL && len > 0)) {
119 return BAD_FUNC_ARG;
120 }
121 return Sha384Update_fips(sha, data, len);
122 }
123 int wc_Sha384Final(wc_Sha384* sha, byte* out)
124 {
125 if (sha == NULL || out == NULL) {
126 return BAD_FUNC_ARG;
127 }
128 return Sha384Final_fips(sha, out);
129 }
130 void wc_Sha384Free(wc_Sha384* sha)
131 {
132 (void)sha;
133 /* Not supported in FIPS */
134 }
135 #endif /* WOLFSSL_SHA384 || HAVE_AESGCM */
136
137#else /* else build without fips, or for FIPS v2 */
138
139#include <wolfssl/wolfcrypt/logging.h>
140
141#ifdef NO_INLINE
142 #include <wolfssl/wolfcrypt/misc.h>
143#else
144 #define WOLFSSL_MISC_INCLUDED
145 #include <wolfcrypt/src/misc.c>
146#endif
147
148
149#if defined(USE_INTEL_SPEEDUP)
150 #if defined(__GNUC__) && ((__GNUC__ < 4) || \
151 (__GNUC__ == 4 && __GNUC_MINOR__ <= 8))
152 #undef NO_AVX2_SUPPORT
153 #define NO_AVX2_SUPPORT
154 #endif
155 #if defined(__clang__) && ((__clang_major__ < 3) || \
156 (__clang_major__ == 3 && __clang_minor__ <= 5))
157 #define NO_AVX2_SUPPORT
158 #elif defined(__clang__) && defined(NO_AVX2_SUPPORT)
159 #undef NO_AVX2_SUPPORT
160 #endif
161
162 #define HAVE_INTEL_AVX1
163 #ifndef NO_AVX2_SUPPORT
164 #define HAVE_INTEL_AVX2
165 #endif
166#endif
167
168#if defined(HAVE_INTEL_AVX1)
169 /* #define DEBUG_XMM */
170#endif
171
172#if defined(HAVE_INTEL_AVX2)
173 #define HAVE_INTEL_RORX
174 /* #define DEBUG_YMM */
175#endif
176
177#if defined(HAVE_BYTEREVERSE64) && \
178 !defined(HAVE_INTEL_AVX1) && !defined(HAVE_INTEL_AVX2)
179 #define ByteReverseWords64(out, in, size) ByteReverseWords64_1(out, size)
180 #define ByteReverseWords64_1(buf, size) \
181 { unsigned int i ;\
182 for(i=0; i< size/sizeof(word64); i++){\
183 __asm__ volatile("bswapq %0":"+r"(buf[i])::) ;\
184 }\
185 }
186#endif
187
188#if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH)
189 /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */
190
191#else
192
193#ifdef WOLFSSL_SHA512
194
195static int InitSha512(wc_Sha512* sha512)
196{
197 if (sha512 == NULL)
198 return BAD_FUNC_ARG;
199
200 sha512->digest[0] = W64LIT(0x6a09e667f3bcc908);
201 sha512->digest[1] = W64LIT(0xbb67ae8584caa73b);
202 sha512->digest[2] = W64LIT(0x3c6ef372fe94f82b);
203 sha512->digest[3] = W64LIT(0xa54ff53a5f1d36f1);
204 sha512->digest[4] = W64LIT(0x510e527fade682d1);
205 sha512->digest[5] = W64LIT(0x9b05688c2b3e6c1f);
206 sha512->digest[6] = W64LIT(0x1f83d9abfb41bd6b);
207 sha512->digest[7] = W64LIT(0x5be0cd19137e2179);
208
209 sha512->buffLen = 0;
210 sha512->loLen = 0;
211 sha512->hiLen = 0;
212
213#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
214 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
215
216 sha512->ctx.sha_type = SHA2_512;
217 /* always start firstblock = 1 when using hw engine */
218 sha512->ctx.isfirstblock = 1;
219 if(sha512->ctx.mode == ESP32_SHA_HW) {
220 /* release hw */
221 esp_sha_hw_unlock();
222 }
223 /* always set mode as INIT
224 * whether using HW or SW is determined at first call of update()
225 */
226 sha512->ctx.mode = ESP32_SHA_INIT;
227#endif
228#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
229 sha512->flags = 0;
230#endif
231 return 0;
232}
233
234#endif /* WOLFSSL_SHA512 */
235
236/* Hardware Acceleration */
237#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
238
239#ifdef WOLFSSL_SHA512
240
241 /*****
242 Intel AVX1/AVX2 Macro Control Structure
243
244 #if defined(HAVE_INteL_SPEEDUP)
245 #define HAVE_INTEL_AVX1
246 #define HAVE_INTEL_AVX2
247 #endif
248
249 int InitSha512(wc_Sha512* sha512) {
250 Save/Recover XMM, YMM
251 ...
252
253 Check Intel AVX cpuid flags
254 }
255
256 #if defined(HAVE_INTEL_AVX1)|| defined(HAVE_INTEL_AVX2)
257 Transform_Sha512_AVX1(); # Function prototype
258 Transform_Sha512_AVX2(); #
259 #endif
260
261 _Transform_Sha512() { # Native Transform Function body
262
263 }
264
265 int Sha512Update() {
266 Save/Recover XMM, YMM
267 ...
268 }
269
270 int Sha512Final() {
271 Save/Recover XMM, YMM
272 ...
273 }
274
275
276 #if defined(HAVE_INTEL_AVX1)
277
278 XMM Instructions/INLINE asm Definitions
279
280 #endif
281
282 #if defined(HAVE_INTEL_AVX2)
283
284 YMM Instructions/INLINE asm Definitions
285
286 #endif
287
288 #if defnied(HAVE_INTEL_AVX1)
289
290 int Transform_Sha512_AVX1() {
291 Stitched Message Sched/Round
292 }
293
294 #endif
295
296 #if defnied(HAVE_INTEL_AVX2)
297
298 int Transform_Sha512_AVX2() {
299 Stitched Message Sched/Round
300 }
301 #endif
302
303 */
304
305
306 /* Each platform needs to query info type 1 from cpuid to see if aesni is
307 * supported. Also, let's setup a macro for proper linkage w/o ABI conflicts
308 */
309
310#ifdef __cplusplus
311 extern "C" {
312#endif
313
314 #if defined(HAVE_INTEL_AVX1)
315 extern int Transform_Sha512_AVX1(wc_Sha512 *sha512);
316 extern int Transform_Sha512_AVX1_Len(wc_Sha512 *sha512, word32 len);
317 #endif
318 #if defined(HAVE_INTEL_AVX2)
319 extern int Transform_Sha512_AVX2(wc_Sha512 *sha512);
320 extern int Transform_Sha512_AVX2_Len(wc_Sha512 *sha512, word32 len);
321 #if defined(HAVE_INTEL_RORX)
322 extern int Transform_Sha512_AVX1_RORX(wc_Sha512 *sha512);
323 extern int Transform_Sha512_AVX1_RORX_Len(wc_Sha512 *sha512,
324 word32 len);
325 extern int Transform_Sha512_AVX2_RORX(wc_Sha512 *sha512);
326 extern int Transform_Sha512_AVX2_RORX_Len(wc_Sha512 *sha512,
327 word32 len);
328 #endif
329 #endif
330
331#ifdef __cplusplus
332 } /* extern "C" */
333#endif
334
335 static int _Transform_Sha512(wc_Sha512 *sha512);
336 static int (*Transform_Sha512_p)(wc_Sha512* sha512) = _Transform_Sha512;
337 static int (*Transform_Sha512_Len_p)(wc_Sha512* sha512, word32 len) = NULL;
338 static int transform_check = 0;
339 static int intel_flags;
340 #define Transform_Sha512(sha512) (*Transform_Sha512_p)(sha512)
341 #define Transform_Sha512_Len(sha512, len) \
342 (*Transform_Sha512_Len_p)(sha512, len)
343
344 static void Sha512_SetTransform()
345 {
346 if (transform_check)
347 return;
348
349 intel_flags = cpuid_get_flags();
350
351 #if defined(HAVE_INTEL_AVX2)
352 if (IS_INTEL_AVX2(intel_flags)) {
353 #ifdef HAVE_INTEL_RORX
354 if (IS_INTEL_BMI2(intel_flags)) {
355 Transform_Sha512_p = Transform_Sha512_AVX2_RORX;
356 Transform_Sha512_Len_p = Transform_Sha512_AVX2_RORX_Len;
357 }
358 else
359 #endif
360 if (1) {
361 Transform_Sha512_p = Transform_Sha512_AVX2;
362 Transform_Sha512_Len_p = Transform_Sha512_AVX2_Len;
363 }
364 #ifdef HAVE_INTEL_RORX
365 else {
366 Transform_Sha512_p = Transform_Sha512_AVX1_RORX;
367 Transform_Sha512_Len_p = Transform_Sha512_AVX1_RORX_Len;
368 }
369 #endif
370 }
371 else
372 #endif
373 #if defined(HAVE_INTEL_AVX1)
374 if (IS_INTEL_AVX1(intel_flags)) {
375 Transform_Sha512_p = Transform_Sha512_AVX1;
376 Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len;
377 }
378 else
379 #endif
380 Transform_Sha512_p = _Transform_Sha512;
381
382 transform_check = 1;
383 }
384#endif /* WOLFSSL_SHA512 */
385
386#else
387 #define Transform_Sha512(sha512) _Transform_Sha512(sha512)
388
389#endif
390
391#ifdef WOLFSSL_SHA512
392
393int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
394{
395 int ret = 0;
396
397 if (sha512 == NULL)
398 return BAD_FUNC_ARG;
399
400 sha512->heap = heap;
401
402 ret = InitSha512(sha512);
403 if (ret != 0)
404 return ret;
405
406#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
407 Sha512_SetTransform();
408#endif
409
410#ifdef WOLFSSL_SMALL_STACK_CACHE
411 sha512->W = NULL;
412#endif
413
414#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
415 ret = wolfAsync_DevCtxInit(&sha512->asyncDev,
416 WOLFSSL_ASYNC_MARKER_SHA512, sha512->heap, devId);
417#else
418 (void)devId;
419#endif /* WOLFSSL_ASYNC_CRYPT */
420
421 return ret;
422}
423
424#endif /* WOLFSSL_SHA512 */
425
426
427static const word64 K512[80] = {
428 W64LIT(0x428a2f98d728ae22), W64LIT(0x7137449123ef65cd),
429 W64LIT(0xb5c0fbcfec4d3b2f), W64LIT(0xe9b5dba58189dbbc),
430 W64LIT(0x3956c25bf348b538), W64LIT(0x59f111f1b605d019),
431 W64LIT(0x923f82a4af194f9b), W64LIT(0xab1c5ed5da6d8118),
432 W64LIT(0xd807aa98a3030242), W64LIT(0x12835b0145706fbe),
433 W64LIT(0x243185be4ee4b28c), W64LIT(0x550c7dc3d5ffb4e2),
434 W64LIT(0x72be5d74f27b896f), W64LIT(0x80deb1fe3b1696b1),
435 W64LIT(0x9bdc06a725c71235), W64LIT(0xc19bf174cf692694),
436 W64LIT(0xe49b69c19ef14ad2), W64LIT(0xefbe4786384f25e3),
437 W64LIT(0x0fc19dc68b8cd5b5), W64LIT(0x240ca1cc77ac9c65),
438 W64LIT(0x2de92c6f592b0275), W64LIT(0x4a7484aa6ea6e483),
439 W64LIT(0x5cb0a9dcbd41fbd4), W64LIT(0x76f988da831153b5),
440 W64LIT(0x983e5152ee66dfab), W64LIT(0xa831c66d2db43210),
441 W64LIT(0xb00327c898fb213f), W64LIT(0xbf597fc7beef0ee4),
442 W64LIT(0xc6e00bf33da88fc2), W64LIT(0xd5a79147930aa725),
443 W64LIT(0x06ca6351e003826f), W64LIT(0x142929670a0e6e70),
444 W64LIT(0x27b70a8546d22ffc), W64LIT(0x2e1b21385c26c926),
445 W64LIT(0x4d2c6dfc5ac42aed), W64LIT(0x53380d139d95b3df),
446 W64LIT(0x650a73548baf63de), W64LIT(0x766a0abb3c77b2a8),
447 W64LIT(0x81c2c92e47edaee6), W64LIT(0x92722c851482353b),
448 W64LIT(0xa2bfe8a14cf10364), W64LIT(0xa81a664bbc423001),
449 W64LIT(0xc24b8b70d0f89791), W64LIT(0xc76c51a30654be30),
450 W64LIT(0xd192e819d6ef5218), W64LIT(0xd69906245565a910),
451 W64LIT(0xf40e35855771202a), W64LIT(0x106aa07032bbd1b8),
452 W64LIT(0x19a4c116b8d2d0c8), W64LIT(0x1e376c085141ab53),
453 W64LIT(0x2748774cdf8eeb99), W64LIT(0x34b0bcb5e19b48a8),
454 W64LIT(0x391c0cb3c5c95a63), W64LIT(0x4ed8aa4ae3418acb),
455 W64LIT(0x5b9cca4f7763e373), W64LIT(0x682e6ff3d6b2b8a3),
456 W64LIT(0x748f82ee5defb2fc), W64LIT(0x78a5636f43172f60),
457 W64LIT(0x84c87814a1f0ab72), W64LIT(0x8cc702081a6439ec),
458 W64LIT(0x90befffa23631e28), W64LIT(0xa4506cebde82bde9),
459 W64LIT(0xbef9a3f7b2c67915), W64LIT(0xc67178f2e372532b),
460 W64LIT(0xca273eceea26619c), W64LIT(0xd186b8c721c0c207),
461 W64LIT(0xeada7dd6cde0eb1e), W64LIT(0xf57d4f7fee6ed178),
462 W64LIT(0x06f067aa72176fba), W64LIT(0x0a637dc5a2c898a6),
463 W64LIT(0x113f9804bef90dae), W64LIT(0x1b710b35131c471b),
464 W64LIT(0x28db77f523047d84), W64LIT(0x32caab7b40c72493),
465 W64LIT(0x3c9ebe0a15c9bebc), W64LIT(0x431d67c49c100d4c),
466 W64LIT(0x4cc5d4becb3e42b6), W64LIT(0x597f299cfc657e2a),
467 W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817)
468};
469
470#define blk0(i) (W[i] = sha512->buffer[i])
471
472#define blk2(i) (\
473 W[ i & 15] += \
474 s1(W[(i-2) & 15])+ \
475 W[(i-7) & 15] + \
476 s0(W[(i-15) & 15]) \
477 )
478
479#define Ch(x,y,z) (z ^ (x & (y ^ z)))
480#define Maj(x,y,z) ((x & y) | (z & (x | y)))
481
482#define a(i) T[(0-i) & 7]
483#define b(i) T[(1-i) & 7]
484#define c(i) T[(2-i) & 7]
485#define d(i) T[(3-i) & 7]
486#define e(i) T[(4-i) & 7]
487#define f(i) T[(5-i) & 7]
488#define g(i) T[(6-i) & 7]
489#define h(i) T[(7-i) & 7]
490
491#define S0(x) (rotrFixed64(x,28) ^ rotrFixed64(x,34) ^ rotrFixed64(x,39))
492#define S1(x) (rotrFixed64(x,14) ^ rotrFixed64(x,18) ^ rotrFixed64(x,41))
493#define s0(x) (rotrFixed64(x,1) ^ rotrFixed64(x,8) ^ (x>>7))
494#define s1(x) (rotrFixed64(x,19) ^ rotrFixed64(x,61) ^ (x>>6))
495
496#define R(i) \
497 h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j ? blk2(i) : blk0(i)); \
498 d(i) += h(i); \
499 h(i) += S0(a(i)) + Maj(a(i),b(i),c(i))
500
501static int _Transform_Sha512(wc_Sha512* sha512)
502{
503 const word64* K = K512;
504 word32 j;
505 word64 T[8];
506
507#ifdef WOLFSSL_SMALL_STACK_CACHE
508 word64* W = sha512->W;
509 if (W == NULL) {
510 W = (word64*) XMALLOC(sizeof(word64) * 16, NULL,
511 DYNAMIC_TYPE_TMP_BUFFER);
512 if (W == NULL)
513 return MEMORY_E;
514 sha512->W = W;
515 }
516#elif defined(WOLFSSL_SMALL_STACK)
517 word64* W;
518 W = (word64*) XMALLOC(sizeof(word64) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
519 if (W == NULL)
520 return MEMORY_E;
521#else
522 word64 W[16];
523#endif
524
525 /* Copy digest to working vars */
526 XMEMCPY(T, sha512->digest, sizeof(T));
527
528#ifdef USE_SLOW_SHA512
529 /* over twice as small, but 50% slower */
530 /* 80 operations, not unrolled */
531 for (j = 0; j < 80; j += 16) {
532 int m;
533 for (m = 0; m < 16; m++) { /* braces needed here for macros {} */
534 R(m);
535 }
536 }
537#else
538 /* 80 operations, partially loop unrolled */
539 for (j = 0; j < 80; j += 16) {
540 R( 0); R( 1); R( 2); R( 3);
541 R( 4); R( 5); R( 6); R( 7);
542 R( 8); R( 9); R(10); R(11);
543 R(12); R(13); R(14); R(15);
544 }
545#endif /* USE_SLOW_SHA512 */
546
547 /* Add the working vars back into digest */
548 sha512->digest[0] += a(0);
549 sha512->digest[1] += b(0);
550 sha512->digest[2] += c(0);
551 sha512->digest[3] += d(0);
552 sha512->digest[4] += e(0);
553 sha512->digest[5] += f(0);
554 sha512->digest[6] += g(0);
555 sha512->digest[7] += h(0);
556
557 /* Wipe variables */
558 ForceZero(W, sizeof(word64) * 16);
559 ForceZero(T, sizeof(T));
560
561#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SMALL_STACK_CACHE)
562 XFREE(W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
563#endif
564
565 return 0;
566}
567
568
569static WC_INLINE void AddLength(wc_Sha512* sha512, word32 len)
570{
571 word64 tmp = sha512->loLen;
572 if ( (sha512->loLen += len) < tmp)
573 sha512->hiLen++; /* carry low to high */
574}
575
576static WC_INLINE int Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
577{
578 int ret = 0;
579 /* do block size increments */
580 byte* local = (byte*)sha512->buffer;
581
582 /* check that internal buffLen is valid */
583 if (sha512->buffLen >= WC_SHA512_BLOCK_SIZE)
584 return BUFFER_E;
585
586 AddLength(sha512, len);
587
588 if (sha512->buffLen > 0) {
589 word32 add = min(len, WC_SHA512_BLOCK_SIZE - sha512->buffLen);
590 if (add > 0) {
591 XMEMCPY(&local[sha512->buffLen], data, add);
592
593 sha512->buffLen += add;
594 data += add;
595 len -= add;
596 }
597
598 if (sha512->buffLen == WC_SHA512_BLOCK_SIZE) {
599 #if defined(LITTLE_ENDIAN_ORDER)
600 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
601 if (!IS_INTEL_AVX1(intel_flags) && !IS_INTEL_AVX2(intel_flags))
602 #endif
603 {
604 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
605 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
606 ByteReverseWords64(sha512->buffer, sha512->buffer,
607 WC_SHA512_BLOCK_SIZE);
608 #endif
609 }
610 #endif
611 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
612 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
613 ret = Transform_Sha512(sha512);
614 #else
615 if(sha512->ctx.mode == ESP32_SHA_INIT) {
616 esp_sha_try_hw_lock(&sha512->ctx);
617 }
618 ret = esp_sha512_process(sha512);
619 if(ret == 0 && sha512->ctx.mode == ESP32_SHA_SW){
620 ret = Transform_Sha512(sha512);
621 }
622 #endif
623 if (ret == 0)
624 sha512->buffLen = 0;
625 else
626 len = 0;
627 }
628 }
629
630#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
631 if (Transform_Sha512_Len_p != NULL) {
632 word32 blocksLen = len & ~(WC_SHA512_BLOCK_SIZE-1);
633
634 if (blocksLen > 0) {
635 sha512->data = data;
636 /* Byte reversal performed in function if required. */
637 Transform_Sha512_Len(sha512, blocksLen);
638 data += blocksLen;
639 len -= blocksLen;
640 }
641 }
642 else
643#endif
644#if !defined(LITTLE_ENDIAN_ORDER) || defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
645 {
646 while (len >= WC_SHA512_BLOCK_SIZE) {
647 XMEMCPY(local, data, WC_SHA512_BLOCK_SIZE);
648
649 data += WC_SHA512_BLOCK_SIZE;
650 len -= WC_SHA512_BLOCK_SIZE;
651
652 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
653 if (!IS_INTEL_AVX1(intel_flags) && !IS_INTEL_AVX2(intel_flags))
654 {
655 ByteReverseWords64(sha512->buffer, sha512->buffer,
656 WC_SHA512_BLOCK_SIZE);
657 }
658 #endif
659 /* Byte reversal performed in function if required. */
660 ret = Transform_Sha512(sha512);
661 if (ret != 0)
662 break;
663 }
664 }
665#else
666 {
667 while (len >= WC_SHA512_BLOCK_SIZE) {
668 XMEMCPY(local, data, WC_SHA512_BLOCK_SIZE);
669
670 data += WC_SHA512_BLOCK_SIZE;
671 len -= WC_SHA512_BLOCK_SIZE;
672 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
673 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
674 ByteReverseWords64(sha512->buffer, sha512->buffer,
675 WC_SHA512_BLOCK_SIZE);
676 #endif
677 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
678 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
679 ret = Transform_Sha512(sha512);
680 #else
681 if(sha512->ctx.mode == ESP32_SHA_INIT) {
682 esp_sha_try_hw_lock(&sha512->ctx);
683 }
684 ret = esp_sha512_process(sha512);
685 if(ret == 0 && sha512->ctx.mode == ESP32_SHA_SW){
686 ret = Transform_Sha512(sha512);
687 }
688 #endif
689 if (ret != 0)
690 break;
691 }
692 }
693#endif
694
695 if (len > 0) {
696 XMEMCPY(local, data, len);
697 sha512->buffLen = len;
698 }
699
700 return ret;
701}
702
703#ifdef WOLFSSL_SHA512
704
705int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
706{
707 if (sha512 == NULL || (data == NULL && len > 0)) {
708 return BAD_FUNC_ARG;
709 }
710
711#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
712 if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
713 #if defined(HAVE_INTEL_QA)
714 return IntelQaSymSha512(&sha512->asyncDev, NULL, data, len);
715 #endif
716 }
717#endif /* WOLFSSL_ASYNC_CRYPT */
718
719 return Sha512Update(sha512, data, len);
720}
721
722#endif /* WOLFSSL_SHA512 */
723
724#endif /* WOLFSSL_IMX6_CAAM */
725
726static WC_INLINE int Sha512Final(wc_Sha512* sha512)
727{
728 byte* local = (byte*)sha512->buffer;
729 int ret;
730
731 if (sha512 == NULL) {
732 return BAD_FUNC_ARG;
733 }
734
735 local[sha512->buffLen++] = 0x80; /* add 1 */
736
737 /* pad with zeros */
738 if (sha512->buffLen > WC_SHA512_PAD_SIZE) {
739 XMEMSET(&local[sha512->buffLen], 0, WC_SHA512_BLOCK_SIZE - sha512->buffLen);
740 sha512->buffLen += WC_SHA512_BLOCK_SIZE - sha512->buffLen;
741#if defined(LITTLE_ENDIAN_ORDER)
742 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
743 if (!IS_INTEL_AVX1(intel_flags) && !IS_INTEL_AVX2(intel_flags))
744 #endif
745 {
746
747 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
748 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
749 ByteReverseWords64(sha512->buffer,sha512->buffer,
750 WC_SHA512_BLOCK_SIZE);
751 #endif
752 }
753#endif /* LITTLE_ENDIAN_ORDER */
754#if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
755 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
756 ret = Transform_Sha512(sha512);
757#else
758 if(sha512->ctx.mode == ESP32_SHA_INIT) {
759 esp_sha_try_hw_lock(&sha512->ctx);
760 }
761 ret = esp_sha512_process(sha512);
762 if(ret == 0 && sha512->ctx.mode == ESP32_SHA_SW){
763 ret = Transform_Sha512(sha512);
764 }
765#endif
766 if (ret != 0)
767 return ret;
768
769 sha512->buffLen = 0;
770 }
771 XMEMSET(&local[sha512->buffLen], 0, WC_SHA512_PAD_SIZE - sha512->buffLen);
772
773 /* put lengths in bits */
774 sha512->hiLen = (sha512->loLen >> (8 * sizeof(sha512->loLen) - 3)) +
775 (sha512->hiLen << 3);
776 sha512->loLen = sha512->loLen << 3;
777
778 /* store lengths */
779#if defined(LITTLE_ENDIAN_ORDER)
780 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
781 if (!IS_INTEL_AVX1(intel_flags) && !IS_INTEL_AVX2(intel_flags))
782 #endif
783 #if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
784 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
785 ByteReverseWords64(sha512->buffer, sha512->buffer, WC_SHA512_PAD_SIZE);
786 #endif
787#endif
788 /* ! length ordering dependent on digest endian type ! */
789
790#if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
791 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
792 sha512->buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64) - 2] = sha512->hiLen;
793 sha512->buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64) - 1] = sha512->loLen;
794#endif
795
796#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
797 if (IS_INTEL_AVX1(intel_flags) || IS_INTEL_AVX2(intel_flags))
798 ByteReverseWords64(&(sha512->buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64) - 2]),
799 &(sha512->buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64) - 2]),
800 WC_SHA512_BLOCK_SIZE - WC_SHA512_PAD_SIZE);
801#endif
802#if !defined(WOLFSSL_ESP32WROOM32_CRYPT) || \
803 defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
804 ret = Transform_Sha512(sha512);
805#else
806 if(sha512->ctx.mode == ESP32_SHA_INIT) {
807 esp_sha_try_hw_lock(&sha512->ctx);
808 }
809 ret = esp_sha512_digest_process(sha512, 1);
810 if(ret == 0 && sha512->ctx.mode == ESP32_SHA_SW) {
811 ret = Transform_Sha512(sha512);
812 }
813#endif
814 if (ret != 0)
815 return ret;
816
817 #ifdef LITTLE_ENDIAN_ORDER
818 ByteReverseWords64(sha512->digest, sha512->digest, WC_SHA512_DIGEST_SIZE);
819 #endif
820
821 return 0;
822}
823
824#ifdef WOLFSSL_SHA512
825
826int wc_Sha512FinalRaw(wc_Sha512* sha512, byte* hash)
827{
828#ifdef LITTLE_ENDIAN_ORDER
829 word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
830#endif
831
832 if (sha512 == NULL || hash == NULL) {
833 return BAD_FUNC_ARG;
834 }
835
836#ifdef LITTLE_ENDIAN_ORDER
837 ByteReverseWords64((word64*)digest, (word64*)sha512->digest,
838 WC_SHA512_DIGEST_SIZE);
839 XMEMCPY(hash, digest, WC_SHA512_DIGEST_SIZE);
840#else
841 XMEMCPY(hash, sha512->digest, WC_SHA512_DIGEST_SIZE);
842#endif
843
844 return 0;
845}
846
847int wc_Sha512Final(wc_Sha512* sha512, byte* hash)
848{
849 int ret;
850
851 if (sha512 == NULL || hash == NULL) {
852 return BAD_FUNC_ARG;
853 }
854
855#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
856 if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
857 #if defined(HAVE_INTEL_QA)
858 return IntelQaSymSha512(&sha512->asyncDev, hash, NULL,
859 WC_SHA512_DIGEST_SIZE);
860 #endif
861 }
862#endif /* WOLFSSL_ASYNC_CRYPT */
863
864 ret = Sha512Final(sha512);
865 if (ret != 0)
866 return ret;
867
868 XMEMCPY(hash, sha512->digest, WC_SHA512_DIGEST_SIZE);
869
870 return InitSha512(sha512); /* reset state */
871}
872
873int wc_InitSha512(wc_Sha512* sha512)
874{
875 return wc_InitSha512_ex(sha512, NULL, INVALID_DEVID);
876}
877
878void wc_Sha512Free(wc_Sha512* sha512)
879{
880 if (sha512 == NULL)
881 return;
882
883#ifdef WOLFSSL_SMALL_STACK_CACHE
884 if (sha512->W != NULL) {
885 XFREE(sha512->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
886 sha512->W = NULL;
887 }
888#endif
889
890#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
891 wolfAsync_DevCtxFree(&sha512->asyncDev, WOLFSSL_ASYNC_MARKER_SHA512);
892#endif /* WOLFSSL_ASYNC_CRYPT */
893}
894
895#endif /* WOLFSSL_SHA512 */
896
897/* -------------------------------------------------------------------------- */
898/* SHA384 */
899/* -------------------------------------------------------------------------- */
900#ifdef WOLFSSL_SHA384
901
902#if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH)
903 /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */
904
905#else
906
907static int InitSha384(wc_Sha384* sha384)
908{
909 if (sha384 == NULL) {
910 return BAD_FUNC_ARG;
911 }
912
913 sha384->digest[0] = W64LIT(0xcbbb9d5dc1059ed8);
914 sha384->digest[1] = W64LIT(0x629a292a367cd507);
915 sha384->digest[2] = W64LIT(0x9159015a3070dd17);
916 sha384->digest[3] = W64LIT(0x152fecd8f70e5939);
917 sha384->digest[4] = W64LIT(0x67332667ffc00b31);
918 sha384->digest[5] = W64LIT(0x8eb44a8768581511);
919 sha384->digest[6] = W64LIT(0xdb0c2e0d64f98fa7);
920 sha384->digest[7] = W64LIT(0x47b5481dbefa4fa4);
921
922 sha384->buffLen = 0;
923 sha384->loLen = 0;
924 sha384->hiLen = 0;
925
926#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
927 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
928 sha384->ctx.sha_type = SHA2_384;
929 /* always start firstblock = 1 when using hw engine */
930 sha384->ctx.isfirstblock = 1;
931 if(sha384->ctx.mode == ESP32_SHA_HW) {
932 /* release hw */
933 esp_sha_hw_unlock();
934 }
935 /* always set mode as INIT
936 * whether using HW or SW is determined at first call of update()
937 */
938 sha384->ctx.mode = ESP32_SHA_INIT;
939
940#endif
941#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
942 sha384->flags = 0;
943#endif
944
945 return 0;
946}
947
948int wc_Sha384Update(wc_Sha384* sha384, const byte* data, word32 len)
949{
950 if (sha384 == NULL || (data == NULL && len > 0)) {
951 return BAD_FUNC_ARG;
952 }
953
954#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
955 if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
956 #if defined(HAVE_INTEL_QA)
957 return IntelQaSymSha384(&sha384->asyncDev, NULL, data, len);
958 #endif
959 }
960#endif /* WOLFSSL_ASYNC_CRYPT */
961
962 return Sha512Update((wc_Sha512*)sha384, data, len);
963}
964
965
966int wc_Sha384FinalRaw(wc_Sha384* sha384, byte* hash)
967{
968#ifdef LITTLE_ENDIAN_ORDER
969 word64 digest[WC_SHA384_DIGEST_SIZE / sizeof(word64)];
970#endif
971
972 if (sha384 == NULL || hash == NULL) {
973 return BAD_FUNC_ARG;
974 }
975
976#ifdef LITTLE_ENDIAN_ORDER
977 ByteReverseWords64((word64*)digest, (word64*)sha384->digest,
978 WC_SHA384_DIGEST_SIZE);
979 XMEMCPY(hash, digest, WC_SHA384_DIGEST_SIZE);
980#else
981 XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE);
982#endif
983
984 return 0;
985}
986
987int wc_Sha384Final(wc_Sha384* sha384, byte* hash)
988{
989 int ret;
990
991 if (sha384 == NULL || hash == NULL) {
992 return BAD_FUNC_ARG;
993 }
994
995#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
996 if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
997 #if defined(HAVE_INTEL_QA)
998 return IntelQaSymSha384(&sha384->asyncDev, hash, NULL,
999 WC_SHA384_DIGEST_SIZE);
1000 #endif
1001 }
1002#endif /* WOLFSSL_ASYNC_CRYPT */
1003
1004 ret = Sha512Final((wc_Sha512*)sha384);
1005 if (ret != 0)
1006 return ret;
1007
1008 XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE);
1009
1010 return InitSha384(sha384); /* reset state */
1011}
1012
1013int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
1014{
1015 int ret;
1016
1017 if (sha384 == NULL) {
1018 return BAD_FUNC_ARG;
1019 }
1020
1021 sha384->heap = heap;
1022 ret = InitSha384(sha384);
1023 if (ret != 0)
1024 return ret;
1025
1026#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
1027 Sha512_SetTransform();
1028#endif
1029#ifdef WOLFSSL_SMALL_STACK_CACHE
1030 sha384->W = NULL;
1031#endif
1032
1033#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
1034 ret = wolfAsync_DevCtxInit(&sha384->asyncDev, WOLFSSL_ASYNC_MARKER_SHA384,
1035 sha384->heap, devId);
1036#else
1037 (void)devId;
1038#endif /* WOLFSSL_ASYNC_CRYPT */
1039
1040 return ret;
1041}
1042
1043#endif /* WOLFSSL_IMX6_CAAM */
1044
1045int wc_InitSha384(wc_Sha384* sha384)
1046{
1047 return wc_InitSha384_ex(sha384, NULL, INVALID_DEVID);
1048}
1049
1050void wc_Sha384Free(wc_Sha384* sha384)
1051{
1052 if (sha384 == NULL)
1053 return;
1054
1055#ifdef WOLFSSL_SMALL_STACK_CACHE
1056 if (sha384->W != NULL) {
1057 XFREE(sha384->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1058 sha384->W = NULL;
1059 }
1060#endif
1061
1062#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
1063 wolfAsync_DevCtxFree(&sha384->asyncDev, WOLFSSL_ASYNC_MARKER_SHA384);
1064#endif /* WOLFSSL_ASYNC_CRYPT */
1065}
1066
1067#endif /* WOLFSSL_SHA384 */
1068
1069#endif /* HAVE_FIPS */
1070
1071#ifdef WOLFSSL_SHA512
1072
1073int wc_Sha512GetHash(wc_Sha512* sha512, byte* hash)
1074{
1075 int ret;
1076 wc_Sha512 tmpSha512;
1077
1078 if (sha512 == NULL || hash == NULL)
1079 return BAD_FUNC_ARG;
1080
1081#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1082 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1083 if(sha512->ctx.mode == ESP32_SHA_INIT) {
1084 esp_sha_try_hw_lock(&sha512->ctx);
1085 }
1086 if(sha512->ctx.mode != ESP32_SHA_SW)
1087 esp_sha512_digest_process(sha512, 0);
1088#endif
1089
1090 ret = wc_Sha512Copy(sha512, &tmpSha512);
1091 if (ret == 0) {
1092 ret = wc_Sha512Final(&tmpSha512, hash);
1093#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1094 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1095 sha512->ctx.mode = ESP32_SHA_SW;;
1096#endif
1097 wc_Sha512Free(&tmpSha512);
1098 }
1099 return ret;
1100}
1101
1102int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
1103{
1104 int ret = 0;
1105
1106 if (src == NULL || dst == NULL)
1107 return BAD_FUNC_ARG;
1108
1109 XMEMCPY(dst, src, sizeof(wc_Sha512));
1110#ifdef WOLFSSL_SMALL_STACK_CACHE
1111 dst->W = NULL;
1112#endif
1113
1114#ifdef WOLFSSL_ASYNC_CRYPT
1115 ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
1116#endif
1117#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1118 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1119 dst->ctx.mode = src->ctx.mode;
1120 dst->ctx.isfirstblock = src->ctx.isfirstblock;
1121 dst->ctx.sha_type = src->ctx.sha_type;
1122#endif
1123#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
1124 dst->flags |= WC_HASH_FLAG_ISCOPY;
1125#endif
1126
1127 return ret;
1128}
1129
1130#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
1131int wc_Sha512SetFlags(wc_Sha512* sha512, word32 flags)
1132{
1133 if (sha512) {
1134 sha512->flags = flags;
1135 }
1136 return 0;
1137}
1138int wc_Sha512GetFlags(wc_Sha512* sha512, word32* flags)
1139{
1140 if (sha512 && flags) {
1141 *flags = sha512->flags;
1142 }
1143 return 0;
1144}
1145#endif
1146
1147#endif /* WOLFSSL_SHA512 */
1148
1149#ifdef WOLFSSL_SHA384
1150
1151int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash)
1152{
1153 int ret;
1154 wc_Sha384 tmpSha384;
1155
1156 if (sha384 == NULL || hash == NULL)
1157 return BAD_FUNC_ARG;
1158#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1159 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1160 if(sha384->ctx.mode == ESP32_SHA_INIT) {
1161 esp_sha_try_hw_lock(&sha384->ctx);
1162 }
1163 if(sha384->ctx.mode != ESP32_SHA_SW) {
1164 esp_sha512_digest_process(sha384, 0);
1165 }
1166#endif
1167 ret = wc_Sha384Copy(sha384, &tmpSha384);
1168 if (ret == 0) {
1169 ret = wc_Sha384Final(&tmpSha384, hash);
1170#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1171 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1172 sha384->ctx.mode = ESP32_SHA_SW;
1173#endif
1174 wc_Sha384Free(&tmpSha384);
1175 }
1176 return ret;
1177}
1178int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
1179{
1180 int ret = 0;
1181
1182 if (src == NULL || dst == NULL)
1183 return BAD_FUNC_ARG;
1184
1185 XMEMCPY(dst, src, sizeof(wc_Sha384));
1186#ifdef WOLFSSL_SMALL_STACK_CACHE
1187 dst->W = NULL;
1188#endif
1189
1190#ifdef WOLFSSL_ASYNC_CRYPT
1191 ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
1192#endif
1193#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
1194 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
1195 dst->ctx.mode = src->ctx.mode;
1196 dst->ctx.isfirstblock = src->ctx.isfirstblock;
1197 dst->ctx.sha_type = src->ctx.sha_type;
1198#endif
1199#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
1200 dst->flags |= WC_HASH_FLAG_ISCOPY;
1201#endif
1202
1203 return ret;
1204}
1205
1206#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
1207int wc_Sha384SetFlags(wc_Sha384* sha384, word32 flags)
1208{
1209 if (sha384) {
1210 sha384->flags = flags;
1211 }
1212 return 0;
1213}
1214int wc_Sha384GetFlags(wc_Sha384* sha384, word32* flags)
1215{
1216 if (sha384 && flags) {
1217 *flags = sha384->flags;
1218 }
1219 return 0;
1220}
1221#endif
1222
1223#endif /* WOLFSSL_SHA384 */
1224
1225#endif /* WOLFSSL_SHA512 || WOLFSSL_SHA384 */
Note: See TracBrowser for help on using the repository browser.