MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

SHA Functional Operation

status_t SHA_Init (SHA_Type *base, sha_ctx_t *ctx, sha_algo_t algo)
 Initialize HASH context. More...
 
status_t SHA_Update (SHA_Type *base, sha_ctx_t *ctx, const uint8_t *message, size_t messageSize)
 Add data to current HASH. More...
 
status_t SHA_Finish (SHA_Type *base, sha_ctx_t *ctx, uint8_t *output, size_t *outputSize)
 Finalize hashing. More...
 
void SHA_SetCallback (SHA_Type *base, sha_ctx_t *ctx, sha_callback_t callback, void *userData)
 Initializes the SHA handle for background hashing. More...
 
status_t SHA_UpdateNonBlocking (SHA_Type *base, sha_ctx_t *ctx, const uint8_t *input, size_t inputSize)
 Create running hash on given data. More...
 
void SHA_ClkInit (SHA_Type *base)
 Start SHA clock. More...
 
void SHA_ClkDeinit (SHA_Type *base)
 Stop SHA clock. More...
 

Function Documentation

status_t SHA_Init ( SHA_Type *  base,
sha_ctx_t ctx,
sha_algo_t  algo 
)

This function initializes new hash context.

Parameters
baseSHA peripheral base address
[out]ctxOutput hash context
algoUnderlaying algorithm to use for hash computation. Either SHA-1 or SHA-256.
Returns
Status of initialization
status_t SHA_Update ( SHA_Type *  base,
sha_ctx_t ctx,
const uint8_t *  message,
size_t  messageSize 
)

Add data to current HASH. This can be called repeatedly with an arbitrary amount of data to be hashed.

Parameters
baseSHA peripheral base address
[in,out]ctxHASH context
messageInput message
messageSizeSize of input message in bytes
Returns
Status of the hash update operation
status_t SHA_Finish ( SHA_Type *  base,
sha_ctx_t ctx,
uint8_t *  output,
size_t *  outputSize 
)

Outputs the final hash and erases the context. SHA-1 or SHA-256 padding bits are automatically added by this function.

Parameters
baseSHA peripheral base address
[in,out]ctxHASH context
[out]outputOutput hash data
[in,out]outputSizeOn input, determines the size of bytes of the output array. On output, tells how many bytes have been written to output.
Returns
Status of the hash finish operation
void SHA_SetCallback ( SHA_Type *  base,
sha_ctx_t ctx,
sha_callback_t  callback,
void *  userData 
)

This function initializes the hash context for background hashing (Non-blocking) APIs. This is less typical interface to hash function, but can be used for parallel processing, when main CPU has something else to do. Example is digital signature RSASSA-PKCS1-V1_5-VERIFY((n,e),M,S) algorithm, where background hashing of M can be started, then CPU can compute S^e mod n (in parallel with background hashing) and once the digest becomes available, CPU can proceed to comparison of EM with EM'.

Parameters
baseSHA peripheral base address.
[out]ctxHash context.
callbackCallback function.
userDataUser data (to be passed as an argument to callback function, once callback is invoked from isr).
status_t SHA_UpdateNonBlocking ( SHA_Type *  base,
sha_ctx_t ctx,
const uint8_t *  input,
size_t  inputSize 
)

Configures the SHA to compute new running hash as AHB master and returns immediately. SHA AHB Master mode supports only aligned input address and can be called only once per continuous block of data. Every call to this function must be preceded with SHA_Init() and finished with _SHA_Finish(). Once callback function is invoked by SHA isr, it should set a flag for the main application to finalize the hashing (padding) and to read out the final digest by calling SHA_Finish().

Parameters
baseSHA peripheral base address
ctxSpecifies callback. Last incomplete 512-bit block of the input is copied into clear buffer for padding.
input32-bit word aligned pointer to Input data.
inputSizeSize of input data in bytes (must be word aligned)
Returns
Status of the hash update operation.
void SHA_ClkInit ( SHA_Type *  base)

Start SHA clock

Parameters
baseSHA peripheral base address
void SHA_ClkDeinit ( SHA_Type *  base)

Stop SHA clock

Parameters
baseSHA peripheral base address