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 
32 
46 #ifndef HASHES_SHA256_H
47 #define HASHES_SHA256_H
48 
49 #include <inttypes.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #define SHA256_DIGEST_LENGTH 32
56 
60 #define SHA256_INTERNAL_BLOCK_SIZE (64)
61 
65 typedef struct {
67  uint32_t state[8];
69  uint32_t count[2];
71  unsigned char buf[64];
73 
77 typedef struct {
83 
87 typedef struct {
89  size_t index;
91  unsigned char element[SHA256_DIGEST_LENGTH];
93 
99 void sha256_init(sha256_context_t *ctx);
100 
108 void sha256_update(sha256_context_t *ctx, const void *data, size_t len);
109 
117 void sha256_final(sha256_context_t *ctx, void *digest);
118 
129 void *sha256(const void *data, size_t len, void *digest);
130 
137 void hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length);
138 
145 void hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len);
146 
154 void hmac_sha256_final(hmac_context_t *ctx, void *digest);
155 
169 const void *hmac_sha256(const void *key, size_t key_length,
170  const void *data, size_t len, void *digest);
171 
186 void *sha256_chain(const void *seed, size_t seed_length,
187  size_t elements, void *tail_element);
188 
217 void *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 
233 int sha256_chain_verify_element(void *element,
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 */
size_t index
the position of this element in its chain
Definition: sha256.h:89
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 statring with a given seed element.
void sha256_init(sha256_context_t *ctx)
SHA-256 initialization.
void * sha256(const void *data, size_t len, void *digest)
A wrapper function to simplify the generation of a hash, this is usefull for generating sha256 for on...
void * sha256_chain(const void *seed, size_t seed_length, size_t elements, void *tail_element)
function to produce a hash chain statring with a given seed element.
const 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
sha256-chain indexed element
Definition: sha256.h:87
Context for HMAC operations based on sha256.
Definition: sha256.h:77
sha256_context_t c_in
Context for inner hash calculation.
Definition: sha256.h:79
Adds include for missing inttype definitions.
void hmac_sha256_final(hmac_context_t *ctx, void *digest)
hmac_sha256_final HMAC SHA-256 finalization.
void sha256_update(sha256_context_t *ctx, const void *data, size_t len)
Add bytes into the hash.
void hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len)
hmac_sha256_update Add data bytes for HMAC calculation
Context for ciper operations based on sha256.
Definition: sha256.h:65
sha256_context_t c_out
Context for outer hash calculation.
Definition: sha256.h:81
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_init(hmac_context_t *ctx, const void *key, size_t key_length)
hmac_sha256_init HMAC SHA-256 calculation.
void sha256_final(sha256_context_t *ctx, void *digest)
SHA-256 finalization.