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... | |
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.
|
inlinestatic |
Confirm digest was read.
Referenced by SHA2ExecuteHash().
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.
[in] | message | Byte 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] | resultDigest | Byte 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] | intermediateDigest | Pointer to intermediate digest.
|
[in] | totalMsgLength | The length in bytes of the entire message including the sections passed to previous calls to SHA2ComputeInitialHash() and SHA2ComputeIntermediateHash(). |
[in] | messageLength | The length in bytes of the last section of the message to process. Does not need to be a multiple of the block size. |
[in] | hashAlgorithm | Selects the hash algorithm to use. One of: |
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.
[in] | message | Byte array containing the message that will be hashed. Any length <= the block size is acceptable. The DMA will finalize the message as necessary. |
[out] | resultDigest | Byte 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] | totalMsgLength | The length in bytes of the entire message . |
[in] | hashAlgorithm | Selects the hash algorithm to use. One of: |
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.
[in] | message | Byte array containing the start of the message to hash. Must be exactly as long as the block length of the selected algorithm. |
[out] | intermediateDigest | Pointer to intermediate digest.
|
[in] | hashAlgorithm | Selects the hash algorithm to use. One of: |
[in] | initialMessageLength | The length in bytes of the first section of the message to process. Must be a multiple of the block size. |
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.
[in] | message | Byte 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] | intermediateDigest | Pointer to intermediate digest.
|
[in] | hashAlgorithm | Selects the hash algorithm to use. One of: |
[in] | intermediateMessageLength | The length in bytes of this section of the message to process. Must be a multiple of the block size. |
|
inlinestatic |
Read the intermediate or final digest.
[in] | digestLength | Length of the digest in bytes. Must be one of:
|
[out] | digest | Pointer to an intermediate digest. Must be 32-bit aligned. |
|
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.
intFlags | is a bit mask of the interrupt sources to be cleared. |
Referenced by SHA2ExecuteHash().
|
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.
intFlags | is the bitwise OR of the interrupt sources to be enabled. |
|
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.
intFlags | is the bitwise OR of the interrupt sources to be enabled. |
Referenced by SHA2ExecuteHash().
|
inlinestatic |
Register an interrupt handler for a crypto interrupt in the dynamic interrupt table.
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.
handlerFxn | is a pointer to the function to be called when the crypto interrupt occurs. |
|
inlinestatic |
Get the current masked interrupt status.
This function returns the masked interrupt status of the crypto module.
|
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.
|
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.
|
inlinestatic |
Configure the crypto DMA for a particular operation.
algorithm | Configures 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.
|
Referenced by SHA2ExecuteHash().
|
inlinestatic |
Load an intermediate digest.
[in] | digestLength | Length of the digest in bytes. Must be one of: |
[in] | digest | Pointer to an intermediate digest. Must be 32-bit aligned. |
Referenced by SHA2ExecuteHash().
|
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.
length | Total message length in bits. |
Referenced by SHA2ExecuteHash().
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.
[in] | channel0Addr | A pointer to the address channel 0 shall use. |
[in] | channel0Length | Length of the data in bytes to be read from or written to at channel0Addr . Set to 0 to not set up this channel. |
[out] | channel1Addr | A pointer to the address channel 1 shall use. |
[in] | channel1Length | Length of the data in bytes to be read from or written to at channel1Addr . Set to 0 to not set up this channel. |
Referenced by SHA2ExecuteHash().
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.
[in] | irqFlags | IRQ 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 : |
irqFlags
. May be any bitwise OR of the following masks:
#define SHA2_ALGSEL_SHA256 0x04 |
Referenced by SHA2ExecuteHash(), and SHA2SelectAlgorithm().
#define SHA2_ALGSEL_SHA512 0x08 |
Referenced by SHA2ExecuteHash(), and SHA2SelectAlgorithm().
#define SHA2_ALGSEL_TAG (CRYPTO_ALGSEL_TAG_M) |
Referenced by SHA2ExecuteHash(), and SHA2SelectAlgorithm().
#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) |
Referenced by SHA2ExecuteHash(), SHA2IntClear(), SHA2IntDisable(), and SHA2IntEnable().
#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_MODE_SELECT_SHA224 (CRYPTO_HASHMODE_SHA224_MODE_M) |
#define SHA2_MODE_SELECT_SHA256 (CRYPTO_HASHMODE_SHA256_MODE_M) |
#define SHA2_MODE_SELECT_SHA384 (CRYPTO_HASHMODE_SHA384_MODE_M) |
#define SHA2_MODE_SELECT_SHA512 (CRYPTO_HASHMODE_SHA512_MODE_M) |
#define SHA2_OLD_DIGEST_NOT_READ 6 |
Referenced by SHA2GetDigest().
#define SHA2_RESULT_RDY (CRYPTO_IRQEN_RESULT_AVAIL_M) |
Referenced by SHA2ExecuteHash(), SHA2IntClear(), SHA2IntDisable(), and SHA2IntEnable().
#define SHA2_SHA224_BLOCK_SIZE_BYTES (512 / 8) |
#define SHA2_SHA224_DIGEST_LENGTH_BYTES (224 / 8) |
Referenced by SHA2ExecuteHash(), SHA2GetDigest(), and SHA2SetDigest().
#define SHA2_SHA256_BLOCK_SIZE_BYTES (512 / 8) |
#define SHA2_SHA256_DIGEST_LENGTH_BYTES (256 / 8) |
Referenced by SHA2ExecuteHash(), SHA2GetDigest(), and SHA2SetDigest().
#define SHA2_SHA384_BLOCK_SIZE_BYTES (1024 / 8) |
#define SHA2_SHA384_DIGEST_LENGTH_BYTES (384 / 8) |
Referenced by SHA2ExecuteHash(), SHA2GetDigest(), and SHA2SetDigest().
#define SHA2_SHA512_BLOCK_SIZE_BYTES (1024 / 8) |
#define SHA2_SHA512_DIGEST_LENGTH_BYTES (512 / 8) |
Referenced by SHA2ExecuteHash(), SHA2GetDigest(), and SHA2SetDigest().
#define SHA2_SUCCESS 0 |
Referenced by SHA2ExecuteHash(), and SHA2GetDigest().