Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1/*-
2 * Copyright 2005 Colin Percival
3 * Copyright 2013 Christian Mehlis & René Kijewski
4 * Copyright 2016 Martin Landsmann <martin.landsmann@haw-hamburg.de>
5 * Copyright 2016 OTA keys S.A.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: src/lib/libmd/sha256.h,v 1.1.2.1 2005/06/24 13:32:25 cperciva Exp $
30 */
31
47#ifndef HASHES_SHA256_H
48#define HASHES_SHA256_H
49
50#include <inttypes.h>
51#include <stddef.h>
52
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
62#define SHA256_DIGEST_LENGTH 32
63
67#define SHA256_INTERNAL_BLOCK_SIZE (64)
68
73
83
87typedef struct {
89 size_t index;
91 unsigned char element[SHA256_DIGEST_LENGTH];
93
100
108static inline void sha256_update(sha256_context_t *ctx, const void *data, size_t len)
109{
110 sha2xx_update(ctx, data, len);
111}
112
120static inline void sha256_final(sha256_context_t *ctx, void *digest)
121{
123}
124
134void sha256(const void *data, size_t len, void *digest);
135
142void hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length);
143
150void hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len);
151
157void hmac_sha256_final(hmac_context_t *ctx, void *digest);
158
169void hmac_sha256(const void *key, size_t key_length,
170 const void *data, size_t len, void *digest);
171
186void *sha256_chain(const void *seed, size_t seed_length,
187 size_t elements, void *tail_element);
188
217void *sha256_chain_with_waypoints(const void *seed, size_t seed_length,
218 size_t elements, void *tail_element,
219 sha256_chain_idx_elm_t *waypoints,
220 size_t *waypoints_length);
221
234 size_t element_index,
235 void *tail_element,
236 size_t chain_length);
237
238#ifdef __cplusplus
239}
240#endif
241
243#endif /* HASHES_SHA256_H */
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:108
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:120
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:62
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:72
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:77
sha256_context_t c_out
Context for outer hash calculation.
Definition sha256.h:81
sha256_context_t c_in
Context for inner hash calculation.
Definition sha256.h:79
sha256-chain indexed element
Definition sha256.h:87
size_t index
the position of this element in its chain
Definition sha256.h:89
Structure to hold the SHA-2XX context.