MPHELL
5.0.0
include
mphell-sha256.h
Go to the documentation of this file.
1
/*
2
MPHELL-5.0
3
Author(s): The MPHELL team
4
5
(C) Copyright 2015-2021 - Institut Fourier / Univ. Grenoble Alpes (France)
6
7
This file is part of the MPHELL Library.
8
MPHELL is free software: you can redistribute it and/or modify
9
it under the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation, version 3 of the License.
11
12
MPHELL is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU Lesser General Public License for more details.
16
17
You should have received a copy of the GNU Lesser General Public License
18
along with MPHELL. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
26
#ifndef SHA256_H
27
#define SHA256_H
28
29
#include <stdint.h>
30
#include <string.h>
31
32
/* DBL_INT_ADD treats two unsigned ints a and b as one 64-bit integer and adds c to it */
33
#define DBL_INT_ADD(a,b,c) if (a > 0xffffffff - (c)) ++b; a += c;
34
#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
35
#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
36
37
#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
38
#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
39
#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
40
#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
41
#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
42
#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
43
48
struct
sha256_state_t
49
{
50
unsigned
char
data
[64];
51
uint8_t
datalen
;
52
uint32_t
bitlen
[2];
53
uint32_t
state
[8];
54
};
55
60
typedef
struct
sha256_state_t
sha256_state
;
61
69
void
sha256
(uint8_t * hashvalue,
const
uint8_t *
data
,
const
uint64_t data_len);
70
#endif
sha256
void sha256(uint8_t *hashvalue, const uint8_t *data, const uint64_t data_len)
Compute the Sha256 hash of "data".
Definition:
mphell-sha256.c:180
sha256_state_t
All the sha256 computations are done on this structure.
Definition:
mphell-sha256.h:49
sha256_state_t::bitlen
uint32_t bitlen[2]
Definition:
mphell-sha256.h:52
sha256_state_t::state
uint32_t state[8]
Definition:
mphell-sha256.h:53
sha256_state_t::data
unsigned char data[64]
Definition:
mphell-sha256.h:50
sha256_state_t::datalen
uint8_t datalen
Definition:
mphell-sha256.h:51
Generated by
1.9.1