sha2.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * sha2.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "api.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /*
20  * SHA224
21  */
22 
23 #define SHA224_SIZE 28
24 #define SHA224_STATESIZE 32
25 #define SHA224_BLOCKSIZE 64
26 
27 typedef struct {
28  uint32_t state[8];
29  uint32_t count;
30  uint8_t buffer[SHA224_BLOCKSIZE];
32 
33 CRYPTO_FUNC_INIT(sha224);
34 CRYPTO_FUNC_UPDATE(sha224);
35 CRYPTO_FUNC_FINAL(sha224);
36 CRYPTO_FUNC_GET_STATE(sha224);
37 CRYPTO_FUNC_SET_STATE(sha224);
38 
39 /*
40  * SHA256
41  */
42 
43 #define SHA256_SIZE 32
44 #define SHA256_STATESIZE 32
45 #define SHA256_BLOCKSIZE 64
46 
48 
49 CRYPTO_FUNC_INIT(sha256);
50 CRYPTO_FUNC_UPDATE(sha256);
51 CRYPTO_FUNC_FINAL(sha256);
52 CRYPTO_FUNC_GET_STATE(sha256);
53 CRYPTO_FUNC_SET_STATE(sha256);
54 
55 CRYPTO_FUNC_HMAC_V(sha256);
56 static inline CRYPTO_FUNC_HMAC(sha256)
57 {
58  crypto_sha256_hmac_v(&msg, &msg_len, 1, key, key_len, digest);
59 }
60 
61 /*
62  * SHA384
63  */
64 
65 #define SHA384_SIZE 48
66 #define SHA384_STATESIZE 64
67 #define SHA384_BLOCKSIZE 128
68 
69 typedef struct {
70  uint64_t state[8];
71  uint32_t count;
72  uint8_t buffer[SHA384_BLOCKSIZE];
74 
75 CRYPTO_FUNC_INIT(sha384);
76 CRYPTO_FUNC_UPDATE(sha384);
77 CRYPTO_FUNC_FINAL(sha384);
78 CRYPTO_FUNC_GET_STATE(sha384);
79 CRYPTO_FUNC_SET_STATE(sha384);
80 
81 CRYPTO_FUNC_HMAC_V(sha384);
82 
83 static inline CRYPTO_FUNC_HMAC(sha384)
84 {
85  crypto_sha384_hmac_v(&msg, &msg_len, 1, key, key_len, digest);
86 }
87 
88 /*
89  * SHA512
90  */
91 
92 #define SHA512_SIZE 64
93 #define SHA512_STATESIZE 64
94 #define SHA512_BLOCKSIZE 128
95 
97 
98 CRYPTO_FUNC_INIT(sha512);
99 CRYPTO_FUNC_UPDATE(sha512);
100 CRYPTO_FUNC_FINAL(sha512);
101 CRYPTO_FUNC_GET_STATE(sha512);
102 CRYPTO_FUNC_SET_STATE(sha512);
103 
104 CRYPTO_FUNC_HMAC_V(sha512);
105 
106 static inline CRYPTO_FUNC_HMAC(sha512)
107 {
108  crypto_sha512_hmac_v(&msg, &msg_len, 1, key, key_len, digest);
109 }
110 
111 #ifdef __cplusplus
112 }
113 #endif
crypto_sha384_context_t crypto_sha512_context_t
Definition: sha2.h:96
uint32_t count
Definition: sha2.h:71
uint32_t count
Definition: sha2.h:29
static CRYPTO_FUNC_HMAC(sha256)
Definition: sha2.h:56
CRYPTO_FUNC_FINAL(sha224)
Definition: sha2.h:27
CRYPTO_FUNC_SET_STATE(sha224)
CRYPTO_FUNC_GET_STATE(sha224)
void size_t const void * key
Definition: blake2s.h:33
crypto_sha224_context_t crypto_sha256_context_t
Definition: sha2.h:47
Definition: sha2.h:69
CRYPTO_FUNC_INIT(sha224)
#define SHA224_BLOCKSIZE
Definition: sha2.h:25
CRYPTO_FUNC_HMAC_V(sha256)
#define SHA384_BLOCKSIZE
Definition: sha2.h:67
CRYPTO_FUNC_UPDATE(sha224)