MySensors Library & Examples  2.3.2
sha256.h
1 /*
2 * The MySensors Arduino library handles the wireless radio link and protocol
3 * between your home built sensors/actuators and HA controller of choice.
4 * The sensors forms a self healing radio network with optional repeaters. Each
5 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6 * network topology allowing messages to be routed to nodes.
7 *
8 * Created by Henrik Ekblad <[email protected]>
9 * Copyright (C) 2013-2019 Sensnology AB
10 * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11 *
12 * Documentation: http://www.mysensors.org
13 * Support Forum: http://forum.mysensors.org
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * ======================================================================
20 *
21 * SHA256 implementation for AVR:
22 *
23 * This file is part of the AVR-Crypto-Lib.
24 * Copyright (C) 2006-2015 Daniel Otte ([email protected])
25 *
26 * This program is free software: you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation, either version 3 of the License, or
29 * (at your option) any later version.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 *
39 * Author: Daniel Otte
40 *
41 * License: GPLv3 or later
42 *
43 * ======================================================================
44 */
45 
46 #ifndef _SHA256_H_
47 #define _SHA256_H_
48 
49 #define MY_CRYPTO_SHA256_ASM
50 
51 #define IPAD 0x36
52 #define OPAD 0x5C
53 
54 #define SHA256_HASH_BITS 256
55 #define SHA256_HASH_BYTES (SHA256_HASH_BITS/8)
56 #define SHA256_BLOCK_BITS 512
57 #define SHA256_BLOCK_BYTES (SHA256_BLOCK_BITS/8)
58 
59 
64 typedef struct {
65  uint32_t h[8];
66  uint64_t length;
67 } sha256_ctx_t;
68 
75 typedef uint8_t sha256_hash_t[SHA256_HASH_BYTES];
76 
77 extern "C" { // ASM implementation, see MyASM.S
84  void sha256_init(sha256_ctx_t *state);
85 
94  void sha256_nextBlock(sha256_ctx_t *state, const void *block);
95 
105  void sha256_lastBlock(sha256_ctx_t *state, const void *block, uint16_t length_b);
106 
114  void sha256_ctx2hash(sha256_hash_t *dest, const sha256_ctx_t *state);
115 
125  void sha256(sha256_hash_t *dest, const void *msg, uint32_t length_b);
126 }
127 
128 #endif
sha256_ctx_t::length
uint64_t length
length
Definition: sha256.h:66
sha256_ctx_t
SHA-256 context type.
Definition: sha256.h:64