SHA-256¶
Implementation of the SHA-256 hashing function.
-
void
sha256_init
(sha256_context_t * ctx)¶ SHA-256 initialization.
Begins a SHA-256 operation.
Parameters
ctx: sha256_context_t handle to init
-
void
sha256_update
(sha256_context_t * ctx, const void * data,msp430_types.h::size_t
len)¶ Add bytes into the hash.
Parameters
ctx: sha256_context_t handle to use data: Input data len: Length of data
-
void
sha256_final
(sha256_context_t * ctx, void * digest)¶ SHA-256 finalization.
Pads the input data, exports the hash value, and clears the context state.
Parameters
ctx: sha256_context_t handle to use digest: resulting digest, this is the hash of all the bytes
-
void *
sha256
(const void * data,msp430_types.h::size_t
len, void * digest)¶ A wrapper function to simplify the generation of a hash, this is usefull for generating sha256 for one buffer.
Parameters
data: pointer to the buffer to generate hash from len: length of the buffer digest: optional pointer to an array for the result, length must be SHA256_DIGEST_LENGTH if digest == NULL, one static buffer is used
-
void
hmac_sha256_init
(hmac_context_t * ctx, const void * key,msp430_types.h::size_t
key_length)¶ hmac_sha256_init HMAC SHA-256 calculation.
Initiate calculation of a HMAC
Parameters
ctx: hmac_context_t handle to use key: key used in the hmac-sha256 computation key_length: the size in bytes of the key
-
void
hmac_sha256_update
(hmac_context_t * ctx, const void * data,msp430_types.h::size_t
len)¶ hmac_sha256_update Add data bytes for HMAC calculation
Parameters
ctx: hmac_context_t handle to use data: pointer to the buffer to generate hash from len: length of the buffer
-
void
hmac_sha256_final
(hmac_context_t * ctx, void * digest)¶ hmac_sha256_final HMAC SHA-256 finalization.
Finish HMAC calculation and export the value
Parameters
ctx: hmac_context_t handle to use digest: the computed hmac-sha256, length MUST be SHA256_DIGEST_LENGTH if digest == NULL, a static buffer is used
-
const void *
hmac_sha256
(const void * key,msp430_types.h::size_t
key_length, const void * data,msp430_types.h::size_t
len, void * digest)¶ function to compute a hmac-sha256 from a given message
Parameters
key: key used in the hmac-sha256 computation key_length: the size in bytes of the key data: pointer to the buffer to generate the hmac-sha256 len: the length of the message in bytes digest: the computed hmac-sha256, length MUST be SHA256_DIGEST_LENGTH if digest == NULL, a static buffer is used Return values
- pointer to the resulting digest. if result == NULL the pointer points to the static buffer
-
void *
sha256_chain
(const void * seed,msp430_types.h::size_t
seed_length,msp430_types.h::size_t
elements, void * tail_element)¶ function to produce a hash chain statring with a given seed element.
The chain is computed by taking the sha256 from the seed, hash the resulting sha256 and continuing taking sha256 from each result consecutively.
Parameters
seed: the seed of the sha256-chain, i.e. the first element seed_length: the size of seed in bytes elements: the number of chained elements, i.e. the index of the last element is (elements-1) tail_element: the final element of the sha256-chain Return values
- pointer to tail_element
-
void *
sha256_chain_with_waypoints
(const void * seed,msp430_types.h::size_t
seed_length,msp430_types.h::size_t
elements, void * tail_element, sha256_chain_idx_elm_t * waypoints,msp430_types.h::size_t
* waypoints_length)¶ function to produce a hash chain statring with a given seed element.
The chain is computed the same way as done with
sha256.h::sha256_chain()
. Additionally intermediate elements are saved while computing the chain. This slows down computation, but provides the caller with indexed “waypoint”-elements. They are supposed to shortcut computing verification elements, this comes in handy when using long chains, e.g. a chain with 2 elements.Parameters
seed: the seed of the sha256-chain, i.e. the first element seed_length: the size of seed in bytes elements: the number of chained elements, i.e. the index of the last element is (elements-1) tail_element: the final element of the sha256-chain waypoints: intermediate elements are stored there. waypoints_length: the size of the waypoints array. If the given size is equal or greater elements, the complete chain will be stored. Otherwise every n-th element is stored where: n = floor(elements / waypoints_length); floor is implicitly used since we perform unsigned integer division. The last used waypoint index is stored in the variable after call. That is (elements - 1) if the complete chain is stored, and (*waypoints_length - 1) if we only store some waypoints. Return values
- pointer to tail_element
-
int
sha256_chain_verify_element
(void * element,msp430_types.h::size_t
element_index, void * tail_element,msp430_types.h::size_t
chain_length)¶ function to verify if a given chain element is part of the chain.
Parameters
element: the chain element to be verified element_index: the position in the chain tail_element: the last element of the sha256-chain chain_length: the number of elements in the chain Return values
- 0 if element is verified to be part of the chain at element_index 1 if the element cannot be verified as part of the chain
-
SHA256_DIGEST_LENGTH
¶ Length of SHA256 digests in bytes.
1
32
-
SHA256_INTERNAL_BLOCK_SIZE
¶ 512 Bit (64 Byte) internally used block size for sha256
1
(64)
-
struct
sha256_context_t
¶ Context for cipher operations based on sha256.
-
uint32_t
state
()¶ global state
-
uint32_t
count
()¶ processed bytes counter
-
unsigned char
buf
()¶ data buffer
-
uint32_t
-
struct
hmac_context_t
¶ Context for HMAC operations based on sha256.
-
sha256_context_t
c_in
¶ Context for inner hash calculation.
-
sha256_context_t
c_out
¶ Context for outer hash calculation.
-
sha256_context_t