Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-sha256.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef LW_INTERNAL_SHA256_H
24 #define LW_INTERNAL_SHA256_H
25 
26 #include "aead-metadata.h"
27 #include <stdint.h>
28 #include <stddef.h>
29 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
49 #define SHA256_HASH_SIZE 32
50 
54 typedef struct
55 {
56  uint32_t h[8];
57  uint32_t w[16];
58  uint64_t length;
59  unsigned posn;
62 
67 
80  (unsigned char *out, const unsigned char *in, size_t inlen);
81 
88 
97  (sha256_state_t *state, const unsigned char *in, size_t inlen);
98 
105 void internal_sha256_hash_finalize(sha256_state_t *state, unsigned char *out);
106 
118  (unsigned char *out,
119  const unsigned char *key, size_t keylen,
120  const unsigned char *in, size_t inlen);
121 
130  (sha256_state_t *state, const unsigned char *key, size_t keylen);
131 
140  (sha256_state_t *state, const unsigned char *in, size_t inlen);
141 
152  (sha256_state_t *state, const unsigned char *key, size_t keylen,
153  unsigned char *out);
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif
unsigned posn
Definition: internal-sha256.h:59
Meta-information about a hash algorithm that is related to an AEAD.
Definition: aead-metadata.h:225
void internal_sha256_hmac_init(sha256_state_t *state, const unsigned char *key, size_t keylen)
Initializes an incremental HMAC state using SHA256.
void internal_sha256_hash_finalize(sha256_state_t *state, unsigned char *out)
Returns the final hash value from a SHA256 hashing operation.
Definition: internal-sha256.c:238
State for SHA256 incremental mode.
Definition: internal-sha256.h:54
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.
void internal_sha256_hash_update(sha256_state_t *state, const unsigned char *in, size_t inlen)
Updates a SHA256 state with more input data.
Definition: internal-sha256.c:217
aead_hash_algorithm_t const internal_sha256_hash_algorithm
Meta-information block for the SHA256 hash algorithm.
Definition: internal-sha256.c:27
Metadata defintions for AEAD and hashing schemes.
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.
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.
uint64_t length
Definition: internal-sha256.h:58
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.
Definition: internal-sha256.c:148
void internal_sha256_hash_init(sha256_state_t *state)
Initializes the state for a SHA256 hashing operation.
Definition: internal-sha256.c:202