NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1/* sha256.h - TinyCrypt interface to a SHA-256 implementation */
2
3/*
4 * Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Intel Corporation nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
57#ifndef __TC_SHA256_H__
58#define __TC_SHA256_H__
59
60#include <stddef.h>
61#include <stdint.h>
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67#define TC_SHA256_BLOCK_SIZE (64)
68#define TC_SHA256_DIGEST_SIZE (32)
69#define TC_SHA256_STATE_BLOCKS (TC_SHA256_DIGEST_SIZE/4)
70
71struct tc_sha256_state_struct {
72 unsigned int iv[TC_SHA256_STATE_BLOCKS];
73 uint64_t bits_hashed;
74 uint8_t leftover[TC_SHA256_BLOCK_SIZE];
75 size_t leftover_offset;
76};
77
78typedef struct tc_sha256_state_struct *TCSha256State_t;
79
87int tc_sha256_init(TCSha256State_t s);
88
105int tc_sha256_update (TCSha256State_t s, const uint8_t *data, size_t datalen);
106
123int tc_sha256_final(uint8_t *digest, TCSha256State_t s);
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* __TC_SHA256_H__ */
int tc_sha256_update(TCSha256State_t s, const uint8_t *data, size_t datalen)
SHA256 update procedure Hashes data_length bytes addressed by data into state s.
Definition sha256.c:65
int tc_sha256_init(TCSha256State_t s)
SHA256 initialization procedure Initializes s.
Definition sha256.c:39
int tc_sha256_final(uint8_t *digest, TCSha256State_t s)
SHA256 final procedure Inserts the completed hash computation into digest.
Definition sha256.c:87