]>
Commit | Line | Data |
---|---|---|
4035e0e7 PT |
1 | /* |
2 | * BIRD Library -- SHA-256 and SHA-224 Hash Functions, | |
3 | * HMAC-SHA-256 and HMAC-SHA-224 Functions | |
4 | * | |
5 | * (c) 2015 CZ.NIC z.s.p.o. | |
6 | * | |
7 | * Based on the code from libgcrypt-1.6.0, which is | |
8 | * (c) 2003, 2006, 2008, 2009 Free Software Foundation, Inc. | |
9 | * | |
10 | * Can be freely distributed and used under the terms of the GNU GPL. | |
11 | */ | |
12 | ||
13 | #ifndef _BIRD_SHA256_H_ | |
14 | #define _BIRD_SHA256_H_ | |
15 | ||
16 | #include "nest/bird.h" | |
17 | ||
5126380b | 18 | |
4035e0e7 PT |
19 | #define SHA224_SIZE 28 |
20 | #define SHA224_HEX_SIZE 57 | |
21 | #define SHA224_BLOCK_SIZE 64 | |
22 | ||
23 | #define SHA256_SIZE 32 | |
24 | #define SHA256_HEX_SIZE 65 | |
25 | #define SHA256_BLOCK_SIZE 64 | |
26 | ||
5126380b | 27 | |
4035e0e7 | 28 | struct sha256_context { |
5126380b OZ |
29 | u32 h0, h1, h2, h3, h4, h5, h6, h7; |
30 | byte buf[SHA256_BLOCK_SIZE]; | |
31 | uint nblocks; | |
32 | uint count; | |
4035e0e7 | 33 | }; |
5126380b OZ |
34 | |
35 | #define sha224_context sha256_context | |
36 | ||
4035e0e7 PT |
37 | |
38 | void sha256_init(struct sha256_context *ctx); | |
39 | void sha224_init(struct sha224_context *ctx); | |
40 | ||
5126380b OZ |
41 | void sha256_update(struct sha256_context *ctx, const byte *buf, size_t len); |
42 | static inline void sha224_update(struct sha224_context *ctx, const byte *buf, size_t len) | |
43 | { sha256_update(ctx, buf, len); } | |
44 | ||
45 | byte *sha256_final(struct sha256_context *ctx); | |
46 | static inline byte *sha224_final(struct sha224_context *ctx) | |
47 | { return sha256_final(ctx); } | |
4035e0e7 | 48 | |
4035e0e7 PT |
49 | |
50 | /* | |
51 | * HMAC-SHA256, HMAC-SHA224 | |
52 | */ | |
5126380b | 53 | |
4035e0e7 PT |
54 | struct sha256_hmac_context |
55 | { | |
56 | struct sha256_context ictx; | |
57 | struct sha256_context octx; | |
58 | }; | |
5126380b OZ |
59 | |
60 | #define sha224_hmac_context sha256_hmac_context | |
61 | ||
4035e0e7 PT |
62 | |
63 | void sha256_hmac_init(struct sha256_hmac_context *ctx, const byte *key, size_t keylen); | |
5126380b | 64 | void sha224_hmac_init(struct sha224_hmac_context *ctx, const byte *key, size_t keylen); |
4035e0e7 PT |
65 | |
66 | void sha256_hmac_update(struct sha256_hmac_context *ctx, const byte *buf, size_t buflen); | |
67 | void sha224_hmac_update(struct sha224_hmac_context *ctx, const byte *buf, size_t buflen); | |
68 | ||
69 | byte *sha256_hmac_final(struct sha256_hmac_context *ctx); | |
70 | byte *sha224_hmac_final(struct sha224_hmac_context *ctx); | |
71 | ||
5126380b | 72 | |
4035e0e7 | 73 | #endif /* _BIRD_SHA256_H_ */ |