Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
Data Structures | Macros | Functions | Variables
internal-sha256.h File Reference

SHA256 implementation for performance comparisons. More...

#include "aead-metadata.h"
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  sha256_state_t
 State for SHA256 incremental mode. More...
 

Macros

#define SHA256_HASH_SIZE   32
 Size of the hash for SHA256.
 

Functions

int internal_sha256_hash (unsigned char *out, const unsigned char *in, size_t inlen)
 Hashes a block of input data with SHA256 to generate a hash value. More...
 
void internal_sha256_hash_init (sha256_state_t *state)
 Initializes the state for a SHA256 hashing operation. More...
 
void internal_sha256_hash_update (sha256_state_t *state, const unsigned char *in, size_t inlen)
 Updates a SHA256 state with more input data. More...
 
void internal_sha256_hash_finalize (sha256_state_t *state, unsigned char *out)
 Returns the final hash value from a SHA256 hashing operation. More...
 
void internal_sha256_hmac (unsigned char *out, const unsigned char *key, size_t keylen, const unsigned char *in, size_t inlen)
 Computes a HMAC value using SHA256. More...
 
void internal_sha256_hmac_init (sha256_state_t *state, const unsigned char *key, size_t keylen)
 Initializes an incremental HMAC state using SHA256. More...
 
void internal_sha256_hmac_update (sha256_state_t *state, const unsigned char *in, size_t inlen)
 Updates an incremental SHA256-HMAC state with more input data. More...
 
void internal_sha256_hmac_finalize (sha256_state_t *state, const unsigned char *key, size_t keylen, unsigned char *out)
 Finalizes an incremental SHA256-HMAC state. More...
 

Variables

aead_hash_algorithm_t const internal_sha256_hash_algorithm
 Meta-information block for the SHA256 hash algorithm.
 

Detailed Description

SHA256 implementation for performance comparisons.

SHA256 is not one of the NIST lightweight submissions. We use it as a comparison to evaluate the performance of other hash algorithsm.

This SHA256 implementation is based on the one from the Arduino Cryptography Library.

Function Documentation

int internal_sha256_hash ( unsigned char *  out,
const unsigned char *  in,
size_t  inlen 
)

Hashes a block of input data with SHA256 to generate a hash value.

Parameters
outBuffer to receive the hash output which must be at least SHA256_HASH_SIZE bytes in length.
inPoints to the input data to be hashed.
inlenLength of the input data in bytes.
Returns
Returns zero on success or -1 if there was an error in the parameters.
void internal_sha256_hash_finalize ( sha256_state_t state,
unsigned char *  out 
)

Returns the final hash value from a SHA256 hashing operation.

Parameters
stateHash state to be finalized.
outPoints to the output buffer to receive the 32-byte hash value.
void internal_sha256_hash_init ( sha256_state_t state)

Initializes the state for a SHA256 hashing operation.

Parameters
stateHash state to be initialized.
void internal_sha256_hash_update ( sha256_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Updates a SHA256 state with more input data.

Parameters
stateHash state to be updated.
inPoints to the input data to be incorporated into the state.
inlenLength of the input data to be incorporated into the state.
void internal_sha256_hmac ( unsigned char *  out,
const unsigned char *  key,
size_t  keylen,
const unsigned char *  in,
size_t  inlen 
)

Computes a HMAC value using SHA256.

Parameters
outBuffer to receive the output HMAC value; must be at least SHA256_HASH_SIZE bytes in length.
keyPoints to the key.
keylenNumber of bytes in the key.
inPoints to the data to authenticate.
inlenNumber of bytes of data to authenticate.
void internal_sha256_hmac_finalize ( sha256_state_t state,
const unsigned char *  key,
size_t  keylen,
unsigned char *  out 
)

Finalizes an incremental SHA256-HMAC state.

Parameters
stateHMAC state to squeeze the output data from.
keyPoints to the key.
keylenNumber of bytes in the key.
outPoints to the output buffer to receive the HMAC value; must be at least SHA256_HASH_SIZE bytes in length.
void internal_sha256_hmac_init ( sha256_state_t state,
const unsigned char *  key,
size_t  keylen 
)

Initializes an incremental HMAC state using SHA256.

Parameters
statePoints to the state to be initialized.
keyPoints to the key.
keylenNumber of bytes in the key.
void internal_sha256_hmac_update ( sha256_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Updates an incremental SHA256-HMAC state with more input data.

Parameters
stateHMAC state to be updated.
inPoints to the input data to be incorporated into the state.
inlenLength of the input data to be incorporated into the state.