16#ifndef CRYPTO_SHA256_H
17#define CRYPTO_SHA256_H
25#define EP0(x) xor3(ror32(x, 2), ror32(x, 13), ror32(x, 22))
26#define EP1(x) xor3(ror32(x, 6), ror32(x, 11), ror32(x, 25))
27#define S0(x) xor3(ror32(x, 7), ror32(x, 18), ((x) >> 3))
28#define S1(x) xor3(ror32(x, 17), ror32(x, 19), ((x) >> 10))
30#define sha256_blk0(i) ( W[i] = bswap32(W[i]) )
31#define sha256_blk(i) ( W[i & 15] += \
32 S1(W[(i - 2) & 15]) + W[(i - 7) & 15] + S0(W[(i - 15) & 15]) )
34#define Ch(x, y, z) xandx(x, y, z)
35#define Maj(x, y, z) ( (x & y) | (z & (x | y)) )
38#define R0(a, b, c, d, e, f, g, h, i) \
39 h += EP1(e) + Ch(e,f,g) + k[i] + sha256_blk0(i); \
40 d += h; h += EP0(a) + Maj(a, b, c)
42#define R(a, b, c, d, e, f, g, h, i, j) \
43 h += EP1(e) + Ch(e,f,g) + k[i+j] + sha256_blk(i); \
44 d += h; h += EP0(a) + Maj(a, b, c)
47 R0(a, b, c, d, e, f, g, h, i); \
48 R0(h, a, b, c, d, e, f, g, (i + 1)); \
49 R0(g, h, a, b, c, d, e, f, (i + 2)); \
50 R0(f, g, h, a, b, c, d, e, (i + 3)); \
51 R0(e, f, g, h, a, b, c, d, (i + 4)); \
52 R0(d, e, f, g, h, a, b, c, (i + 5)); \
53 R0(c, d, e, f, g, h, a, b, (i + 6)); \
54 R0(b, c, d, e, f, g, h, a, (i + 7))
57 R(a, b, c, d, e, f, g, h, i, j); \
58 R(h, a, b, c, d, e, f, g, (i + 1), j); \
59 R(g, h, a, b, c, d, e, f, (i + 2), j); \
60 R(f, g, h, a, b, c, d, e, (i + 3), j); \
61 R(e, f, g, h, a, b, c, d, (i + 4), j); \
62 R(d, e, f, g, h, a, b, c, (i + 5), j); \
63 R(c, d, e, f, g, h, a, b, (i + 6), j); \
64 R(b, c, d, e, f, g, h, a, (i + 7), j)
80 SHA256_CTX *ctx,
const void *in,
size_t inlen);
82void sha256(
const void *in,
size_t inlen,
void *out);
86 void test_kcu_sha256(
const void *in,
size_t *inlen,
size_t max_inlen,
void sha256(const void *in, size_t inlen, void *out)
Convenient all-in-one SHA256 computation.
Definition: sha256.c:177
void sha256_final(SHA256_CTX *ctx, void *out)
Finalize a SHA256 message digest.
Definition: sha256.c:129
void sha256_init(SHA256_CTX *ctx)
Initialize a SHA256 context.
Definition: sha256.c:82
void sha256_update(SHA256_CTX *ctx, const void *in, size_t inlen)
Add inlen bytes from in to a SHA256 context for hashing.
Definition: sha256.c:102
uint32_t datalen
Length of buffered input.
Definition: sha256.h:70
Device utilities and includes support.