SHA256#

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.

Modules#

btl_sha256_context

Enumerations#

enum
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 Documentation#

SHA_Type_t#

SHA_Type_t

Type variable for SHA-256 Cryptography.

Enumerator
SHA256

SHA-256 type.


Definition at line 44 of file platform/bootloader/security/sha/btl_sha256.h

Function Documentation#

btl_sha256_init#

void btl_sha256_init (btl_sha256_context * ctx)

Initialize SHA-256 context.

Parameters
N/Actx

SHA-256 context to be initialized


Definition at line 55 of file platform/bootloader/security/sha/btl_sha256.h

btl_sha256_starts_ret#

int btl_sha256_starts_ret (btl_sha256_context * ctx, int is224)

Set up SHA-256 context.

Parameters
N/Actx

context to be initialized

N/Ais224

0 = use SHA256, 1 = use SHA224

Returns

  • 0 if successful


Definition at line 66 of file platform/bootloader/security/sha/btl_sha256.h

btl_sha256_update_ret#

int btl_sha256_update_ret (btl_sha256_context * ctx, const unsigned char * input, size_t ilen)

SHA-256 process buffer.

Parameters
N/Actx

SHA-256 context

N/Ainput

buffer holding the data

N/Ailen

length of the input data

Returns

  • 0 if successful


Definition at line 78 of file platform/bootloader/security/sha/btl_sha256.h

btl_sha256_finish_ret#

int btl_sha256_finish_ret (btl_sha256_context * ctx, unsigned char output)

SHA-256 final digest.

Parameters
N/Actx

SHA-256 context

N/Aoutput

SHA-224/256 checksum result

Returns

  • 0 if successful


Definition at line 89 of file platform/bootloader/security/sha/btl_sha256.h

sha_x_process#

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.

Parameters
N/Aalgo

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

N/Anum_blocks

Number of SHA blocks in data block

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.

Returns

  • Zero on success. Negative error code on failure.


Definition at line 105 of file platform/bootloader/security/sha/btl_sha256.h

sha_x_update#

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.

Parameters
N/Aalgo

Which hashing algorithm to use

[inout]data

Pointer to the hashing algorithm's state buffer

[in]data_len

Pointer to the data to add to the hash

[inout]state

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.

[inout]buffer

Counter variable keeping track of the amount of bytes hashed, to later be used for hash finalization. For first use, initialize with zeroes.

[in]counter

Length to data to add to hash

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.

Returns

  • Zero on success. Negative error code on failure.


Definition at line 132 of file platform/bootloader/security/sha/btl_sha256.h

sha_x_finish#

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.

Parameters
N/Aalgo

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.

[inout]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.

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.

Returns

  • Zero on success. Negative error code on failure.


Definition at line 159 of file platform/bootloader/security/sha/btl_sha256.h