pic32cz_ca90_crypto_hash.c
Go to the documentation of this file.
1 /**
2  * @file pic32cz_ca90_crypto_hash.c
3  * @brief PIC32CZ CA90 hash hardware accelerator
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "pic32c.h"
36 #include "hsm_hash.h"
37 #include "core/crypto.h"
40 #include "hash/hash_algorithms.h"
41 #include "debug.h"
42 
43 //Check crypto library configuration
44 #if (PIC32CZ_CA90_CRYPTO_HASH_SUPPORT == ENABLED)
45 
46 //Padding string
47 static const uint8_t padding[128] =
48 {
49  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
57 };
58 
59 
60 /**
61  * @brief Update hash value
62  * @param[in] type Hash algorithm
63  * @param[in] data Pointer to the input buffer
64  * @param[in] length Length of the input buffer
65  * @param[in,out] h Intermediate hash value
66  * @return Error code
67  **/
68 
69 error_t hashProcessData(hsm_Hash_Types_E type, const uint8_t *data,
70  size_t length, uint32_t *h)
71 {
72  hsm_Cmd_Status_E status;
73 
74  //Acquire exclusive access to the HSM
76 
77  //Digest the message
78  status = HSM_Hash_UpdateCmd((uint8_t *) h, (uint8_t *) data, length, type);
79 
80  //Release exclusive access to the HSM
82 
83  //Return status code
84  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
85 }
86 
87 
88 #if (SHA1_SUPPORT == ENABLED)
89 
90 /**
91  * @brief Digest a message using SHA-1
92  * @param[in] data Pointer to the message being hashed
93  * @param[in] length Length of the message
94  * @param[out] digest Pointer to the calculated digest
95  * @return Error code
96  **/
97 
98 error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
99 {
100  hsm_Cmd_Status_E status;
101 
102  //Acquire exclusive access to the HSM
104 
105  //Digest the message
106  status = HSM_Hash_DigestDirect(HSM_CMD_HASH_SHA1, (uint8_t *) data,
107  length, digest);
108 
109  //Release exclusive access to the HSM
111 
112  //Return status code
113  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
114 }
115 
116 
117 /**
118  * @brief Initialize SHA-1 message digest context
119  * @param[in] context Pointer to the SHA-1 context to initialize
120  **/
121 
122 void sha1Init(Sha1Context *context)
123 {
124  //Set initial hash value
125  context->h[0] = BETOH32(0x67452301);
126  context->h[1] = BETOH32(0xEFCDAB89);
127  context->h[2] = BETOH32(0x98BADCFE);
128  context->h[3] = BETOH32(0x10325476);
129  context->h[4] = BETOH32(0xC3D2E1F0);
130 
131  //Number of bytes in the buffer
132  context->size = 0;
133  //Total length of the message
134  context->totalSize = 0;
135 }
136 
137 
138 /**
139  * @brief Update the SHA-1 context with a portion of the message being hashed
140  * @param[in] context Pointer to the SHA-1 context
141  * @param[in] data Pointer to the buffer being hashed
142  * @param[in] length Length of the buffer
143  **/
144 
145 void sha1Update(Sha1Context *context, const void *data, size_t length)
146 {
147  size_t n;
148 
149  //Process the incoming data
150  while(length > 0)
151  {
152  //Check whether some data is pending in the buffer
153  if(context->size == 0 && length >= 64)
154  {
155  //The length must be a multiple of 64 bytes
156  n = length - (length % 64);
157 
158  //Update hash value
159  hashProcessData(HSM_CMD_HASH_SHA1, data, n, context->h);
160 
161  //Update the SHA-1 context
162  context->totalSize += n;
163  //Advance the data pointer
164  data = (uint8_t *) data + n;
165  //Remaining bytes to process
166  length -= n;
167  }
168  else
169  {
170  //The buffer can hold at most 64 bytes
171  n = MIN(length, 64 - context->size);
172 
173  //Copy the data to the buffer
174  osMemcpy(context->buffer + context->size, data, n);
175 
176  //Update the SHA-1 context
177  context->size += n;
178  context->totalSize += n;
179  //Advance the data pointer
180  data = (uint8_t *) data + n;
181  //Remaining bytes to process
182  length -= n;
183 
184  //Check whether the buffer is full
185  if(context->size == 64)
186  {
187  //Update hash value
188  hashProcessData(HSM_CMD_HASH_SHA1, context->buffer,
189  context->size, context->h);
190 
191  //Empty the buffer
192  context->size = 0;
193  }
194  }
195  }
196 }
197 
198 
199 /**
200  * @brief Finish the SHA-1 message digest
201  * @param[in] context Pointer to the SHA-1 context
202  * @param[out] digest Calculated digest
203  **/
204 
205 void sha1Final(Sha1Context *context, uint8_t *digest)
206 {
207  uint_t i;
208  size_t paddingSize;
209  uint64_t totalSize;
210 
211  //Length of the original message (before padding)
212  totalSize = context->totalSize * 8;
213 
214  //Pad the message so that its length is congruent to 56 modulo 64
215  if(context->size < 56)
216  {
217  paddingSize = 56 - context->size;
218  }
219  else
220  {
221  paddingSize = 64 + 56 - context->size;
222  }
223 
224  //Append padding
225  sha1Update(context, padding, paddingSize);
226 
227  //Append the length of the original message
228  for(i = 0; i < 8; i++)
229  {
230  context->buffer[63 - i] = totalSize & 0xFF;
231  totalSize >>= 8;
232  }
233 
234  //Calculate the message digest
235  hashProcessData(HSM_CMD_HASH_SHA1, context->buffer, 64,
236  context->h);
237 
238  //Copy the resulting digest
239  for(i = 0; i < (SHA1_DIGEST_SIZE / 4); i++)
240  {
241  STORE32LE(context->h[i], digest + i * 4);
242  }
243 }
244 
245 
246 /**
247  * @brief Finish the SHA-1 message digest (no padding added)
248  * @param[in] context Pointer to the SHA-1 context
249  * @param[out] digest Calculated digest
250  **/
251 
252 void sha1FinalRaw(Sha1Context *context, uint8_t *digest)
253 {
254  uint_t i;
255 
256  //Copy the resulting digest
257  for(i = 0; i < (SHA1_DIGEST_SIZE / 4); i++)
258  {
259  STORE32LE(context->h[i], digest + i * 4);
260  }
261 }
262 
263 #endif
264 #if (SHA224_SUPPORT == ENABLED)
265 
266 /**
267  * @brief Digest a message using SHA-224
268  * @param[in] data Pointer to the message being hashed
269  * @param[in] length Length of the message
270  * @param[out] digest Pointer to the calculated digest
271  * @return Error code
272  **/
273 
274 error_t sha224Compute(const void *data, size_t length, uint8_t *digest)
275 {
276  hsm_Cmd_Status_E status;
277 
278  //Acquire exclusive access to the HSM
280 
281  //Digest the message
282  status = HSM_Hash_DigestDirect(HSM_CMD_HASH_SHA224, (uint8_t *) data,
283  length, digest);
284 
285  //Release exclusive access to the HSM
287 
288  //Return status code
289  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
290 }
291 
292 
293 /**
294  * @brief Initialize SHA-224 message digest context
295  * @param[in] context Pointer to the SHA-224 context to initialize
296  **/
297 
298 void sha224Init(Sha224Context *context)
299 {
300  //Set initial hash value
301  context->h[0] = BETOH32(0xC1059ED8);
302  context->h[1] = BETOH32(0x367CD507);
303  context->h[2] = BETOH32(0x3070DD17);
304  context->h[3] = BETOH32(0xF70E5939);
305  context->h[4] = BETOH32(0xFFC00B31);
306  context->h[5] = BETOH32(0x68581511);
307  context->h[6] = BETOH32(0x64F98FA7);
308  context->h[7] = BETOH32(0xBEFA4FA4);
309 
310  //Number of bytes in the buffer
311  context->size = 0;
312  //Total length of the message
313  context->totalSize = 0;
314 }
315 
316 #endif
317 #if (SHA256_SUPPORT == ENABLED)
318 
319 /**
320  * @brief Digest a message using SHA-256
321  * @param[in] data Pointer to the message being hashed
322  * @param[in] length Length of the message
323  * @param[out] digest Pointer to the calculated digest
324  * @return Error code
325  **/
326 
327 error_t sha256Compute(const void *data, size_t length, uint8_t *digest)
328 {
329  hsm_Cmd_Status_E status;
330 
331  //Acquire exclusive access to the HSM
333 
334  //Digest the message
335  status = HSM_Hash_DigestDirect(HSM_CMD_HASH_SHA256, (uint8_t *) data,
336  length, digest);
337 
338  //Release exclusive access to the HSM
340 
341  //Return status code
342  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
343 }
344 
345 
346 /**
347  * @brief Initialize SHA-256 message digest context
348  * @param[in] context Pointer to the SHA-256 context to initialize
349  **/
350 
351 void sha256Init(Sha256Context *context)
352 {
353  //Set initial hash value
354  context->h[0] = BETOH32(0x6A09E667);
355  context->h[1] = BETOH32(0xBB67AE85);
356  context->h[2] = BETOH32(0x3C6EF372);
357  context->h[3] = BETOH32(0xA54FF53A);
358  context->h[4] = BETOH32(0x510E527F);
359  context->h[5] = BETOH32(0x9B05688C);
360  context->h[6] = BETOH32(0x1F83D9AB);
361  context->h[7] = BETOH32(0x5BE0CD19);
362 
363  //Number of bytes in the buffer
364  context->size = 0;
365  //Total length of the message
366  context->totalSize = 0;
367 }
368 
369 /**
370  * @brief Update the SHA-256 context with a portion of the message being hashed
371  * @param[in] context Pointer to the SHA-256 context
372  * @param[in] data Pointer to the buffer being hashed
373  * @param[in] length Length of the buffer
374  **/
375 
376 void sha256Update(Sha256Context *context, const void *data, size_t length)
377 {
378  size_t n;
379 
380  //Process the incoming data
381  while(length > 0)
382  {
383  //Check whether some data is pending in the buffer
384  if(context->size == 0 && length >= 64)
385  {
386  //The length must be a multiple of 64 bytes
387  n = length - (length % 64);
388 
389  //Update hash value
390  hashProcessData(HSM_CMD_HASH_SHA256, data, n, context->h);
391 
392  //Update the SHA-256 context
393  context->totalSize += n;
394  //Advance the data pointer
395  data = (uint8_t *) data + n;
396  //Remaining bytes to process
397  length -= n;
398  }
399  else
400  {
401  //The buffer can hold at most 64 bytes
402  n = MIN(length, 64 - context->size);
403 
404  //Copy the data to the buffer
405  osMemcpy(context->buffer + context->size, data, n);
406 
407  //Update the SHA-256 context
408  context->size += n;
409  context->totalSize += n;
410  //Advance the data pointer
411  data = (uint8_t *) data + n;
412  //Remaining bytes to process
413  length -= n;
414 
415  //Check whether the buffer is full
416  if(context->size == 64)
417  {
418  //Update hash value
419  hashProcessData(HSM_CMD_HASH_SHA256, context->buffer,
420  context->size, context->h);
421 
422  //Empty the buffer
423  context->size = 0;
424  }
425  }
426  }
427 }
428 
429 
430 /**
431  * @brief Finish the SHA-256 message digest
432  * @param[in] context Pointer to the SHA-256 context
433  * @param[out] digest Calculated digest
434  **/
435 
436 void sha256Final(Sha256Context *context, uint8_t *digest)
437 {
438  uint_t i;
439  size_t paddingSize;
440  uint64_t totalSize;
441 
442  //Length of the original message (before padding)
443  totalSize = context->totalSize * 8;
444 
445  //Pad the message so that its length is congruent to 56 modulo 64
446  if(context->size < 56)
447  {
448  paddingSize = 56 - context->size;
449  }
450  else
451  {
452  paddingSize = 64 + 56 - context->size;
453  }
454 
455  //Append padding
456  sha256Update(context, padding, paddingSize);
457 
458  //Append the length of the original message
459  for(i = 0; i < 8; i++)
460  {
461  context->buffer[63 - i] = totalSize & 0xFF;
462  totalSize >>= 8;
463  }
464 
465  //Calculate the message digest
466  hashProcessData(HSM_CMD_HASH_SHA256, context->buffer, 64,
467  context->h);
468 
469  //Copy the resulting digest
470  for(i = 0; i < (SHA256_DIGEST_SIZE / 4); i++)
471  {
472  STORE32LE(context->h[i], digest + i * 4);
473  }
474 }
475 
476 
477 /**
478  * @brief Finish the SHA-256 message digest (no padding added)
479  * @param[in] context Pointer to the SHA-256 context
480  * @param[out] digest Calculated digest
481  **/
482 
483 void sha256FinalRaw(Sha256Context *context, uint8_t *digest)
484 {
485  uint_t i;
486 
487  //Copy the resulting digest
488  for(i = 0; i < (SHA256_DIGEST_SIZE / 4); i++)
489  {
490  STORE32LE(context->h[i], digest + i * 4);
491  }
492 }
493 
494 #endif
495 #if (SHA384_SUPPORT == ENABLED)
496 
497 /**
498  * @brief Digest a message using SHA-384
499  * @param[in] data Pointer to the message being hashed
500  * @param[in] length Length of the message
501  * @param[out] digest Pointer to the calculated digest
502  * @return Error code
503  **/
504 
505 error_t sha384Compute(const void *data, size_t length, uint8_t *digest)
506 {
507  hsm_Cmd_Status_E status;
508 
509  //Acquire exclusive access to the HSM
511 
512  //Digest the message
513  status = HSM_Hash_DigestDirect(HSM_CMD_HASH_SHA384, (uint8_t *) data,
514  length, digest);
515 
516  //Release exclusive access to the HSM
518 
519  //Return status code
520  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
521 }
522 
523 
524 /**
525  * @brief Initialize SHA-384 message digest context
526  * @param[in] context Pointer to the SHA-384 context to initialize
527  **/
528 
529 void sha384Init(Sha384Context *context)
530 {
531  //Set initial hash value
532  context->h[0] = BETOH64(0xCBBB9D5DC1059ED8);
533  context->h[1] = BETOH64(0x629A292A367CD507);
534  context->h[2] = BETOH64(0x9159015A3070DD17);
535  context->h[3] = BETOH64(0x152FECD8F70E5939);
536  context->h[4] = BETOH64(0x67332667FFC00B31);
537  context->h[5] = BETOH64(0x8EB44A8768581511);
538  context->h[6] = BETOH64(0xDB0C2E0D64F98FA7);
539  context->h[7] = BETOH64(0x47B5481DBEFA4FA4);
540 
541  //Number of bytes in the buffer
542  context->size = 0;
543  //Total length of the message
544  context->totalSize = 0;
545 }
546 
547 
548 /**
549  * @brief Finish the SHA-384 message digest (no padding added)
550  * @param[in] context Pointer to the SHA-384 context
551  * @param[out] digest Calculated digest
552  **/
553 
554 void sha384FinalRaw(Sha384Context *context, uint8_t *digest)
555 {
556  uint_t i;
557 
558  //Copy the resulting digest
559  for(i = 0; i < (SHA384_DIGEST_SIZE / 8); i++)
560  {
561  STORE64LE(context->h[i], digest + i * 8);
562  }
563 }
564 
565 #endif
566 #if (SHA512_SUPPORT == ENABLED)
567 
568 /**
569  * @brief Digest a message using SHA-512
570  * @param[in] data Pointer to the message being hashed
571  * @param[in] length Length of the message
572  * @param[out] digest Pointer to the calculated digest
573  * @return Error code
574  **/
575 
576 error_t sha512Compute(const void *data, size_t length, uint8_t *digest)
577 {
578  hsm_Cmd_Status_E status;
579 
580  //Acquire exclusive access to the HSM
582 
583  //Digest the message
584  status = HSM_Hash_DigestDirect(HSM_CMD_HASH_SHA512, (uint8_t *) data,
585  length, digest);
586 
587  //Release exclusive access to the HSM
589 
590  //Return status code
591  return (status == HSM_CMD_SUCCESS) ? NO_ERROR : ERROR_FAILURE;
592 }
593 
594 
595 /**
596  * @brief Initialize SHA-512 message digest context
597  * @param[in] context Pointer to the SHA-512 context to initialize
598  **/
599 
600 void sha512Init(Sha512Context *context)
601 {
602  //Set initial hash value
603  context->h[0] = BETOH64(0x6A09E667F3BCC908);
604  context->h[1] = BETOH64(0xBB67AE8584CAA73B);
605  context->h[2] = BETOH64(0x3C6EF372FE94F82B);
606  context->h[3] = BETOH64(0xA54FF53A5F1D36F1);
607  context->h[4] = BETOH64(0x510E527FADE682D1);
608  context->h[5] = BETOH64(0x9B05688C2B3E6C1F);
609  context->h[6] = BETOH64(0x1F83D9ABFB41BD6B);
610  context->h[7] = BETOH64(0x5BE0CD19137E2179);
611 
612  //Number of bytes in the buffer
613  context->size = 0;
614  //Total length of the message
615  context->totalSize = 0;
616 }
617 
618 
619 /**
620  * @brief Update the SHA-512 context with a portion of the message being hashed
621  * @param[in] context Pointer to the SHA-512 context
622  * @param[in] data Pointer to the buffer being hashed
623  * @param[in] length Length of the buffer
624  **/
625 
626 void sha512Update(Sha512Context *context, const void *data, size_t length)
627 {
628  size_t n;
629 
630  //Process the incoming data
631  while(length > 0)
632  {
633  //Check whether some data is pending in the buffer
634  if(context->size == 0 && length >= 128)
635  {
636  //The length must be a multiple of 128 bytes
637  n = length - (length % 128);
638 
639  //Update hash value
640  hashProcessData(HSM_CMD_HASH_SHA512, data, n,
641  (uint32_t *) context->h);
642 
643  //Update the SHA-512 context
644  context->totalSize += n;
645  //Advance the data pointer
646  data = (uint8_t *) data + n;
647  //Remaining bytes to process
648  length -= n;
649  }
650  else
651  {
652  //The buffer can hold at most 128 bytes
653  n = MIN(length, 128 - context->size);
654 
655  //Copy the data to the buffer
656  osMemcpy(context->buffer + context->size, data, n);
657 
658  //Update the SHA-512 context
659  context->size += n;
660  context->totalSize += n;
661  //Advance the data pointer
662  data = (uint8_t *) data + n;
663  //Remaining bytes to process
664  length -= n;
665 
666  //Check whether the buffer is full
667  if(context->size == 128)
668  {
669  //Update hash value
670  hashProcessData(HSM_CMD_HASH_SHA512, context->buffer,
671  context->size, (uint32_t *) context->h);
672 
673  //Empty the buffer
674  context->size = 0;
675  }
676  }
677  }
678 }
679 
680 
681 /**
682  * @brief Finish the SHA-512 message digest
683  * @param[in] context Pointer to the SHA-512 context
684  * @param[out] digest Calculated digest
685  **/
686 
687 void sha512Final(Sha512Context *context, uint8_t *digest)
688 {
689  uint_t i;
690  size_t paddingSize;
691  uint64_t totalSize;
692 
693  //Length of the original message (before padding)
694  totalSize = context->totalSize * 8;
695 
696  //Pad the message so that its length is congruent to 112 modulo 128
697  if(context->size < 112)
698  {
699  paddingSize = 112 - context->size;
700  }
701  else
702  {
703  paddingSize = 128 + 112 - context->size;
704  }
705 
706  //Append padding
707  sha512Update(context, padding, paddingSize);
708 
709  //Append the length of the original message
710  for(i = 0; i < 16; i++)
711  {
712  context->buffer[127 - i] = totalSize & 0xFF;
713  totalSize >>= 8;
714  }
715 
716  //Calculate the message digest
717  hashProcessData(HSM_CMD_HASH_SHA512, context->buffer, 128,
718  (uint32_t *) context->h);
719 
720  //Copy the resulting digest
721  for(i = 0; i < (SHA512_DIGEST_SIZE / 8); i++)
722  {
723  STORE64LE(context->h[i], digest + i * 8);
724  }
725 }
726 
727 #endif
728 #if (SHA512_224_SUPPORT == ENABLED)
729 
730 /**
731  * @brief Initialize SHA-512/224 message digest context
732  * @param[in] context Pointer to the SHA-512/224 context to initialize
733  **/
734 
736 {
737  //Set initial hash value
738  context->h[0] = BETOH64(0x8C3D37C819544DA2);
739  context->h[1] = BETOH64(0x73E1996689DCD4D6);
740  context->h[2] = BETOH64(0x1DFAB7AE32FF9C82);
741  context->h[3] = BETOH64(0x679DD514582F9FCF);
742  context->h[4] = BETOH64(0x0F6D2B697BD44DA8);
743  context->h[5] = BETOH64(0x77E36F7304C48942);
744  context->h[6] = BETOH64(0x3F9D85A86A1D36C8);
745  context->h[7] = BETOH64(0x1112E6AD91D692A1);
746 
747  //Number of bytes in the buffer
748  context->size = 0;
749  //Total length of the message
750  context->totalSize = 0;
751 }
752 
753 #endif
754 #if (SHA512_256_SUPPORT == ENABLED)
755 
756 /**
757  * @brief Initialize SHA-512/256 message digest context
758  * @param[in] context Pointer to the SHA-512/256 context to initialize
759  **/
760 
762 {
763  //Set initial hash value
764  context->h[0] = BETOH64(0x22312194FC2BF72C);
765  context->h[1] = BETOH64(0x9F555FA3C84C64C2);
766  context->h[2] = BETOH64(0x2393B86B6F53B151);
767  context->h[3] = BETOH64(0x963877195940EABD);
768  context->h[4] = BETOH64(0x96283EE2A88EFFE3);
769  context->h[5] = BETOH64(0xBE5E1E2553863992);
770  context->h[6] = BETOH64(0x2B0199FC2C85B8AA);
771  context->h[7] = BETOH64(0x0EB72DDC81C52CA2);
772 
773  //Number of bytes in the buffer
774  context->size = 0;
775  //Total length of the message
776  context->totalSize = 0;
777 }
778 
779 #endif
780 #endif
void sha512Final(Sha512Context *context, uint8_t *digest)
Finish the SHA-512 message digest.
SHA-256 algorithm context.
Definition: sha256.h:62
void sha512_224Init(Sha512_224Context *context)
Initialize SHA-512/224 message digest context.
uint8_t data[]
Definition: ethernet.h:224
void sha512Init(Sha512Context *context)
Initialize SHA-512 message digest context.
#define STORE32LE(a, p)
Definition: cpu_endian.h:279
size_t size
Definition: sha256.h:69
uint8_t type
Definition: coap_common.h:176
uint32_t h[8]
Definition: sha256.h:63
#define BETOH32(value)
Definition: cpu_endian.h:451
void sha256Final(Sha256Context *context, uint8_t *digest)
Finish the SHA-256 message digest.
void sha224Init(Sha224Context *context)
Initialize SHA-224 message digest context.
uint64_t totalSize
Definition: sha1.h:70
size_t size
Definition: sha512.h:69
error_t sha256Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-256.
error_t sha384Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-384.
void sha1Init(Sha1Context *context)
Initialize SHA-1 message digest context.
uint8_t h
Definition: ndp.h:302
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
error_t
Error codes.
Definition: error.h:43
void sha384Init(Sha384Context *context)
Initialize SHA-384 message digest context.
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
error_t hashProcessData(hsm_Hash_Types_E type, const uint8_t *data, size_t length, uint32_t *h)
Update hash value.
SHA-512 algorithm context.
Definition: sha512.h:62
uint32_t h[5]
Definition: sha1.h:63
error_t sha512Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-512.
void sha256FinalRaw(Sha256Context *context, uint8_t *digest)
Finish the SHA-256 message digest (no padding added)
General definitions for cryptographic algorithms.
uint8_t buffer[128]
Definition: sha512.h:67
uint8_t length
Definition: tcp.h:375
uint8_t buffer[64]
Definition: sha256.h:67
#define MIN(a, b)
Definition: os_port.h:63
#define SHA384_DIGEST_SIZE
Definition: sha384.h:41
void sha256Init(Sha256Context *context)
Initialize SHA-256 message digest context.
Collection of hash algorithms.
OsMutex pic32czca90CryptoMutex
void sha1Final(Sha1Context *context, uint8_t *digest)
Finish the SHA-1 message digest.
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
PIC32CZ CA90 hardware cryptographic accelerator (HSM)
uint64_t h[8]
Definition: sha512.h:63
uint8_t n
#define STORE64LE(a, p)
Definition: cpu_endian.h:311
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-1.
size_t size
Definition: sha1.h:69
#define BETOH64(value)
Definition: cpu_endian.h:452
void sha384FinalRaw(Sha384Context *context, uint8_t *digest)
Finish the SHA-384 message digest (no padding added)
error_t sha224Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-224.
SHA-1 algorithm context.
Definition: sha1.h:62
void sha256Update(Sha256Context *context, const void *data, size_t length)
Update the SHA-256 context with a portion of the message being hashed.
void sha1FinalRaw(Sha1Context *context, uint8_t *digest)
Finish the SHA-1 message digest (no padding added)
uint8_t buffer[64]
Definition: sha1.h:67
uint64_t totalSize
Definition: sha512.h:70
uint64_t totalSize
Definition: sha256.h:70
PIC32CZ CA90 hash hardware accelerator.
void sha1Update(Sha1Context *context, const void *data, size_t length)
Update the SHA-1 context with a portion of the message being hashed.
unsigned int uint_t
Definition: compiler_port.h:57
#define SHA256_DIGEST_SIZE
Definition: sha256.h:45
void sha512Update(Sha512Context *context, const void *data, size_t length)
Update the SHA-512 context with a portion of the message being hashed.
#define SHA512_DIGEST_SIZE
Definition: sha512.h:45
@ NO_ERROR
Success.
Definition: error.h:44
void sha512_256Init(Sha512_256Context *context)
Initialize SHA-512/256 message digest context.
Debugging facilities.