Functions | |
uint32_t | rotr32fixed (uint32_t x, unsigned int y) |
void | sha256_init (shw_hash_state_t *state) |
static void | sha256_process_block (shw_hash_state_t *state) |
fsl_shw_return_t | shw_hash_init (shw_hash_state_t *state, fsl_shw_hash_alg_t alg) |
fsl_shw_return_t | shw_hash_update (shw_hash_state_t *state, const uint8_t *input, unsigned int input_len) |
fsl_shw_return_t | shw_hash_final (shw_hash_state_t *state, uint8_t *result, unsigned int result_len) |
This file contains implementations for use of the (internal) SHW hash software computation. It defines the usual three steps:
In support of the above functions, it also contains these functions:
These functions depend upon the Linux Endian functions __be32_to_cpu(), __cpu_to_be32() to convert a 4-byte big-endian array to an integer and vice-versa. For those without Linux, it should be pretty obvious what they do.
The shw_hash_update() and shw_hash_final() functions are generic enough to support SHA-1/SHA-224/SHA-256, as needed. Some extra tweaking would be necessary to get them to support SHA-384/SHA-512.
uint32_t rotr32fixed | ( | uint32_t | x, | |
unsigned int | y | |||
) | [inline] |
Rotate a value right by a number of bits.
x | Word of data which needs rotating | |
y | Number of bits to rotate |
void sha256_init | ( | shw_hash_state_t * | state | ) |
Initialize the Hash State
Constructs the SHA256 hash engine. Specification: State Size = 32 bytes Block Size = 64 bytes Digest Size = 32 bytes
state | Address of hash state structure |
References shw_hash_state::bit_count, shw_hash_state::partial_count_bytes, and shw_hash_state::state.
Referenced by shw_hash_init().
static void sha256_process_block | ( | shw_hash_state_t * | state | ) | [static] |
Hash a block of data into the SHA-256 hash state.
This function hash the block of data in the partial_block
element of the state structure into the state variables of the state structure.
state | Address of hash state structure |
References shw_hash_state::partial_block, and shw_hash_state::state.
Referenced by shw_hash_update().
fsl_shw_return_t shw_hash_final | ( | shw_hash_state_t * | state, | |
uint8_t * | result, | |||
unsigned int | result_len | |||
) |
Finalize the hash
Performs the finalize operation on the previous input data & returns the resulting digest. The finalize operation performs the appropriate padding up to the block size.
state | Address of hash state structure | |
result | Location to store the hash result | |
result_len | Number of bytes of result to be stored. |
References shw_hash_state::bit_count, FSL_RETURN_BAD_DATA_LENGTH_S, FSL_RETURN_OK_S, shw_hash_state::partial_count_bytes, SHW_HASH_LEN, shw_hash_update(), and shw_hash_state::state.
Referenced by shw_hmac_final().
fsl_shw_return_t shw_hash_init | ( | shw_hash_state_t * | state, | |
fsl_shw_hash_alg_t | alg | |||
) |
Initialize the hash state structure
state | Address of hash state structure. | |
alg | Which hash algorithm to use (must be FSL_HASH_ALG_SHA1) |
References FSL_HASH_ALG_SHA256, FSL_RETURN_BAD_ALGORITHM_S, FSL_RETURN_OK_S, and sha256_init().
Referenced by shw_hmac_init().
fsl_shw_return_t shw_hash_update | ( | shw_hash_state_t * | state, | |
const uint8_t * | input, | |||
unsigned int | input_len | |||
) |
Add input bytes to the hash
The bytes are added to the partial_block element of the hash state, and as the partial block is filled, it is processed by sha1_process_block(). This function also updates the bit_count element of the hash state.
state | Address of hash state structure | |
input | Address of bytes to add to the hash | |
input_len | Numbef of bytes at input |
References shw_hash_state::bit_count, FSL_RETURN_OK_S, shw_hash_state::partial_block, shw_hash_state::partial_count_bytes, and sha256_process_block().
Referenced by shw_hash_final(), shw_hmac_final(), shw_hmac_init(), and shw_hmac_update().
© Freescale Semiconductor, Inc., 2007.
All rights reserved. Freescale Confidential Proprietary NDA Required |
![]() |