tm4c129_crypto_hash.c
Go to the documentation of this file.
1 /**
2  * @file tm4c129_crypto_hash.c
3  * @brief Tiva TM4C129 hash hardware accelerator
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include <stdint.h>
36 #include <stdbool.h>
37 #include "inc/hw_types.h"
38 #include "inc/hw_memmap.h"
39 #include "inc/hw_shamd5.h"
40 #include "core/crypto.h"
43 #include "hash/hash_algorithms.h"
44 #include "debug.h"
45 
46 //Check crypto library configuration
47 #if (TM4C129_CRYPTO_HASH_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief Reset SHA/MD5 module
52  **/
53 
54 void hashReset(void)
55 {
56  uint32_t temp;
57 
58  //Perform software reset
59  SHAMD5_SYSCONFIG_R |= SHAMD5_SYSCONFIG_SOFTRESET;
60 
61  //Wait for the reset to complete
62  while((SHAMD5_SYSSTATUS_R & SHAMD5_SYSSTATUS_RESETDONE) == 0)
63  {
64  }
65 
66  //Force idle mode
67  temp = SHAMD5_SYSCONFIG_R & ~SHAMD5_SYSCONFIG_SIDLE_M;
68  SHAMD5_SYSCONFIG_R = temp | SHAMD5_SYSCONFIG_SIDLE_FORCE;
69 }
70 
71 
72 /**
73  * @brief Update hash value
74  * @param[in] data Pointer to the input buffer
75  * @param[in] length Length of the input buffer
76  * @param[out] digest Resulting digest value
77  * @param[in] digestSize Size of the digest, in bytes
78  **/
79 
80 void hashProcessData(const uint8_t *data, size_t length, uint8_t *digest,
81  size_t digestSize)
82 {
83  size_t i;
84  uint32_t temp;
85 
86  //Specify the length
88 
89  //Digest input data
90  while(length >= 64)
91  {
92  //Wait for the SHA/MD5 engine to be ready to accept data
93  while((SHAMD5_IRQSTATUS_R & SHAMD5_IRQSTATUS_INPUT_READY) == 0)
94  {
95  }
96 
97  //Write 64-byte block
114 
115  //Advance data pointer
116  data += 64;
117  length -= 64;
118  }
119 
120  //Process final block
121  if(length > 0)
122  {
123  //Wait for the SHA/MD5 engine to be ready to accept data
124  while((SHAMD5_IRQSTATUS_R & SHAMD5_IRQSTATUS_INPUT_READY) == 0)
125  {
126  }
127 
128  //Write final block
129  for(i = 0; i < length; i += 4)
130  {
131  //Write 32-bit word
132  HWREG(SHAMD5_BASE + SHAMD5_O_DATA_0_IN + i) = LOAD32LE(data);
133  //Advance data pointer
134  data += 4;
135  }
136  }
137 
138  //Wait for the output to be ready
139  while((SHAMD5_IRQSTATUS_R & SHAMD5_IRQSTATUS_OUTPUT_READY) == 0)
140  {
141  }
142 
143  //Read the resulting output value
144  for(i = 0; i < digestSize; i += 4)
145  {
146  temp = HWREG(SHAMD5_BASE + SHAMD5_O_IDIGEST_A + i);
147  STORE32LE(temp, digest + i);
148  }
149 }
150 
151 
152 #if (MD5_SUPPORT == ENABLED)
153 
154 /**
155  * @brief Digest a message using MD5
156  * @param[in] data Pointer to the message being hashed
157  * @param[in] length Length of the message
158  * @param[out] digest Pointer to the calculated digest
159  * @return Error code
160  **/
161 
162 error_t md5Compute(const void *data, size_t length, uint8_t *digest)
163 {
164  //Acquire exclusive access to the SHA/MD5 module
166 
167  //Reset the SHA/MD5 module before use
168  hashReset();
169 
170  //Configure the SHA/MD5 module
171  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_MD5 | SHAMD5_MODE_ALGO_CONSTANT |
172  SHAMD5_MODE_CLOSE_HASH;
173 
174  //Digest the message
176 
177  //Release exclusive access to the SHA/MD5 module
179 
180  //Sucessful processing
181  return NO_ERROR;
182 }
183 
184 
185 /**
186  * @brief Initialize MD5 message digest context
187  * @param[in] context Pointer to the MD5 context to initialize
188  **/
189 
190 void md5Init(Md5Context *context)
191 {
192  //Set initial hash value
193  context->h[0] = 0x67452301;
194  context->h[1] = 0xEFCDAB89;
195  context->h[2] = 0x98BADCFE;
196  context->h[3] = 0x10325476;
197 
198  //Number of bytes in the buffer
199  context->size = 0;
200  //Total length of the message
201  context->totalSize = 0;
202 }
203 
204 
205 /**
206  * @brief Update the MD5 context with a portion of the message being hashed
207  * @param[in] context Pointer to the MD5 context
208  * @param[in] data Pointer to the buffer being hashed
209  * @param[in] length Length of the buffer
210  **/
211 
212 void md5Update(Md5Context *context, const void *data, size_t length)
213 {
214  size_t n;
215 
216  //Acquire exclusive access to the SHA/MD5 module
218 
219  //Reset the SHA/MD5 module before use
220  hashReset();
221 
222  //Configure the SHA/MD5 module
223  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_MD5;
224 
225  //Restore hash context
226  SHAMD5_IDIGEST_A_R = context->h[0];
227  SHAMD5_IDIGEST_B_R = context->h[1];
228  SHAMD5_IDIGEST_C_R = context->h[2];
229  SHAMD5_IDIGEST_D_R = context->h[3];
230 
231  //Restore the value of the SHA_DIGEST_COUNT register
232  SHAMD5_DIGEST_COUNT_R = context->totalSize;
233 
234  //Process the incoming data
235  while(length > 0)
236  {
237  //Check whether some data is pending in the buffer
238  if(context->size == 0 && length >= 64)
239  {
240  //The length must be a multiple of 64 bytes
241  n = length - (length % 64);
242 
243  //Update hash value
245 
246  //Advance the data pointer
247  data = (uint8_t *) data + n;
248  //Remaining bytes to process
249  length -= n;
250  }
251  else
252  {
253  //The buffer can hold at most 64 bytes
254  n = MIN(length, 64 - context->size);
255 
256  //Copy the data to the buffer
257  osMemcpy(context->buffer + context->size, data, n);
258 
259  //Update the MD5 context
260  context->size += n;
261  //Advance the data pointer
262  data = (uint8_t *) data + n;
263  //Remaining bytes to process
264  length -= n;
265 
266  //Check whether the buffer is full
267  if(context->size == 64)
268  {
269  //Update hash value
270  hashProcessData(context->buffer, context->size, context->digest,
272 
273  //Empty the buffer
274  context->size = 0;
275  }
276  }
277  }
278 
279  //Save the value of the SHA_DIGEST_COUNT register
280  context->totalSize = SHAMD5_DIGEST_COUNT_R;
281 
282  //Release exclusive access to the SHA/MD5 module
284 }
285 
286 
287 /**
288  * @brief Finish the MD5 message digest
289  * @param[in] context Pointer to the MD5 context
290  * @param[out] digest Calculated digest (optional parameter)
291  **/
292 
293 void md5Final(Md5Context *context, uint8_t *digest)
294 {
295  //Acquire exclusive access to the SHA/MD5 module
297 
298  //Reset the SHA/MD5 module before use
299  hashReset();
300 
301  //Configure the SHA/MD5 module
302  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_MD5 | SHAMD5_MODE_CLOSE_HASH;
303 
304  //Restore hash context
305  SHAMD5_IDIGEST_A_R = context->h[0];
306  SHAMD5_IDIGEST_B_R = context->h[1];
307  SHAMD5_IDIGEST_C_R = context->h[2];
308  SHAMD5_IDIGEST_D_R = context->h[3];
309 
310  //Restore the value of the SHA_DIGEST_COUNT register
311  SHAMD5_DIGEST_COUNT_R = context->totalSize;
312 
313  //Finish digest calculation
314  hashProcessData(context->buffer, context->size, context->digest,
316 
317  //Release exclusive access to the SHA/MD5 module
319 
320  //Copy the resulting digest
321  if(digest != NULL)
322  {
323  osMemcpy(digest, context->digest, MD5_DIGEST_SIZE);
324  }
325 }
326 
327 
328 /**
329  * @brief Finish the MD5 message digest (no padding added)
330  * @param[in] context Pointer to the MD5 context
331  * @param[out] digest Calculated digest
332  **/
333 
334 void md5FinalRaw(Md5Context *context, uint8_t *digest)
335 {
336  //Copy the resulting digest
337  osMemcpy(digest, context->digest, MD5_DIGEST_SIZE);
338 }
339 
340 #endif
341 #if (SHA1_SUPPORT == ENABLED)
342 
343 /**
344  * @brief Digest a message using SHA-1
345  * @param[in] data Pointer to the message being hashed
346  * @param[in] length Length of the message
347  * @param[out] digest Pointer to the calculated digest
348  * @return Error code
349  **/
350 
351 error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
352 {
353  //Acquire exclusive access to the SHA/MD5 module
355 
356  //Reset the SHA/MD5 module before use
357  hashReset();
358 
359  //Configure the SHA/MD5 module
360  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA1 | SHAMD5_MODE_ALGO_CONSTANT |
361  SHAMD5_MODE_CLOSE_HASH;
362 
363  //Digest the message
365 
366  //Release exclusive access to the SHA/MD5 module
368 
369  //Sucessful processing
370  return NO_ERROR;
371 }
372 
373 
374 /**
375  * @brief Initialize SHA-1 message digest context
376  * @param[in] context Pointer to the SHA-1 context to initialize
377  **/
378 
379 void sha1Init(Sha1Context *context)
380 {
381  //Set initial hash value
382  context->h[0] = BETOH32(0x67452301);
383  context->h[1] = BETOH32(0xEFCDAB89);
384  context->h[2] = BETOH32(0x98BADCFE);
385  context->h[3] = BETOH32(0x10325476);
386  context->h[4] = BETOH32(0xC3D2E1F0);
387 
388  //Number of bytes in the buffer
389  context->size = 0;
390  //Total length of the message
391  context->totalSize = 0;
392 }
393 
394 
395 /**
396  * @brief Update the SHA-1 context with a portion of the message being hashed
397  * @param[in] context Pointer to the SHA-1 context
398  * @param[in] data Pointer to the buffer being hashed
399  * @param[in] length Length of the buffer
400  **/
401 
402 void sha1Update(Sha1Context *context, const void *data, size_t length)
403 {
404  size_t n;
405 
406  //Acquire exclusive access to the SHA/MD5 module
408 
409  //Reset the SHA/MD5 module before use
410  hashReset();
411 
412  //Configure the SHA/MD5 module
413  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA1;
414 
415  //Restore hash context
416  SHAMD5_IDIGEST_A_R = context->h[0];
417  SHAMD5_IDIGEST_B_R = context->h[1];
418  SHAMD5_IDIGEST_C_R = context->h[2];
419  SHAMD5_IDIGEST_D_R = context->h[3];
420  SHAMD5_IDIGEST_E_R = context->h[4];
421 
422  //Restore the value of the SHA_DIGEST_COUNT register
423  SHAMD5_DIGEST_COUNT_R = context->totalSize;
424 
425  //Process the incoming data
426  while(length > 0)
427  {
428  //Check whether some data is pending in the buffer
429  if(context->size == 0 && length >= 64)
430  {
431  //The length must be a multiple of 64 bytes
432  n = length - (length % 64);
433 
434  //Update hash value
436 
437  //Advance the data pointer
438  data = (uint8_t *) data + n;
439  //Remaining bytes to process
440  length -= n;
441  }
442  else
443  {
444  //The buffer can hold at most 64 bytes
445  n = MIN(length, 64 - context->size);
446 
447  //Copy the data to the buffer
448  osMemcpy(context->buffer + context->size, data, n);
449 
450  //Update the SHA-1 context
451  context->size += n;
452  //Advance the data pointer
453  data = (uint8_t *) data + n;
454  //Remaining bytes to process
455  length -= n;
456 
457  //Check whether the buffer is full
458  if(context->size == 64)
459  {
460  //Update hash value
461  hashProcessData(context->buffer, context->size, context->digest,
463 
464  //Empty the buffer
465  context->size = 0;
466  }
467  }
468  }
469 
470  //Save the value of the SHA_DIGEST_COUNT register
471  context->totalSize = SHAMD5_DIGEST_COUNT_R;
472 
473  //Release exclusive access to the SHA/MD5 module
475 }
476 
477 
478 /**
479  * @brief Finish the SHA-1 message digest
480  * @param[in] context Pointer to the SHA-1 context
481  * @param[out] digest Calculated digest (optional parameter)
482  **/
483 
484 void sha1Final(Sha1Context *context, uint8_t *digest)
485 {
486  //Acquire exclusive access to the SHA/MD5 module
488 
489  //Reset the SHA/MD5 module before use
490  hashReset();
491 
492  //Configure the SHA/MD5 module
493  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA1 | SHAMD5_MODE_CLOSE_HASH;
494 
495  //Restore hash context
496  SHAMD5_IDIGEST_A_R = context->h[0];
497  SHAMD5_IDIGEST_B_R = context->h[1];
498  SHAMD5_IDIGEST_C_R = context->h[2];
499  SHAMD5_IDIGEST_D_R = context->h[3];
500  SHAMD5_IDIGEST_E_R = context->h[4];
501 
502  //Restore the value of the SHA_DIGEST_COUNT register
503  SHAMD5_DIGEST_COUNT_R = context->totalSize;
504 
505  //Finish digest calculation
506  hashProcessData(context->buffer, context->size, context->digest,
508 
509  //Release exclusive access to the SHA/MD5 module
511 
512  //Copy the resulting digest
513  if(digest != NULL)
514  {
515  osMemcpy(digest, context->digest, SHA1_DIGEST_SIZE);
516  }
517 }
518 
519 
520 /**
521  * @brief Finish the SHA-1 message digest (no padding added)
522  * @param[in] context Pointer to the SHA-1 context
523  * @param[out] digest Calculated digest
524  **/
525 
526 void sha1FinalRaw(Sha1Context *context, uint8_t *digest)
527 {
528  //Copy the resulting digest
529  osMemcpy(digest, context->digest, SHA1_DIGEST_SIZE);
530 }
531 
532 #endif
533 #if (SHA224_SUPPORT == ENABLED)
534 
535 /**
536  * @brief Digest a message using SHA-224
537  * @param[in] data Pointer to the message being hashed
538  * @param[in] length Length of the message
539  * @param[out] digest Pointer to the calculated digest
540  * @return Error code
541  **/
542 
543 error_t sha224Compute(const void *data, size_t length, uint8_t *digest)
544 {
545  //Acquire exclusive access to the SHA/MD5 module
547 
548  //Reset the SHA/MD5 module before use
549  hashReset();
550 
551  //Configure the SHA/MD5 module
552  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA224 | SHAMD5_MODE_ALGO_CONSTANT |
553  SHAMD5_MODE_CLOSE_HASH;
554 
555  //Digest the message
557 
558  //Release exclusive access to the SHA/MD5 module
560 
561  //Sucessful processing
562  return NO_ERROR;
563 }
564 
565 
566 /**
567  * @brief Initialize SHA-224 message digest context
568  * @param[in] context Pointer to the SHA-224 context to initialize
569  **/
570 
571 void sha224Init(Sha224Context *context)
572 {
573  //Set initial hash value
574  context->h[0] = BETOH32(0xC1059ED8);
575  context->h[1] = BETOH32(0x367CD507);
576  context->h[2] = BETOH32(0x3070DD17);
577  context->h[3] = BETOH32(0xF70E5939);
578  context->h[4] = BETOH32(0xFFC00B31);
579  context->h[5] = BETOH32(0x68581511);
580  context->h[6] = BETOH32(0x64F98FA7);
581  context->h[7] = BETOH32(0xBEFA4FA4);
582 
583  //Number of bytes in the buffer
584  context->size = 0;
585  //Total length of the message
586  context->totalSize = 0;
587 }
588 
589 
590 /**
591  * @brief Finish the SHA-224 message digest
592  * @param[in] context Pointer to the SHA-224 context
593  * @param[out] digest Calculated digest (optional parameter)
594  **/
595 
596 void sha224Final(Sha224Context *context, uint8_t *digest)
597 {
598  //Acquire exclusive access to the SHA/MD5 module
600 
601  //Reset the SHA/MD5 module before use
602  hashReset();
603 
604  //Configure the SHA/MD5 module
605  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA224 | SHAMD5_MODE_CLOSE_HASH;
606 
607  //Restore hash context
608  SHAMD5_IDIGEST_A_R = context->h[0];
609  SHAMD5_IDIGEST_B_R = context->h[1];
610  SHAMD5_IDIGEST_C_R = context->h[2];
611  SHAMD5_IDIGEST_D_R = context->h[3];
612  SHAMD5_IDIGEST_E_R = context->h[4];
613  SHAMD5_IDIGEST_F_R = context->h[5];
614  SHAMD5_IDIGEST_G_R = context->h[6];
615  SHAMD5_IDIGEST_H_R = context->h[7];
616 
617  //Restore the value of the SHA_DIGEST_COUNT register
618  SHAMD5_DIGEST_COUNT_R = context->totalSize;
619 
620  //Finish digest calculation
621  hashProcessData(context->buffer, context->size, context->digest,
623 
624  //Release exclusive access to the SHA/MD5 module
626 
627  //Copy the resulting digest
628  if(digest != NULL)
629  {
630  osMemcpy(digest, context->digest, SHA224_DIGEST_SIZE);
631  }
632 }
633 
634 #endif
635 #if (SHA256_SUPPORT == ENABLED)
636 
637 /**
638  * @brief Digest a message using SHA-256
639  * @param[in] data Pointer to the message being hashed
640  * @param[in] length Length of the message
641  * @param[out] digest Pointer to the calculated digest
642  * @return Error code
643  **/
644 
645 error_t sha256Compute(const void *data, size_t length, uint8_t *digest)
646 {
647  //Acquire exclusive access to the SHA/MD5 module
649 
650  //Reset the SHA/MD5 module before use
651  hashReset();
652 
653  //Configure the SHA/MD5 module
654  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA256 | SHAMD5_MODE_ALGO_CONSTANT |
655  SHAMD5_MODE_CLOSE_HASH;
656 
657  //Digest the message
659 
660  //Release exclusive access to the SHA/MD5 module
662 
663  //Sucessful processing
664  return NO_ERROR;
665 }
666 
667 
668 /**
669  * @brief Initialize SHA-256 message digest context
670  * @param[in] context Pointer to the SHA-256 context to initialize
671  **/
672 
673 void sha256Init(Sha256Context *context)
674 {
675  //Set initial hash value
676  context->h[0] = BETOH32(0x6A09E667);
677  context->h[1] = BETOH32(0xBB67AE85);
678  context->h[2] = BETOH32(0x3C6EF372);
679  context->h[3] = BETOH32(0xA54FF53A);
680  context->h[4] = BETOH32(0x510E527F);
681  context->h[5] = BETOH32(0x9B05688C);
682  context->h[6] = BETOH32(0x1F83D9AB);
683  context->h[7] = BETOH32(0x5BE0CD19);
684 
685  //Number of bytes in the buffer
686  context->size = 0;
687  //Total length of the message
688  context->totalSize = 0;
689 }
690 
691 
692 /**
693  * @brief Update the SHA-256 context with a portion of the message being hashed
694  * @param[in] context Pointer to the SHA-256 context
695  * @param[in] data Pointer to the buffer being hashed
696  * @param[in] length Length of the buffer
697  **/
698 
699 void sha256Update(Sha256Context *context, const void *data, size_t length)
700 {
701  size_t n;
702 
703  //Acquire exclusive access to the SHA/MD5 module
705 
706  //Reset the SHA/MD5 module before use
707  hashReset();
708 
709  //Configure the SHA/MD5 module
710  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA256;
711 
712  //Restore hash context
713  SHAMD5_IDIGEST_A_R = context->h[0];
714  SHAMD5_IDIGEST_B_R = context->h[1];
715  SHAMD5_IDIGEST_C_R = context->h[2];
716  SHAMD5_IDIGEST_D_R = context->h[3];
717  SHAMD5_IDIGEST_E_R = context->h[4];
718  SHAMD5_IDIGEST_F_R = context->h[5];
719  SHAMD5_IDIGEST_G_R = context->h[6];
720  SHAMD5_IDIGEST_H_R = context->h[7];
721 
722  //Restore the value of the SHA_DIGEST_COUNT register
723  SHAMD5_DIGEST_COUNT_R = context->totalSize;
724 
725  //Process the incoming data
726  while(length > 0)
727  {
728  //Check whether some data is pending in the buffer
729  if(context->size == 0 && length >= 64)
730  {
731  //The length must be a multiple of 64 bytes
732  n = length - (length % 64);
733 
734  //Update hash value
736 
737  //Advance the data pointer
738  data = (uint8_t *) data + n;
739  //Remaining bytes to process
740  length -= n;
741  }
742  else
743  {
744  //The buffer can hold at most 64 bytes
745  n = MIN(length, 64 - context->size);
746 
747  //Copy the data to the buffer
748  osMemcpy(context->buffer + context->size, data, n);
749 
750  //Update the SHA-256 context
751  context->size += n;
752  //Advance the data pointer
753  data = (uint8_t *) data + n;
754  //Remaining bytes to process
755  length -= n;
756 
757  //Check whether the buffer is full
758  if(context->size == 64)
759  {
760  //Update hash value
761  hashProcessData(context->buffer, context->size, context->digest,
763 
764  //Empty the buffer
765  context->size = 0;
766  }
767  }
768  }
769 
770  //Save the value of the SHA_DIGEST_COUNT register
771  context->totalSize = SHAMD5_DIGEST_COUNT_R;
772 
773  //Release exclusive access to the SHA/MD5 module
775 }
776 
777 
778 /**
779  * @brief Finish the SHA-256 message digest
780  * @param[in] context Pointer to the SHA-256 context
781  * @param[out] digest Calculated digest (optional parameter)
782  **/
783 
784 void sha256Final(Sha256Context *context, uint8_t *digest)
785 {
786  //Acquire exclusive access to the SHA/MD5 module
788 
789  //Reset the SHA/MD5 module before use
790  hashReset();
791 
792  //Configure the SHA/MD5 module
793  SHAMD5_MODE_R = SHAMD5_MODE_ALGO_SHA256 | SHAMD5_MODE_CLOSE_HASH;
794 
795  //Restore hash context
796  SHAMD5_IDIGEST_A_R = context->h[0];
797  SHAMD5_IDIGEST_B_R = context->h[1];
798  SHAMD5_IDIGEST_C_R = context->h[2];
799  SHAMD5_IDIGEST_D_R = context->h[3];
800  SHAMD5_IDIGEST_E_R = context->h[4];
801  SHAMD5_IDIGEST_F_R = context->h[5];
802  SHAMD5_IDIGEST_G_R = context->h[6];
803  SHAMD5_IDIGEST_H_R = context->h[7];
804 
805  //Restore the value of the SHA_DIGEST_COUNT register
806  SHAMD5_DIGEST_COUNT_R = context->totalSize;
807 
808  //Finish digest calculation
809  hashProcessData(context->buffer, context->size, context->digest,
811 
812  //Release exclusive access to the SHA/MD5 module
814 
815  //Copy the resulting digest
816  if(digest != NULL)
817  {
818  osMemcpy(digest, context->digest, SHA256_DIGEST_SIZE);
819  }
820 }
821 
822 
823 /**
824  * @brief Finish the SHA-256 message digest (no padding added)
825  * @param[in] context Pointer to the SHA-256 context
826  * @param[out] digest Calculated digest
827  **/
828 
829 void sha256FinalRaw(Sha256Context *context, uint8_t *digest)
830 {
831  //Copy the resulting digest
832  osMemcpy(digest, context->digest, SHA256_DIGEST_SIZE);
833 }
834 
835 #endif
836 #endif
#define SHAMD5_DATA_5_IN_R
#define SHAMD5_DATA_10_IN_R
uint8_t digest[16]
Definition: md5.h:66
Tiva TM4C129 hardware cryptographic accelerator.
void md5Final(Md5Context *context, uint8_t *digest)
Finish the MD5 message digest.
#define SHAMD5_SYSCONFIG_R
SHA-256 algorithm context.
Definition: sha256.h:62
#define SHAMD5_SYSSTATUS_R
#define SHAMD5_IDIGEST_C_R
void sha224Init(Sha224Context *context)
Initialize SHA-224 message digest context.
uint8_t data[]
Definition: ethernet.h:222
#define STORE32LE(a, p)
Definition: cpu_endian.h:279
size_t size
Definition: sha256.h:73
#define SHA224_DIGEST_SIZE
Definition: sha224.h:41
void md5Update(Md5Context *context, const void *data, size_t length)
Update the MD5 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)
uint32_t h[8]
Definition: sha256.h:65
void sha256Final(Sha256Context *context, uint8_t *digest)
Finish the SHA-256 message digest.
error_t sha224Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-224.
#define BETOH32(value)
Definition: cpu_endian.h:451
#define SHAMD5_IDIGEST_A_R
void md5FinalRaw(Md5Context *context, uint8_t *digest)
Finish the MD5 message digest (no padding added)
#define SHAMD5_DATA_11_IN_R
void md5Init(Md5Context *context)
Initialize MD5 message digest context.
#define SHAMD5_DATA_13_IN_R
void hashProcessData(const uint8_t *data, size_t length, uint8_t *digest, size_t digestSize)
Update hash value.
#define SHAMD5_DATA_3_IN_R
uint64_t totalSize
Definition: sha1.h:74
#define SHAMD5_LENGTH_R
#define SHAMD5_DATA_6_IN_R
#define SHAMD5_IDIGEST_F_R
uint8_t buffer[64]
Definition: md5.h:71
void sha1Final(Sha1Context *context, uint8_t *digest)
Finish the SHA-1 message digest.
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
void sha256Update(Sha256Context *context, const void *data, size_t length)
Update the SHA-256 context with a portion of the message being hashed.
error_t
Error codes.
Definition: error.h:43
#define SHAMD5_IDIGEST_G_R
#define SHAMD5_DATA_12_IN_R
#define SHAMD5_IRQSTATUS_R
#define SHAMD5_IDIGEST_B_R
#define SHAMD5_DATA_4_IN_R
uint32_t h[5]
Definition: sha1.h:65
General definitions for cryptographic algorithms.
#define SHAMD5_DATA_2_IN_R
void sha224Final(Sha224Context *context, uint8_t *digest)
Finish the SHA-224 message digest.
MD5 algorithm context.
Definition: md5.h:62
void sha1Update(Sha1Context *context, const void *data, size_t length)
Update the SHA-1 context with a portion of the message being hashed.
Tiva TM4C129 hash hardware accelerator.
uint8_t length
Definition: tcp.h:368
uint8_t buffer[64]
Definition: sha256.h:71
#define MIN(a, b)
Definition: os_port.h:63
#define SHAMD5_DATA_1_IN_R
uint64_t totalSize
Definition: md5.h:74
#define SHAMD5_IDIGEST_E_R
#define MD5_DIGEST_SIZE
Definition: md5.h:45
OsMutex tm4c129CryptoMutex
Collection of hash algorithms.
#define SHAMD5_IDIGEST_D_R
uint8_t digest[32]
Definition: sha256.h:66
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-1.
#define SHAMD5_DATA_8_IN_R
uint8_t n
#define SHAMD5_IDIGEST_H_R
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
#define SHAMD5_MODE_R
size_t size
Definition: sha1.h:73
error_t md5Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using MD5.
size_t size
Definition: md5.h:73
#define SHAMD5_DATA_15_IN_R
#define SHAMD5_DATA_14_IN_R
SHA-1 algorithm context.
Definition: sha1.h:62
void sha1Init(Sha1Context *context)
Initialize SHA-1 message digest context.
#define SHAMD5_DATA_0_IN_R
uint8_t buffer[64]
Definition: sha1.h:71
void sha256FinalRaw(Sha256Context *context, uint8_t *digest)
Finish the SHA-256 message digest (no padding added)
#define LOAD32LE(p)
Definition: cpu_endian.h:203
uint64_t totalSize
Definition: sha256.h:74
#define SHAMD5_DIGEST_COUNT_R
#define SHAMD5_DATA_9_IN_R
#define SHAMD5_DATA_7_IN_R
#define SHA256_DIGEST_SIZE
Definition: sha256.h:45
void sha256Init(Sha256Context *context)
Initialize SHA-256 message digest context.
uint32_t h[4]
Definition: md5.h:65
error_t sha256Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-256.
uint8_t digest[20]
Definition: sha1.h:66
@ NO_ERROR
Success.
Definition: error.h:44
void hashReset(void)
Reset SHA/MD5 module.
Debugging facilities.