Microchip® Advanced Software Framework

sha2_routines.c File Reference

Software implementation of the SHA256 algorithm.

#include <string.h>
#include "sha2_routines.h"

Macros

#define rotate_right(value, places)   ((value >> places) | (value << (32 - places)))
 

Functions

void sw_sha256 (const uint8_t *message, unsigned int len, uint8_t digest[SHA256_DIGEST_SIZE])
 single call convenience function which computes Hash of given data using SHA256 software More...
 
void sw_sha256_final (sw_sha256_ctx *ctx, uint8_t digest[SHA256_DIGEST_SIZE])
 completes the final SHA256 calculation and returns the final digest/hash More...
 
void sw_sha256_init (sw_sha256_ctx *ctx)
 Intialize the software SHA256. More...
 
static void sw_sha256_process (sw_sha256_ctx *ctx, const uint8_t *blocks, uint32_t block_count)
 Processes whole blocks (64 bytes) of data. More...
 
void sw_sha256_update (sw_sha256_ctx *ctx, const uint8_t *msg, uint32_t msg_size)
 updates the running hash with the next block of data, called iteratively for the entire stream of data to be hashed using the SHA256 software More...
 

#define rotate_right (   value,
  places 
)    ((value >> places) | (value << (32 - places)))

Referenced by sw_sha256_process().

void sw_sha256 ( const uint8_t *  message,
unsigned int  len,
uint8_t  digest[SHA256_DIGEST_SIZE] 
)

single call convenience function which computes Hash of given data using SHA256 software

Parameters
[in]messagepointer to stream of data to hash
[in]lensize of data stream to hash
[out]digestresult

References sw_sha256_final(), sw_sha256_init(), and sw_sha256_update().

void sw_sha256_final ( sw_sha256_ctx ctx,
uint8_t  digest[SHA256_DIGEST_SIZE] 
)

completes the final SHA256 calculation and returns the final digest/hash

Parameters
[in]ctxptr to context data structure
[out]digestreceives the computed digest of the SHA 256

References sw_sha256_ctx::block, sw_sha256_ctx::block_size, sw_sha256_ctx::hash, i, j, SHA256_BLOCK_SIZE, sw_sha256_process(), and sw_sha256_ctx::total_msg_size.

Referenced by atcac_sw_sha2_256_finish(), and sw_sha256().

void sw_sha256_init ( sw_sha256_ctx ctx)

Intialize the software SHA256.

Parameters
[in]ctxSHA256 hash context

References sw_sha256_ctx::hash, and i.

Referenced by atcac_sw_sha2_256_init(), and sw_sha256().

static void sw_sha256_process ( sw_sha256_ctx ctx,
const uint8_t *  blocks,
uint32_t  block_count 
)
static

Processes whole blocks (64 bytes) of data.

Parameters
[in]ctxSHA256 hash context
[in]blocksRaw blocks to be processed
[in]block_countNumber of 64-byte blocks to process

References sw_sha256_ctx::hash, i, rotate_right, and SHA256_BLOCK_SIZE.

Referenced by sw_sha256_final(), and sw_sha256_update().

void sw_sha256_update ( sw_sha256_ctx ctx,
const uint8_t *  msg,
uint32_t  msg_size 
)

updates the running hash with the next block of data, called iteratively for the entire stream of data to be hashed using the SHA256 software

Parameters
[in]ctxSHA256 hash context
[in]msgRaw blocks to be processed
[in]msg_sizeThe size of the message passed

References sw_sha256_ctx::block, sw_sha256_ctx::block_size, SHA256_BLOCK_SIZE, sw_sha256_process(), and sw_sha256_ctx::total_msg_size.

Referenced by atcac_sw_sha2_256_update(), and sw_sha256().