CC26xx Driver Library
[sha2.h] Secure Hash Algorithm 2

Functions

void SHA2StartDMAOperation (uint8_t *channel0Addr, uint32_t channel0Length, uint8_t *channel1Addr, uint32_t channel1Length)
 Start a crypto DMA operation. More...
 
uint32_t SHA2WaitForIRQFlags (uint32_t irqFlags)
 Poll the interrupt status register and clear when done. More...
 
uint32_t SHA2ComputeInitialHash (const uint8_t *message, uint32_t *intermediateDigest, uint32_t hashAlgorithm, uint32_t initialMessageLength)
 Start a new SHA-2 hash operation. More...
 
uint32_t SHA2ComputeIntermediateHash (const uint8_t *message, uint32_t *intermediateDigest, uint32_t hashAlgorithm, uint32_t intermediateMessageLength)
 Resume a SHA-2 hash operation but do not finalize it. More...
 
uint32_t SHA2ComputeFinalHash (const uint8_t *message, uint8_t *resultDigest, uint32_t *intermediateDigest, uint32_t totalMsgLength, uint32_t messageLength, uint32_t hashAlgorithm)
 Resume a SHA-2 hash operation and finalize it. More...
 
uint32_t SHA2ComputeHash (const uint8_t *message, uint8_t *resultDigest, uint32_t totalMsgLength, uint32_t hashAlgorithm)
 Start a SHA-2 hash operation and return the finalized digest. More...
 
static void SHA2SelectAlgorithm (uint32_t algorithm)
 Configure the crypto DMA for a particular operation. More...
 
static void SHA2SetMessageLength (uint32_t length)
 Specify the total length of the message. More...
 
static void SHA2SetDigest (uint32_t *digest, uint8_t digestLength)
 Load an intermediate digest. More...
 
static uint32_t SHA2GetDigest (uint32_t *digest, uint8_t digestLength)
 Read the intermediate or final digest. More...
 
static void SHA2ClearDigestAvailableFlag (void)
 Confirm digest was read. More...
 
static void SHA2IntEnable (uint32_t intFlags)
 Enable individual crypto interrupt sources. More...
 
static void SHA2IntDisable (uint32_t intFlags)
 Disable individual crypto interrupt sources. More...
 
static uint32_t SHA2IntStatusMasked (void)
 Get the current masked interrupt status. More...
 
static uint32_t SHA2IntStatusRaw (void)
 Get the current raw interrupt status. More...
 
static void SHA2IntClear (uint32_t intFlags)
 Clear crypto interrupt sources. More...
 
static void SHA2IntRegister (void(*handlerFxn)(void))
 Register an interrupt handler for a crypto interrupt in the dynamic interrupt table. More...
 
static void SHA2IntUnregister (void)
 Unregister an interrupt handler for a crypto interrupt in the dynamic interrupt table. More...
 

Detailed Description

Introduction

The SHA-2 (Secure Hash Algorithm) API provides access to the SHA-2 functionality of the crypto core. The AES accelerator and keystore are also contained within the crypto core. Hence, only one of SHA-2 and AES may be used at the same time. This module offers hardware acceleration for the SHA-2 family of hash algorithms. The following output digest sizes are supported:

Messages are hashed in one go or in multiple steps. Stepwise hashing consists of an initial hash, multiple intermediate hashes, and a finalization hash.

The crypto core does not have retention and all configuration settings are lost when going into standby or shutdown. If you wish to continue a hash operation after going into standby or shutdown, you must load the intermediate hash into system RAM before entering standby or shutdown and load the intermediate hash back into the crypto module after resuming operation.

Function Documentation

static void SHA2ClearDigestAvailableFlag ( void  )
inlinestatic

Confirm digest was read.

Referenced by SHA2ExecuteHash().

569 {
571 }
uint32_t SHA2ComputeFinalHash ( const uint8_t *  message,
uint8_t *  resultDigest,
uint32_t *  intermediateDigest,
uint32_t  totalMsgLength,
uint32_t  messageLength,
uint32_t  hashAlgorithm 
)

Resume a SHA-2 hash operation and finalize it.

This function resumes a previous hash session.

Call this function when continuing a hash operation and the message is complete.

Parameters
[in]messageByte array containing the final block of the message to hash. Any length <= the block size is acceptable. The DMA finalize the message as necessary.
[out]resultDigestByte array that the final digest will be written to. Must be of a length equal to the digest length of the selected hash algorithm.
[in]intermediateDigestPointer to intermediate digest.
  • NULL The intermediate digest will be sourced from the internal registers of the SHA module.
  • Not NULL Specifies the location the intermediate digest will be read from. Must be of a length equal to the digest length of the selected hash algorithm. Must be 32-bit aligned. intermediateDigest is copied from and to the registers through the AHB slave interface. This can only be done word-by-word.
[in]totalMsgLengthThe length in bytes of the entire message including the sections passed to previous calls to SHA2ComputeInitialHash() and SHA2ComputeIntermediateHash().
[in]messageLengthThe length in bytes of the last section of the message to process. Does not need to be a multiple of the block size.
[in]hashAlgorithmSelects the hash algorithm to use. One of:
Returns
Returns a SHA-2 return code.
See also
SHA2ComputeInitialHash()
SHA2ComputeIntermediateHash()
168 {
169  ASSERT(message);
170  ASSERT(totalMsgLength);
171  ASSERT(!(intermediateDigest == NULL) && !((uint32_t)intermediateDigest & 0x03));
172  ASSERT(resultDigest);
173  ASSERT((hashAlgorithm == SHA2_MODE_SELECT_SHA224) ||
174  (hashAlgorithm == SHA2_MODE_SELECT_SHA256) ||
175  (hashAlgorithm == SHA2_MODE_SELECT_SHA384) ||
176  (hashAlgorithm == SHA2_MODE_SELECT_SHA512));
177 
178  return SHA2ExecuteHash(message, resultDigest, intermediateDigest, totalMsgLength, messageLength, hashAlgorithm, false, true);
179 }
#define SHA2_MODE_SELECT_SHA224
Definition: sha2.h:131
#define SHA2_MODE_SELECT_SHA512
Definition: sha2.h:134
static uint32_t SHA2ExecuteHash(const uint8_t *message, uint8_t *resultDigest, uint32_t *intermediateDigest, uint32_t totalMsgLength, uint32_t messageLength, uint32_t hashAlgorithm, bool initialHash, bool finalHash)
Definition: sha2.c:204
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_MODE_SELECT_SHA256
Definition: sha2.h:132
#define SHA2_MODE_SELECT_SHA384
Definition: sha2.h:133

Here is the call graph for this function:

uint32_t SHA2ComputeHash ( const uint8_t *  message,
uint8_t *  resultDigest,
uint32_t  totalMsgLength,
uint32_t  hashAlgorithm 
)

Start a SHA-2 hash operation and return the finalized digest.

This function starts a hash operation and returns the finalized digest.

Use this function if the entire message is available when starting the hash.

Parameters
[in]messageByte array containing the message that will be hashed. Any length <= the block size is acceptable. The DMA will finalize the message as necessary.
[out]resultDigestByte array that the final digest will be written to. Must be of a length equal to the digest length of the selected hash algorithm.
[in]totalMsgLengthThe length in bytes of the entire message.
[in]hashAlgorithmSelects the hash algorithm to use. One of:
Returns
Returns a SHA-2 return code.
187 {
188  ASSERT(message);
189  ASSERT(totalMsgLength);
190  ASSERT(resultDigest);
191  ASSERT((hashAlgorithm == SHA2_MODE_SELECT_SHA224) ||
192  (hashAlgorithm == SHA2_MODE_SELECT_SHA256) ||
193  (hashAlgorithm == SHA2_MODE_SELECT_SHA384) ||
194  (hashAlgorithm == SHA2_MODE_SELECT_SHA512));
195 
196  return SHA2ExecuteHash(message, resultDigest, 0, totalMsgLength, totalMsgLength, hashAlgorithm, true, true);
197 }
#define SHA2_MODE_SELECT_SHA224
Definition: sha2.h:131
#define SHA2_MODE_SELECT_SHA512
Definition: sha2.h:134
static uint32_t SHA2ExecuteHash(const uint8_t *message, uint8_t *resultDigest, uint32_t *intermediateDigest, uint32_t totalMsgLength, uint32_t messageLength, uint32_t hashAlgorithm, bool initialHash, bool finalHash)
Definition: sha2.c:204
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_MODE_SELECT_SHA256
Definition: sha2.h:132
#define SHA2_MODE_SELECT_SHA384
Definition: sha2.h:133

Here is the call graph for this function:

uint32_t SHA2ComputeInitialHash ( const uint8_t *  message,
uint32_t *  intermediateDigest,
uint32_t  hashAlgorithm,
uint32_t  initialMessageLength 
)

Start a new SHA-2 hash operation.

This function begins a new piecewise hash operation.

Call this function when starting a new hash operation and the entire message is not yet available.

Call SHA2ComputeIntermediateHash() or SHA2ComputeFinalHash() after this call.

If the device shall go into standby in between calls to this function and either SHA2ComputeIntermediateHash() or SHA2ComputeFinalHash(), the intermediate digest must be saved in system RAM.

Parameters
[in]messageByte array containing the start of the message to hash. Must be exactly as long as the block length of the selected algorithm.
[out]intermediateDigestPointer to intermediate digest.
  • NULL The intermediate digest will be stored in the internal registers of the SHA module.
  • Not NULL Specifies the location the intermediate digest will be written to.

    Must be of a length equal to the digest length of the selected hash algorithm. Must be 32-bit aligned. intermediateDigest is copied into the registers through the AHB slave interface in SHA2ComputeIntermediateHash() and SHA2ComputeFinalHash(). This can only be done word-by-word.

[in]hashAlgorithmSelects the hash algorithm to use. One of:
[in]initialMessageLengthThe length in bytes of the first section of the message to process. Must be a multiple of the block size.
Returns
Returns a SHA-2 return code.
See also
SHA2ComputeIntermediateHash()
SHA2ComputeFinalHash()
134 {
135  ASSERT(message);
136  ASSERT((hashAlgorithm == SHA2_MODE_SELECT_SHA224) ||
137  (hashAlgorithm == SHA2_MODE_SELECT_SHA256) ||
138  (hashAlgorithm == SHA2_MODE_SELECT_SHA384) ||
139  (hashAlgorithm == SHA2_MODE_SELECT_SHA512));
140  ASSERT(!(intermediateDigest == NULL) && !((uint32_t)intermediateDigest & 0x03));
141 
142  return SHA2ExecuteHash(message, (uint8_t *)intermediateDigest, intermediateDigest, initialMessageLength, initialMessageLength, hashAlgorithm, true, false);
143 }
#define SHA2_MODE_SELECT_SHA224
Definition: sha2.h:131
#define SHA2_MODE_SELECT_SHA512
Definition: sha2.h:134
static uint32_t SHA2ExecuteHash(const uint8_t *message, uint8_t *resultDigest, uint32_t *intermediateDigest, uint32_t totalMsgLength, uint32_t messageLength, uint32_t hashAlgorithm, bool initialHash, bool finalHash)
Definition: sha2.c:204
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_MODE_SELECT_SHA256
Definition: sha2.h:132
#define SHA2_MODE_SELECT_SHA384
Definition: sha2.h:133

Here is the call graph for this function:

uint32_t SHA2ComputeIntermediateHash ( const uint8_t *  message,
uint32_t *  intermediateDigest,
uint32_t  hashAlgorithm,
uint32_t  intermediateMessageLength 
)

Resume a SHA-2 hash operation but do not finalize it.

This function resumes a previous hash operation.

Call this function when continuing a hash operation and the message is not yet complete.

Call this function again or SHA2ComputeFinalHash() after this call.

If the device shall go into standby in between calls to this function and SHA2ComputeFinalHash(), the intermediate digest must be saved in system RAM.

Parameters
[in]messageByte array containing the start of the current block of the message to hash. Must be exactly as long as the block length of the selected algorithm.
[in,out]intermediateDigestPointer to intermediate digest.
  • NULL The intermediate digest will be sourced from the internal registers of the SHA module and stored there after the operation completes.
  • Not NULL Specifies the location the intermediate digest will be read from and written to.

    Must be of a length equal to the digest length of the selected hash algorithm. Must be 32-bit aligned. intermediateDigest is copied from and to the registers through the AHB slave interface. This can only be done word-by-word.

[in]hashAlgorithmSelects the hash algorithm to use. One of:
[in]intermediateMessageLengthThe length in bytes of this section of the message to process. Must be a multiple of the block size.
Returns
Returns a SHA-2 return code.
See also
SHA2ComputeInitialHash()
SHA2ComputeFinalHash()
151 {
152  ASSERT(message);
153  ASSERT(!(intermediateDigest == NULL) && !((uint32_t)intermediateDigest & 0x03));
154  ASSERT((hashAlgorithm == SHA2_MODE_SELECT_SHA224) ||
155  (hashAlgorithm == SHA2_MODE_SELECT_SHA256) ||
156  (hashAlgorithm == SHA2_MODE_SELECT_SHA384) ||
157  (hashAlgorithm == SHA2_MODE_SELECT_SHA512));
158 
159  return SHA2ExecuteHash(message, (uint8_t *)intermediateDigest, intermediateDigest, 0, intermediateMessageLength, hashAlgorithm, false, false);
160 }
#define SHA2_MODE_SELECT_SHA224
Definition: sha2.h:131
#define SHA2_MODE_SELECT_SHA512
Definition: sha2.h:134
static uint32_t SHA2ExecuteHash(const uint8_t *message, uint8_t *resultDigest, uint32_t *intermediateDigest, uint32_t totalMsgLength, uint32_t messageLength, uint32_t hashAlgorithm, bool initialHash, bool finalHash)
Definition: sha2.c:204
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_MODE_SELECT_SHA256
Definition: sha2.h:132
#define SHA2_MODE_SELECT_SHA384
Definition: sha2.h:133

Here is the call graph for this function:

static uint32_t SHA2GetDigest ( uint32_t *  digest,
uint8_t  digestLength 
)
inlinestatic

Read the intermediate or final digest.

Parameters
[in]digestLengthLength of the digest in bytes. Must be one of:
  • ref SHA2_SHA224_DIGEST_LENGTH_BYTES
  • ref SHA2_SHA256_DIGEST_LENGTH_BYTES
  • ref SHA2_SHA384_DIGEST_LENGTH_BYTES
  • ref SHA2_SHA512_DIGEST_LENGTH_BYTES
[out]digestPointer to an intermediate digest. Must be 32-bit aligned.
Returns
Returns a status code.
542 {
543  // Check the arguments.
544  ASSERT(!(digest == NULL) && !((uint32_t)digest & 0x03));
545  ASSERT((digestLength == SHA2_SHA224_DIGEST_LENGTH_BYTES) ||
546  (digestLength == SHA2_SHA256_DIGEST_LENGTH_BYTES) ||
547  (digestLength == SHA2_SHA384_DIGEST_LENGTH_BYTES) ||
548  (digestLength == SHA2_SHA512_DIGEST_LENGTH_BYTES));
549 
552  }
553  else {
554  // Read digest
555  uint32_t i = 0;
556  for (i = 0; i < (digestLength / sizeof(uint32_t)); i++) {
557  digest[i] = HWREG(CRYPTO_BASE + CRYPTO_O_HASHDIGESTA + (i * sizeof(uint32_t)));
558  }
559  return SHA2_SUCCESS;
560  }
561 }
#define SHA2_OLD_DIGEST_NOT_READ
Definition: sha2.h:121
#define SHA2_SHA512_DIGEST_LENGTH_BYTES
Definition: sha2.h:127
#define SHA2_SHA384_DIGEST_LENGTH_BYTES
Definition: sha2.h:126
#define SHA2_SHA224_DIGEST_LENGTH_BYTES
Definition: sha2.h:124
#define SHA2_SHA256_DIGEST_LENGTH_BYTES
Definition: sha2.h:125
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_SUCCESS
Definition: sha2.h:116
static void SHA2IntClear ( uint32_t  intFlags)
inlinestatic

Clear crypto interrupt sources.

The specified crypto interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being recognized again immediately upon exit.

Note
Due to write buffers and synchronizers in the system it may take several clock cycles from a register write clearing an event in the module until the event is actually cleared in the NVIC of the system CPU. It is recommended to clear the event source early in the interrupt service routine (ISR) to allow the event clear to propagate to the NVIC before returning from the ISR.
Parameters
intFlagsis a bit mask of the interrupt sources to be cleared.
Returns
None

Referenced by SHA2ExecuteHash().

688 {
689  // Check the arguments.
690  ASSERT((intFlags & SHA2_DMA_IN_DONE) ||
691  (intFlags & SHA2_RESULT_RDY));
692 
693  // Clear the requested interrupt sources,
694  HWREG(CRYPTO_BASE + CRYPTO_O_IRQCLR) = intFlags;
695 }
#define SHA2_RESULT_RDY
Definition: sha2.h:105
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_DMA_IN_DONE
Definition: sha2.h:104
static void SHA2IntDisable ( uint32_t  intFlags)
inlinestatic

Disable individual crypto interrupt sources.

This function disables the indicated crypto interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt. Disabled sources have no effect on the processor.

Parameters
intFlagsis the bitwise OR of the interrupt sources to be enabled.
Returns
None
617 {
618  // Check the arguments.
619  ASSERT((intFlags & SHA2_DMA_IN_DONE) ||
620  (intFlags & SHA2_RESULT_RDY));
621 
622  // Disable the specified interrupts.
623  HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN) &= ~intFlags;
624 }
#define SHA2_RESULT_RDY
Definition: sha2.h:105
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_DMA_IN_DONE
Definition: sha2.h:104
static void SHA2IntEnable ( uint32_t  intFlags)
inlinestatic

Enable individual crypto interrupt sources.

This function enables the indicated crypto interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt. Disabled sources have no effect on the processor.

Parameters
intFlagsis the bitwise OR of the interrupt sources to be enabled.
Returns
None

Referenced by SHA2ExecuteHash().

589 {
590  // Check the arguments.
591  ASSERT((intFlags & SHA2_DMA_IN_DONE) ||
592  (intFlags & SHA2_RESULT_RDY));
593 
594  // Using level interrupt.
596 
597  // Enable the specified interrupts.
598  HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN) |= intFlags;
599 }
#define SHA2_RESULT_RDY
Definition: sha2.h:105
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_DMA_IN_DONE
Definition: sha2.h:104
static void SHA2IntRegister ( void(*)(void)  handlerFxn)
inlinestatic

Register an interrupt handler for a crypto interrupt in the dynamic interrupt table.

Note
Only use this function if you want to use the dynamic vector table (in SRAM)!

This function registers a function as the interrupt handler for a specific interrupt and enables the corresponding interrupt in the interrupt controller.

Specific crypto interrupts must be enabled via SHA2IntEnable(). It is the interrupt handler's responsibility to clear the interrupt source.

Parameters
handlerFxnis a pointer to the function to be called when the crypto interrupt occurs.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
719 {
720  // Register the interrupt handler.
721  IntRegister(INT_CRYPTO_RESULT_AVAIL_IRQ, handlerFxn);
722 
723  // Enable the crypto interrupt.
724  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
725 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:153
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283

Here is the call graph for this function:

static uint32_t SHA2IntStatusMasked ( void  )
inlinestatic

Get the current masked interrupt status.

This function returns the masked interrupt status of the crypto module.

Returns
Returns the status of the masked lines when enabled:
638 {
639  uint32_t mask;
640 
641  // Return the masked interrupt status
642  mask = HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN);
643  return(mask & HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT));
644 }
static uint32_t SHA2IntStatusRaw ( void  )
inlinestatic

Get the current raw interrupt status.

This function returns the raw interrupt status of the crypto module. It returns both the status of the lines routed to the NVIC as well as the error flags.

Returns
Returns the raw interrupt status:
661 {
662  // Return either the raw interrupt status
663  return(HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT));
664 }
static void SHA2IntUnregister ( void  )
inlinestatic

Unregister an interrupt handler for a crypto interrupt in the dynamic interrupt table.

This function does the actual unregistering of the interrupt handler. It clears the handler called when a crypto interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
743 {
744  // Disable the interrupt.
745  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
746 
747  // Unregister the interrupt handler.
748  IntUnregister(INT_CRYPTO_RESULT_AVAIL_IRQ);
749 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:189
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327

Here is the call graph for this function:

static void SHA2SelectAlgorithm ( uint32_t  algorithm)
inlinestatic

Configure the crypto DMA for a particular operation.

Parameters
algorithmConfigures the crypto DMA for a particular operation. It also powers on the respective part of the system. SHA2_ALGSEL_TAG may be combined with another flag. All other flags are mutually exclusive.
Returns
None

Referenced by SHA2ExecuteHash().

456 {
457  ASSERT((algorithm == SHA2_ALGSEL_SHA256) ||
458  (algorithm == SHA2_ALGSEL_SHA512) ||
459  (algorithm == SHA2_ALGSEL_SHA256 | SHA2_ALGSEL_TAG) ||
460  (algorithm == SHA2_ALGSEL_SHA512 | SHA2_ALGSEL_TAG));
461 
462  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = algorithm;
463 }
#define SHA2_ALGSEL_SHA512
Definition: sha2.h:151
#define SHA2_ALGSEL_TAG
Definition: sha2.h:152
#define ASSERT(expr)
Definition: debug.h:73
#define SHA2_ALGSEL_SHA256
Definition: sha2.h:150
static void SHA2SetDigest ( uint32_t *  digest,
uint8_t  digestLength 
)
inlinestatic

Load an intermediate digest.

Parameters
[in]digestLengthLength of the digest in bytes. Must be one of:
[in]digestPointer to an intermediate digest. Must be 32-bit aligned.

Referenced by SHA2ExecuteHash().

507 {
508  // Check the arguments.
509  ASSERT(!(digest == NULL) && !((uint32_t)digest & 0x03));
510  ASSERT((digestLength == SHA2_SHA224_DIGEST_LENGTH_BYTES) ||
511  (digestLength == SHA2_SHA256_DIGEST_LENGTH_BYTES) ||
512  (digestLength == SHA2_SHA384_DIGEST_LENGTH_BYTES) ||
513  (digestLength == SHA2_SHA512_DIGEST_LENGTH_BYTES));
514 
515  // Write digest
516  uint32_t i = 0;
517  for (i = 0; i < (digestLength / sizeof(uint32_t)); i++) {
518  HWREG(CRYPTO_BASE + CRYPTO_O_HASHDIGESTA + (i * sizeof(uint32_t))) = digest[i];
519  }
520 
521 }
#define SHA2_SHA512_DIGEST_LENGTH_BYTES
Definition: sha2.h:127
#define SHA2_SHA384_DIGEST_LENGTH_BYTES
Definition: sha2.h:126
#define SHA2_SHA224_DIGEST_LENGTH_BYTES
Definition: sha2.h:124
#define SHA2_SHA256_DIGEST_LENGTH_BYTES
Definition: sha2.h:125
#define ASSERT(expr)
Definition: debug.h:73
static void SHA2SetMessageLength ( uint32_t  length)
inlinestatic

Specify the total length of the message.

Despite specifying it here, the crypto DMA must still be set up with the correct data length.

Call this function only when setting up the final hash operation to enable finalization.

Parameters
lengthTotal message length in bits.
Returns
None
See also
SHA2StartDMAOperation()

Referenced by SHA2ExecuteHash().

485 {
486  HWREG(CRYPTO_BASE + CRYPTO_O_HASHINLENL) = length;
487  // CRYPTO_O_HASHINLENH is automatically set to 0. No need for the extra write.
488 }
void SHA2StartDMAOperation ( uint8_t *  channel0Addr,
uint32_t  channel0Length,
uint8_t *  channel1Addr,
uint32_t  channel1Length 
)

Start a crypto DMA operation.

Enable the crypto DMA channels, configure the channel addresses, and set the length of the data transfer. Setting the length of the data transfer automatically starts the transfer. It is also used by the hardware module as a signal to begin the encryption, decryption, or MAC operation.

Parameters
[in]channel0AddrA pointer to the address channel 0 shall use.
[in]channel0LengthLength of the data in bytes to be read from or written to at channel0Addr. Set to 0 to not set up this channel.
[out]channel1AddrA pointer to the address channel 1 shall use.
[in]channel1LengthLength of the data in bytes to be read from or written to at channel1Addr. Set to 0 to not set up this channel.
Returns
None

Referenced by SHA2ExecuteHash().

72 {
73 
74  // Clear any outstanding events.
76 
78 
79  if (channel0Addr) {
80  // Configure the DMA controller - enable both DMA channels.
82 
83  // Base address of the payload data in ext. memory.
84  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)channel0Addr;
85 
86  // Payload data length in bytes, equal to the cipher text length.
87  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = channel0Length;
88  }
89 
90  if (channel1Addr) {
91  // Enable DMA channel 1.
93 
94  // Base address of the output data buffer.
95  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)channel1Addr;
96 
97  // Output data length in bytes, equal to the cipher text length.
98  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = channel1Length;
99  }
100 }
uint32_t SHA2WaitForIRQFlags ( uint32_t  irqFlags)

Poll the interrupt status register and clear when done.

This function polls until one of the bits in the irqFlags is asserted. Only SHA2_DMA_IN_DONE and SHA2_RESULT_RDY can actually trigger the interrupt line. That means that one of those should always be included in irqFlags and will always be returned together with any error codes.

Parameters
[in]irqFlagsIRQ flags to poll and mask that the status register will be masked with. Consists of any bitwise OR of the flags below that includes at least one of SHA2_DMA_IN_DONE or SHA2_RESULT_RDY :
Returns
Returns the IRQ status register masked with irqFlags. May be any bitwise OR of the following masks:
108 {
109  uint32_t irqTrigger = 0;
110  // Wait for the DMA operation to complete. Add a delay to make sure we are
111  // not flooding the bus with requests too much.
112  do {
113  CPUdelay(1);
114  }
116 
117  // Save the IRQ trigger source
118  irqTrigger = HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT);
119 
120  // Clear IRQ flags
121  HWREG(CRYPTO_BASE + CRYPTO_O_IRQCLR) = irqFlags;
122 
124 
125  return irqTrigger;
126 }
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343

Here is the call graph for this function:

Macro Definition Documentation

#define SHA2_ALGSEL_SHA256   0x04
#define SHA2_ALGSEL_SHA512   0x08
#define SHA2_ALGSEL_TAG   (CRYPTO_ALGSEL_TAG_M)
#define SHA2_DIGEST_NOT_READY   5
#define SHA2_DMA_BUS_ERR   (CRYPTO_IRQCLR_DMA_BUS_ERR_M)
#define SHA2_DMA_BUSY   3
#define SHA2_DMA_CHANNEL0_ACTIVE   (CRYPTO_DMASTAT_CH0_ACT_M)
#define SHA2_DMA_CHANNEL1_ACTIVE   (CRYPTO_DMASTAT_CH1_ACT_M)
#define SHA2_DMA_ERROR   4
#define SHA2_DMA_IN_DONE   (CRYPTO_IRQEN_DMA_IN_DONE_M)
#define SHA2_DMA_PORT_ERROR   (CRYPTO_DMASTAT_PORT_ERR_M)
#define SHA2_INVALID_ALGORITHM   1

Referenced by SHA2ExecuteHash().

#define SHA2_MODE_SELECT_NEW_HASH   (CRYPTO_HASHMODE_NEW_HASH_M)
#define SHA2_OLD_DIGEST_NOT_READ   6

Referenced by SHA2GetDigest().

#define SHA2_SHA224_BLOCK_SIZE_BYTES   (512 / 8)
#define SHA2_SHA224_DIGEST_LENGTH_BYTES   (224 / 8)
#define SHA2_SHA256_BLOCK_SIZE_BYTES   (512 / 8)
#define SHA2_SHA256_DIGEST_LENGTH_BYTES   (256 / 8)
#define SHA2_SHA384_BLOCK_SIZE_BYTES   (1024 / 8)
#define SHA2_SHA384_DIGEST_LENGTH_BYTES   (384 / 8)
#define SHA2_SHA512_BLOCK_SIZE_BYTES   (1024 / 8)
#define SHA2_SHA512_DIGEST_LENGTH_BYTES   (512 / 8)
#define SHA2_SUCCESS   0

Referenced by SHA2ExecuteHash(), and SHA2GetDigest().