1 /* kcapi_hash.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 * KCAPI hash options:
24 *
25 * WOLFSSL_KCAPI_HASH_KEEP: Cache the hash data instead of streaming.
26 * Needed to get the current hash and continue with more data.
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33 #include <wolfssl/wolfcrypt/settings.h>
34
35 #if defined(WOLFSSL_KCAPI_HASH)
36
37 #define FIPS_NO_WRAPPERS
38
39 #include <wolfssl/wolfcrypt/error-crypt.h>
40 #include <wolfssl/wolfcrypt/logging.h>
41 #include <wolfssl/wolfcrypt/port/kcapi/wc_kcapi.h>
42 #include <wolfssl/wolfcrypt/port/kcapi/kcapi_hash.h>
43
44 /* generic KCAPI hash free */
KcapiHashFree(wolfssl_KCAPI_Hash * hash)45 void KcapiHashFree(wolfssl_KCAPI_Hash* hash)
46 {
47 if (hash != NULL) {
48 if (hash->handle != NULL) {
49 kcapi_md_destroy(hash->handle);
50 hash->handle = NULL;
51 }
52
53 #if defined(WOLFSSL_KCAPI_HASH_KEEP)
54 if (hash->msg != NULL) {
55 XFREE(hash->msg, hash->heap, DYNAMIC_TYPE_TMP_BUFFER);
56 hash->msg = NULL;
57 }
58 #endif
59 }
60 }
61
62
63 /* generic hash init for KCAPI, returns 0 on success */
KcapiHashInit(wolfssl_KCAPI_Hash * hash,void * heap,int devId,const char * type)64 static int KcapiHashInit(wolfssl_KCAPI_Hash* hash, void* heap, int devId,
65 const char* type)
66 {
67 int ret = 0;
68
69 if (hash == NULL) {
70 ret = BAD_FUNC_ARG;
71 }
72
73 if (ret == 0) {
74 (void)devId; /* no async for now */
75 XMEMSET(hash, 0, sizeof(wolfssl_KCAPI_Hash));
76 hash->heap = heap;
77 #if defined(WOLFSSL_KCAPI_HASH_KEEP)
78 hash->len = 0;
79 hash->used = 0;
80 hash->msg = NULL;
81 #endif
82 hash->handle = NULL;
83 XSTRNCPY(hash->type, type, sizeof(hash->type)-1);
84 }
85
86 return ret;
87
88 }
89
90
91 /* generic hash update for KCAPI, returns 0 on success */
KcapiHashUpdate(wolfssl_KCAPI_Hash * hash,const byte * in,word32 sz)92 static int KcapiHashUpdate(wolfssl_KCAPI_Hash* hash, const byte* in, word32 sz)
93 {
94 int ret = 0;
95
96 if (hash == NULL || (sz > 0 && in == NULL)) {
97 ret = BAD_FUNC_ARG;
98 }
99
100 #ifdef WOLFSSL_KCAPI_HASH_KEEP
101 if (ret == 0) {
102 /* keep full message to hash at end instead of incremental updates */
103 if (hash->len < hash->used + sz) {
104 if (hash->msg == NULL) {
105 hash->msg = (byte*)XMALLOC(hash->used + sz, hash->heap,
106 DYNAMIC_TYPE_TMP_BUFFER);
107 if (hash->msg == NULL) {
108 ret = MEMORY_E;
109 }
110 }
111 else {
112 byte* pt = (byte*)XREALLOC(hash->msg, hash->used + sz,
113 hash->heap, DYNAMIC_TYPE_TMP_BUFFER);
114 if (pt == NULL) {
115 ret = MEMORY_E;
116 }
117 else {
118 hash->msg = pt;
119 }
120 }
121
122 if (ret == 0) {
123 hash->len = hash->used + sz;
124 }
125 }
126
127 if (ret == 0) {
128 XMEMCPY(hash->msg + hash->used, in, sz);
129 hash->used += sz;
130 }
131 }
132 #else
133 if ((ret == 0) && (hash->handle == NULL)) {
134 ret = kcapi_md_init(&hash->handle, hash->type, 0);
135 }
136 if (ret == 0) {
137 ret = kcapi_md_update(hash->handle, in, sz);
138 if (ret > 0) {
139 ret = 0;
140 }
141 }
142 #endif
143
144 return ret;
145 }
146
147
148 /* generic hash final for KCAPI, return 0 on success */
KcapiHashFinal(wolfssl_KCAPI_Hash * hash,byte * out,word32 outSz,const char * type)149 static int KcapiHashFinal(wolfssl_KCAPI_Hash* hash, byte* out, word32 outSz,
150 const char* type)
151 {
152 int ret = 0;
153 int rc;
154 void* heap = NULL;
155
156 if (hash == NULL || out == NULL) {
157 ret = BAD_FUNC_ARG;
158 }
159
160 if ((ret == 0) && (hash->handle == NULL)) {
161 ret = kcapi_md_init(&hash->handle, hash->type, 0);
162 }
163 if (ret == 0) {
164 heap = hash->heap; /* keep because KcapiHashInit clears the pointer */
165 #ifdef WOLFSSL_KCAPI_HASH_KEEP
166 /* keep full message to out at end instead of incremental updates */
167 ret = kcapi_md_update(hash->handle, hash->msg, hash->used);
168 XFREE(hash->msg, heap, DYNAMIC_TYPE_TMP_BUFFER);
169 hash->msg = NULL;
170 #endif
171
172 if (ret == 0) {
173 ret = kcapi_md_final(hash->handle, out, outSz);
174 }
175
176 KcapiHashFree(hash);
177 rc = KcapiHashInit(hash, heap, 0, type);
178 if (ret >= 0) {
179 ret = rc;
180 }
181 }
182
183 return ret;
184 }
185
186
187 /* generic function to get intermediate hash */
KcapiHashGet(wolfssl_KCAPI_Hash * hash,byte * out,word32 outSz)188 static int KcapiHashGet(wolfssl_KCAPI_Hash* hash, byte* out, word32 outSz)
189 {
190 int ret = 0;
191
192 if (hash == NULL || out == NULL) {
193 ret = BAD_FUNC_ARG;
194 }
195
196 #ifdef WOLFSSL_KCAPI_HASH_KEEP
197 if ((ret == 0) && (hash->handle == NULL)) {
198 ret = kcapi_md_init(&hash->handle, hash->type, 0);
199 }
200 if (ret == 0) {
201 ret = kcapi_md_update(hash->handle, hash->msg, hash->used);
202 if (ret >= 0) {
203 ret = kcapi_md_final(hash->handle, out, outSz);
204 if (ret >= 0) {
205 ret = 0;
206 }
207 }
208 kcapi_md_destroy(hash->handle);
209 hash->handle = NULL;
210 }
211 #else
212 if (ret == 0) {
213 (void)hash;
214 (void)out;
215 (void)outSz;
216
217 WOLFSSL_MSG("Compile with WOLFSSL_KCAPI_HASH_KEEP for this feature");
218 ret = NOT_COMPILED_IN;
219 }
220 #endif
221
222 return ret;
223 }
224
225
226 /* generic struct copy for KCAPI, returns 0 on success */
KcapiHashCopy(wolfssl_KCAPI_Hash * src,wolfssl_KCAPI_Hash * dst)227 static int KcapiHashCopy(wolfssl_KCAPI_Hash* src, wolfssl_KCAPI_Hash* dst)
228 {
229 int ret = 0;
230
231 if (src == NULL || dst == NULL) {
232 ret = BAD_FUNC_ARG;
233 }
234
235 if (ret == 0) {
236 XMEMCPY(dst, src, sizeof(wolfssl_KCAPI_Hash));
237 dst->handle = NULL;
238
239 #ifdef WOLFSSL_KCAPI_HASH_KEEP
240 dst->msg = (byte*)XMALLOC(src->len, dst->heap, DYNAMIC_TYPE_TMP_BUFFER);
241 if (dst->msg == NULL) {
242 ret = MEMORY_E;
243 }
244 }
245 if (ret == 0) {
246 XMEMCPY(dst->msg, src->msg, src->len);
247 #endif
248
249 XMEMCPY(dst->type, src->type, sizeof(dst->type));
250 ret = kcapi_md_init(&dst->handle, src->type, 0);
251 if (ret < 0) {
252 KcapiHashFree(dst);
253 ret = -1;
254 }
255 }
256
257 return ret;
258 }
259
260
261 #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_KCAPI_HASH) && \
262 !defined(WOLFSSL_NO_KCAPI_SHA224)
263 #include <wolfssl/wolfcrypt/sha256.h>
264
265 static const char WC_NAME_SHA224[] = "sha224";
266
267
268 /* create KCAPI handle for SHA224 operation */
wc_InitSha224_ex(wc_Sha224 * sha,void * heap,int devId)269 int wc_InitSha224_ex(wc_Sha224* sha, void* heap, int devId)
270 {
271 if (sha == NULL) {
272 return BAD_FUNC_ARG;
273 }
274 return KcapiHashInit(&sha->kcapi, heap, devId, WC_NAME_SHA224);
275 }
276
277
wc_Sha224Update(wc_Sha224 * sha,const byte * in,word32 sz)278 int wc_Sha224Update(wc_Sha224* sha, const byte* in, word32 sz)
279 {
280 if (sha == NULL) {
281 return BAD_FUNC_ARG;
282 }
283 return KcapiHashUpdate(&sha->kcapi, in, sz);
284 }
285
286
wc_Sha224Final(wc_Sha224 * sha,byte * hash)287 int wc_Sha224Final(wc_Sha224* sha, byte* hash)
288 {
289 if (sha == NULL) {
290 return BAD_FUNC_ARG;
291 }
292 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA224_DIGEST_SIZE,
293 WC_NAME_SHA224);
294 }
295
296
wc_Sha224GetHash(wc_Sha224 * sha,byte * hash)297 int wc_Sha224GetHash(wc_Sha224* sha, byte* hash)
298 {
299 if (sha == NULL) {
300 return BAD_FUNC_ARG;
301 }
302 return KcapiHashGet(&sha->kcapi, hash, WC_SHA224_DIGEST_SIZE);
303 }
304
305
wc_Sha224Copy(wc_Sha224 * src,wc_Sha224 * dst)306 int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst)
307 {
308 if (src == NULL || dst == NULL) {
309 return BAD_FUNC_ARG;
310 }
311 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
312 }
313 #endif /* WOLFSSL_SHA224 */
314
315 #if !defined(NO_SHA256) && defined(WOLFSSL_KCAPI_HASH)
316 #include <wolfssl/wolfcrypt/sha256.h>
317
318 static const char WC_NAME_SHA256[] = "sha256";
319
320
321 /* create KCAPI handle for SHA256 operation */
322 #if defined(HAVE_FIPS) && \
323 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
InitSha256(wc_Sha256 * sha)324 int InitSha256(wc_Sha256* sha)
325 {
326 if (sha == NULL) {
327 return BAD_FUNC_ARG;
328 }
329 return KcapiHashInit(&sha->kcapi, NULL, INVALID_DEVID, WC_NAME_SHA256);
330 }
331
332
Sha256Update(wc_Sha256 * sha,const byte * in,word32 sz)333 int Sha256Update(wc_Sha256* sha, const byte* in, word32 sz)
334 {
335 if (sha == NULL) {
336 return BAD_FUNC_ARG;
337 }
338 return KcapiHashUpdate(&sha->kcapi, in, sz);
339 }
340
341
Sha256Final(wc_Sha256 * sha,byte * hash)342 int Sha256Final(wc_Sha256* sha, byte* hash)
343 {
344 if (sha == NULL) {
345 return BAD_FUNC_ARG;
346 }
347 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA256_DIGEST_SIZE,
348 WC_NAME_SHA256);
349 }
350 #else
wc_InitSha256_ex(wc_Sha256 * sha,void * heap,int devid)351 int wc_InitSha256_ex(wc_Sha256* sha, void* heap, int devid)
352 {
353 if (sha == NULL) {
354 return BAD_FUNC_ARG;
355 }
356 return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA256);
357 }
358
359
wc_Sha256Update(wc_Sha256 * sha,const byte * in,word32 sz)360 int wc_Sha256Update(wc_Sha256* sha, const byte* in, word32 sz)
361 {
362 if (sha == NULL) {
363 return BAD_FUNC_ARG;
364 }
365 return KcapiHashUpdate(&sha->kcapi, in, sz);
366 }
367
368
wc_Sha256Final(wc_Sha256 * sha,byte * hash)369 int wc_Sha256Final(wc_Sha256* sha, byte* hash)
370 {
371 if (sha == NULL) {
372 return BAD_FUNC_ARG;
373 }
374 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA256_DIGEST_SIZE,
375 WC_NAME_SHA256);
376 }
377 #endif
378
379
wc_Sha256GetHash(wc_Sha256 * sha,byte * hash)380 int wc_Sha256GetHash(wc_Sha256* sha, byte* hash)
381 {
382 if (sha == NULL) {
383 return BAD_FUNC_ARG;
384 }
385 return KcapiHashGet(&sha->kcapi, hash, WC_SHA256_DIGEST_SIZE);
386 }
387
388
wc_Sha256Copy(wc_Sha256 * src,wc_Sha256 * dst)389 int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
390 {
391 if (src == NULL || dst == NULL) {
392 return BAD_FUNC_ARG;
393 }
394 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
395 }
396 #endif /* !NO_SHA256 */
397
398 #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_KCAPI_HASH)
399 #include <wolfssl/wolfcrypt/sha512.h>
400
401 static const char WC_NAME_SHA384[] = "sha384";
402
403
404 #if defined(HAVE_FIPS) && \
405 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
406 /* create KCAPI handle for SHA384 operation */
InitSha384(wc_Sha384 * sha)407 int InitSha384(wc_Sha384* sha)
408 {
409 if (sha == NULL) {
410 return BAD_FUNC_ARG;
411 }
412 return KcapiHashInit(&sha->kcapi, NULL, INVALID_DEVID, WC_NAME_SHA384);
413 }
414
415
Sha384Update(wc_Sha384 * sha,const byte * in,word32 sz)416 int Sha384Update(wc_Sha384* sha, const byte* in, word32 sz)
417 {
418 if (sha == NULL) {
419 return BAD_FUNC_ARG;
420 }
421 return KcapiHashUpdate(&sha->kcapi, in, sz);
422 }
423
424
Sha384Final(wc_Sha384 * sha,byte * hash)425 int Sha384Final(wc_Sha384* sha, byte* hash)
426 {
427 if (sha == NULL) {
428 return BAD_FUNC_ARG;
429 }
430 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA384_DIGEST_SIZE,
431 WC_NAME_SHA384);
432 }
433 #else
434 /* create KCAPI handle for SHA384 operation */
wc_InitSha384_ex(wc_Sha384 * sha,void * heap,int devid)435 int wc_InitSha384_ex(wc_Sha384* sha, void* heap, int devid)
436 {
437 if (sha == NULL) {
438 return BAD_FUNC_ARG;
439 }
440 return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA384);
441 }
442
443
wc_Sha384Update(wc_Sha384 * sha,const byte * in,word32 sz)444 int wc_Sha384Update(wc_Sha384* sha, const byte* in, word32 sz)
445 {
446 if (sha == NULL) {
447 return BAD_FUNC_ARG;
448 }
449 return KcapiHashUpdate(&sha->kcapi, in, sz);
450 }
451
452
wc_Sha384Final(wc_Sha384 * sha,byte * hash)453 int wc_Sha384Final(wc_Sha384* sha, byte* hash)
454 {
455 if (sha == NULL) {
456 return BAD_FUNC_ARG;
457 }
458 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA384_DIGEST_SIZE,
459 WC_NAME_SHA384);
460 }
461 #endif
462
wc_Sha384GetHash(wc_Sha384 * sha,byte * hash)463 int wc_Sha384GetHash(wc_Sha384* sha, byte* hash)
464 {
465 if (sha == NULL) {
466 return BAD_FUNC_ARG;
467 }
468 return KcapiHashGet(&sha->kcapi, hash, WC_SHA384_DIGEST_SIZE);
469 }
470
471
wc_Sha384Copy(wc_Sha384 * src,wc_Sha384 * dst)472 int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
473 {
474 if (src == NULL || dst == NULL) {
475 return BAD_FUNC_ARG;
476 }
477 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
478 }
479 #endif /* WOLFSSL_SHA384 */
480
481 #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_KCAPI_HASH)
482 #include <wolfssl/wolfcrypt/sha512.h>
483
484 static const char WC_NAME_SHA512[] = "sha512";
485
486 #if defined(HAVE_FIPS) && \
487 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
488 /* create KCAPI handle for SHA512 operation */
InitSha512(wc_Sha512 * sha)489 int InitSha512(wc_Sha512* sha)
490 {
491 if (sha == NULL) {
492 return BAD_FUNC_ARG;
493 }
494 return KcapiHashInit(&sha->kcapi, NULL, INVALID_DEVID, WC_NAME_SHA512);
495 }
496
497
Sha512Update(wc_Sha512 * sha,const byte * in,word32 sz)498 int Sha512Update(wc_Sha512* sha, const byte* in, word32 sz)
499 {
500 if (sha == NULL) {
501 return BAD_FUNC_ARG;
502 }
503 return KcapiHashUpdate(&sha->kcapi, in, sz);
504 }
505
506
Sha512Final(wc_Sha512 * sha,byte * hash)507 int Sha512Final(wc_Sha512* sha, byte* hash)
508 {
509 if (sha == NULL) {
510 return BAD_FUNC_ARG;
511 }
512 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE,
513 WC_NAME_SHA512);
514 }
515 #else
516 /* create KCAPI handle for SHA512 operation */
wc_InitSha512_ex(wc_Sha512 * sha,void * heap,int devid)517 int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devid)
518 {
519 if (sha == NULL) {
520 return BAD_FUNC_ARG;
521 }
522 return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512);
523 }
524
525
wc_Sha512Update(wc_Sha512 * sha,const byte * in,word32 sz)526 int wc_Sha512Update(wc_Sha512* sha, const byte* in, word32 sz)
527 {
528 if (sha == NULL) {
529 return BAD_FUNC_ARG;
530 }
531 return KcapiHashUpdate(&sha->kcapi, in, sz);
532 }
533
534
wc_Sha512Final(wc_Sha512 * sha,byte * hash)535 int wc_Sha512Final(wc_Sha512* sha, byte* hash)
536 {
537 if (sha == NULL) {
538 return BAD_FUNC_ARG;
539 }
540 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE,
541 WC_NAME_SHA512);
542 }
543 #endif
544
wc_Sha512GetHash(wc_Sha512 * sha,byte * hash)545 int wc_Sha512GetHash(wc_Sha512* sha, byte* hash)
546 {
547 if (sha == NULL) {
548 return BAD_FUNC_ARG;
549 }
550 return KcapiHashGet(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE);
551 }
552
553
wc_Sha512Copy(wc_Sha512 * src,wc_Sha512 * dst)554 int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
555 {
556 if (src == NULL || dst == NULL) {
557 return BAD_FUNC_ARG;
558 }
559 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
560 }
561
562 #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
563 #if !defined(WOLFSSL_NOSHA512_224)
564 static const char WC_NAME_SHA512_224[] = "sha512-224";
565
566 /* create KCAPI handle for SHA512 operation */
wc_InitSha512_224_ex(wc_Sha512 * sha,void * heap,int devid)567 int wc_InitSha512_224_ex(wc_Sha512* sha, void* heap, int devid)
568 {
569 if (sha == NULL) {
570 return BAD_FUNC_ARG;
571 }
572 return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_224);
573 }
574
575
wc_Sha512_224Final(wc_Sha512 * sha,byte * hash)576 int wc_Sha512_224Final(wc_Sha512* sha, byte* hash)
577 {
578 if (sha == NULL) {
579 return BAD_FUNC_ARG;
580 }
581 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE,
582 WC_NAME_SHA512_224);
583 }
wc_Sha512_224GetHash(wc_Sha512 * sha,byte * hash)584 int wc_Sha512_224GetHash(wc_Sha512* sha, byte* hash)
585 {
586 if (sha == NULL) {
587 return BAD_FUNC_ARG;
588 }
589 return KcapiHashGet(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE);
590 }
591
592
wc_Sha512_224Copy(wc_Sha512 * src,wc_Sha512 * dst)593 int wc_Sha512_224Copy(wc_Sha512* src, wc_Sha512* dst)
594 {
595 if (src == NULL || dst == NULL) {
596 return BAD_FUNC_ARG;
597 }
598 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
599 }
600 #endif /* !WOLFSSL_NOSHA512_224 */
601
602 #if !defined(WOLFSSL_NOSHA512_256)
603 static const char WC_NAME_SHA512_256[] = "sha512-256";
604
605 /* create KCAPI handle for SHA512 operation */
wc_InitSha512_256_ex(wc_Sha512 * sha,void * heap,int devid)606 int wc_InitSha512_256_ex(wc_Sha512* sha, void* heap, int devid)
607 {
608 if (sha == NULL) {
609 return BAD_FUNC_ARG;
610 }
611 return KcapiHashInit(&sha->kcapi, heap, devid, WC_NAME_SHA512_256);
612 }
613
614
wc_Sha512_256Final(wc_Sha512 * sha,byte * hash)615 int wc_Sha512_256Final(wc_Sha512* sha, byte* hash)
616 {
617 if (sha == NULL) {
618 return BAD_FUNC_ARG;
619 }
620 return KcapiHashFinal(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE,
621 WC_NAME_SHA512_256);
622 }
wc_Sha512_256GetHash(wc_Sha512 * sha,byte * hash)623 int wc_Sha512_256GetHash(wc_Sha512* sha, byte* hash)
624 {
625 if (sha == NULL) {
626 return BAD_FUNC_ARG;
627 }
628 return KcapiHashGet(&sha->kcapi, hash, WC_SHA512_DIGEST_SIZE);
629 }
630
631
wc_Sha512_256Copy(wc_Sha512 * src,wc_Sha512 * dst)632 int wc_Sha512_256Copy(wc_Sha512* src, wc_Sha512* dst)
633 {
634 if (src == NULL || dst == NULL) {
635 return BAD_FUNC_ARG;
636 }
637 return KcapiHashCopy(&src->kcapi, &dst->kcapi);
638 }
639 #endif /* !WOLFSSL_NOSHA512_256 */
640 #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
641
642 #endif /* WOLFSSL_SHA512 */
643
644 #endif /* WOLFSSL_KCAPI_HASH */
645
646