SHA256Components > Security

Description

SHA-256 Cryptography Library.

This file includes an alternative implementation of the standard mbed TLS SHA using hardware accelerator incorporated in MCU devices from Silicon Labs.

Data Structures

struct  btl_sha256_context
 Context Variable type for SHA-256 Cryptography.
 

Enumerations

enum  SHA_Type_t { SHA256 }
 Type variable for SHA-256 Cryptography.
 

Functions

void btl_sha256_init (btl_sha256_context *ctx)
 Initialize SHA-256 context.
 
int btl_sha256_starts_ret (btl_sha256_context *ctx, int is224)
 Set up SHA-256 context.
 
int btl_sha256_update_ret (btl_sha256_context *ctx, const unsigned char *input, size_t ilen)
 SHA-256 process buffer.
 
int btl_sha256_finish_ret (btl_sha256_context *ctx, unsigned char output[32])
 SHA-256 final digest.
 
int sha_x_process (SHA_Type_t algo, uint8_t *state_in, const unsigned char *blockdata, uint8_t *state_out, uint32_t num_blocks)
 Process (a) block(s) of data to be hashed.
 
int sha_x_update (SHA_Type_t algo, const unsigned char *data, size_t data_len, uint8_t *state, unsigned char *buffer, uint32_t *counter)
 Process an arbitrary number of bytes to be hashed.
 
int sha_x_finish (SHA_Type_t algo, uint8_t *state, uint8_t *buffer, uint32_t *counter, uint8_t *output)
 Process an arbitrary number of bytes to be hashed.
 

Enumeration Type Documentation

enum SHA_Type_t

Type variable for SHA-256 Cryptography.

Enumerator
SHA256 

SHA-256 type

Definition at line 44 of file btl_sha256.h.

Function Documentation

void btl_sha256_init ( btl_sha256_context ctx)

Initialize SHA-256 context.

Parameters
ctxSHA-256 context to be initialized
int btl_sha256_starts_ret ( btl_sha256_context ctx,
int  is224 
)

Set up SHA-256 context.

Parameters
ctxcontext to be initialized
is2240 = use SHA256, 1 = use SHA224
Returns
0 if successful
int btl_sha256_update_ret ( btl_sha256_context ctx,
const unsigned char *  input,
size_t  ilen 
)

SHA-256 process buffer.

Parameters
ctxSHA-256 context
inputbuffer holding the data
ilenlength of the input data
Returns
0 if successful
int btl_sha256_finish_ret ( btl_sha256_context ctx,
unsigned char  output[32] 
)

SHA-256 final digest.

Parameters
ctxSHA-256 context
outputSHA-224/256 checksum result
Returns
0 if successful
int sha_x_process ( SHA_Type_t  algo,
uint8_t *  state_in,
const unsigned char *  blockdata,
uint8_t *  state_out,
uint32_t  num_blocks 
)

Process (a) block(s) of data to be hashed.

Note
Watch the blocksize! Blocks are 64 bytes for SHA-1 through SHA-256, and 128 bytes for SHA-384 through SHA-512.
Watch the state size! State size is half the block size.
Parameters
algoWhich hashing algorithm to use
[in]state_inPrevious state of the hashing algorithm
[in]blockdataPointer to the block(s) of data
[out]state_outPointer to block of memory to store state
num_blocksNumber of SHA blocks in data block
Returns
Zero on success. Negative error code on failure.
int sha_x_update ( SHA_Type_t  algo,
const unsigned char *  data,
size_t  data_len,
uint8_t *  state,
unsigned char *  buffer,
uint32_t *  counter 
)

Process an arbitrary number of bytes to be hashed.

Note
Watch the blocksize! Blocks are 64 bytes for SHA-1 through SHA-256, and 128 bytes for SHA-384 through SHA-512.
Watch the state size! State size is half the block size.
Watch the counter size! Counter is 64 bytes for SHA-1 through SHA-256, and 128 bytes for SHA-384 through SHA-512.
Parameters
algoWhich hashing algorithm to use
[in,out]statePointer to the hashing algorithm's state buffer
[in]dataPointer to the data to add to the hash
[in,out]bufferPointer to a block buffer to retrieve/store a partial block in between calls to this function. Needs to have a size equal to the block size.
[in,out]counterCounter variable keeping track of the amount of bytes hashed, to later be used for hash finalization. For first use, initialize with zeroes.
[in]data_lenLength to data to add to hash
Returns
Zero on success. Negative error code on failure.
int sha_x_finish ( SHA_Type_t  algo,
uint8_t *  state,
uint8_t *  buffer,
uint32_t *  counter,
uint8_t *  output 
)

Process an arbitrary number of bytes to be hashed.

Note
Watch the blocksize! Blocks are 64 bytes for SHA-1 through SHA-256, and 128 bytes for SHA-384 through SHA-512.
Watch the state size! State size is half the block size.
Watch the counter size! Counter is 64 bytes for SHA-1 through SHA-256, and 128 bytes for SHA-384 through SHA-512.
Parameters
algoWhich hashing algorithm to use
[in]statePointer to the hashing algorithm's state buffer
[in]bufferPointer to a block buffer to retrieve/store a partial block in between calls to this function. Needs to have a size equal to the block size.
[in,out]counterCounter variable keeping track of the amount of bytes hashed, to later be used for hash finalization. For first use, initialize with zeroes.
[out]outputPointer to the destination of the hash.
Returns
Zero on success. Negative error code on failure.