Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1/*-
2 * SPDX-FileCopyrightText: 2005 Colin Percival
3 * SPDX-FileCopyrightText: 2013 Christian Mehlis & René Kijewski
4 * SPDX-FileCopyrightText: 2016 Martin Landsmann <martin.landsmann@haw-hamburg.de>
5 * SPDX-FileCopyrightText: 2016 OTA keys S.A.
6 * SPDX-License-Identifier: BSD-2-Clause
7 */
8
9#pragma once
10
25
26#include <inttypes.h>
27#include <stddef.h>
28
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
38#define SHA256_DIGEST_LENGTH 32
39
43#define SHA256_INTERNAL_BLOCK_SIZE (64)
44
49
59
63typedef struct {
65 size_t index;
69
76
84static inline void sha256_update(sha256_context_t *ctx, const void *data, size_t len)
85{
86 sha2xx_update(ctx, data, len);
87}
88
96static inline void sha256_final(sha256_context_t *ctx, void *digest)
97{
99}
100
110void sha256(const void *data, size_t len, void *digest);
111
118void hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length);
119
126void hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len);
127
136void hmac_sha256_final(hmac_context_t *ctx, void *digest);
137
148void hmac_sha256(const void *key, size_t key_length,
149 const void *data, size_t len, void *digest);
150
165void *sha256_chain(const void *seed, size_t seed_length,
166 size_t elements, void *tail_element);
167
196void *sha256_chain_with_waypoints(const void *seed, size_t seed_length,
197 size_t elements, void *tail_element,
198 sha256_chain_idx_elm_t *waypoints,
199 size_t *waypoints_length);
200
213 size_t element_index,
214 void *tail_element,
215 size_t chain_length);
216
217#ifdef __cplusplus
218}
219#endif
220
int sha256_chain_verify_element(void *element, size_t element_index, void *tail_element, size_t chain_length)
function to verify if a given chain element is part of the chain.
void hmac_sha256(const void *key, size_t key_length, const void *data, size_t len, void *digest)
function to compute a hmac-sha256 from a given message
static void sha256_update(sha256_context_t *ctx, const void *data, size_t len)
Add bytes into the hash.
Definition sha256.h:84
void * sha256_chain_with_waypoints(const void *seed, size_t seed_length, size_t elements, void *tail_element, sha256_chain_idx_elm_t *waypoints, size_t *waypoints_length)
function to produce a hash chain starting with a given seed element.
static void sha256_final(sha256_context_t *ctx, void *digest)
SHA-256 finalization.
Definition sha256.h:96
void hmac_sha256_final(hmac_context_t *ctx, void *digest)
hmac_sha256_final HMAC SHA-256 finalization.
void hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len)
hmac_sha256_update Add data bytes for HMAC calculation
void hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length)
hmac_sha256_init HMAC SHA-256 calculation.
void sha256_init(sha256_context_t *ctx)
SHA-256 initialization.
#define SHA256_DIGEST_LENGTH
Length of SHA256 digests in bytes.
Definition sha256.h:38
void * sha256_chain(const void *seed, size_t seed_length, size_t elements, void *tail_element)
function to produce a hash chain starting with a given seed element.
void sha256(const void *data, size_t len, void *digest)
A wrapper function to simplify the generation of a hash, this is useful for generating sha256 for one...
sha2xx_context_t sha256_context_t
Context for cipher operations based on sha256.
Definition sha256.h:48
void sha2xx_final(sha2xx_context_t *ctx, void *digest, size_t dig_len)
SHA-2XX finalization.
void sha2xx_update(sha2xx_context_t *ctx, const void *data, size_t len)
Add bytes into the hash.
Adds include for missing inttype definitions.
Common definitions for the SHA-224/256 hash functions.
Context for HMAC operations based on sha256.
Definition sha256.h:53
sha256_context_t c_out
Context for outer hash calculation.
Definition sha256.h:57
sha256_context_t c_in
Context for inner hash calculation.
Definition sha256.h:55
sha256-chain indexed element
Definition sha256.h:63
unsigned char element[SHA256_DIGEST_LENGTH]
the element
Definition sha256.h:67
size_t index
the position of this element in its chain
Definition sha256.h:65
Structure to hold the SHA-2XX context.