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

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
ctx SHA-256 context to be initialized
int btl_sha256_starts_ret ( btl_sha256_context * ctx,
int is224
)

Set up SHA-256 context.

Parameters
ctx context to be initialized
is224 0 = 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
ctx SHA-256 context
input buffer holding the data
ilen length 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
ctx SHA-256 context
output SHA-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
algo Which hashing algorithm to use
[in] state_in Previous state of the hashing algorithm
[in] blockdata Pointer to the block(s) of data
[out] state_out Pointer to block of memory to store state
num_blocks Number 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
algo Which hashing algorithm to use
[in,out] state Pointer to the hashing algorithm's state buffer
[in] data Pointer to the data to add to the hash
[in,out] buffer Pointer 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] counter Counter variable keeping track of the amount of bytes hashed, to later be used for hash finalization. For first use, initialize with zeroes.
[in] data_len Length 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
algo Which hashing algorithm to use
[in] state Pointer to the hashing algorithm's state buffer
[in] buffer Pointer 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] counter Counter variable keeping track of the amount of bytes hashed, to later be used for hash finalization. For first use, initialize with zeroes.
[out] output Pointer to the destination of the hash.
Returns
Zero on success. Negative error code on failure.