Skip to content

Commit e714135

Browse files
committed
Define HMAC static information
1 parent 612974e commit e714135

File tree

1 file changed

+94
-15
lines changed

1 file changed

+94
-15
lines changed

Modules/hmacmodule.c

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,64 @@
99

1010
#include "clinic/hmacmodule.c.h"
1111

12-
typedef void (*HACL_HMAC_digest_f)(uint8_t *out,
13-
uint8_t *key, uint32_t keylen,
14-
uint8_t *msg, uint32_t msglen);
12+
typedef void (*HACL_HMAC_digest_func_t)(uint8_t *out,
13+
uint8_t *key, uint32_t keylen,
14+
uint8_t *msg, uint32_t msglen);
15+
16+
// HMAC underlying hash function static information.
17+
18+
/* MD-5 */
19+
#define Py_hmac_md5_block_size 64
20+
#define Py_hmac_md5_digest_size 16
21+
#define Py_hmac_md5_digest_func Hacl_HMAC_compute_md5
22+
23+
/* SHA-1 family */
24+
#define Py_hmac_sha1_block_size 64
25+
#define Py_hmac_sha1_digest_size 20
26+
#define Py_hmac_sha1_digest_func Hacl_HMAC_compute_sha1
27+
28+
/* SHA-2 family */
29+
#define Py_hmac_sha2_224_block_size 64
30+
#define Py_hmac_sha2_224_digest_size 28
31+
#define Py_hmac_sha2_224_digest_func Hacl_HMAC_compute_sha2_224
32+
33+
#define Py_hmac_sha2_256_block_size 64
34+
#define Py_hmac_sha2_256_digest_size 32
35+
#define Py_hmac_sha2_256_digest_func Hacl_HMAC_compute_sha2_256
36+
37+
#define Py_hmac_sha2_384_block_size 128
38+
#define Py_hmac_sha2_384_digest_size 48
39+
#define Py_hmac_sha2_384_digest_func Hacl_HMAC_compute_sha2_384
40+
41+
#define Py_hmac_sha2_512_block_size 128
42+
#define Py_hmac_sha2_512_digest_size 64
43+
#define Py_hmac_sha2_512_digest_func Hacl_HMAC_compute_sha2_512
44+
45+
/* SHA-3 family */
46+
#define Py_hmac_sha3_224_block_size 144
47+
#define Py_hmac_sha3_224_digest_size 28
48+
#define Py_hmac_sha3_224_digest_func Hacl_HMAC_compute_sha3_224
49+
50+
#define Py_hmac_sha3_256_block_size 136
51+
#define Py_hmac_sha3_256_digest_size 32
52+
#define Py_hmac_sha3_256_digest_func Hacl_HMAC_compute_sha3_256
53+
54+
#define Py_hmac_sha3_384_block_size 104
55+
#define Py_hmac_sha3_384_digest_size 48
56+
#define Py_hmac_sha3_384_digest_func Hacl_HMAC_compute_sha3_384
57+
58+
#define Py_hmac_sha3_512_block_size 72
59+
#define Py_hmac_sha3_512_digest_size 64
60+
#define Py_hmac_sha3_512_digest_func Hacl_HMAC_compute_sha3_512
61+
62+
/* Blake family */
63+
#define Py_hmac_blake2s_block_size 64
64+
#define Py_hmac_blake2s_digest_size 32
65+
#define Py_hmac_blake2s_digest_func Hacl_HMAC_compute_blake2s_32
66+
67+
#define Py_hmac_blake2b_block_size 128
68+
#define Py_hmac_blake2b_digest_size 64
69+
#define Py_hmac_blake2b_digest_func Hacl_HMAC_compute_blake2b_32
1570

1671
/* Check that the buffer length fits on a uint32_t. */
1772
static inline int
@@ -69,7 +124,9 @@ static PyObject *
69124
_hmac_compute_md5_impl(PyObject *module, PyObject *key, PyObject *msg)
70125
/*[clinic end generated code: output=7837a4ceccbbf636 input=77a4b774c7d61218]*/
71126
{
72-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_md5, 16, key, msg);
127+
Py_HACL_HMAC_ONESHOT(Py_hmac_md5_digest_func,
128+
Py_hmac_md5_digest_size,
129+
key, msg);
73130
}
74131

75132
/*[clinic input]
@@ -85,7 +142,9 @@ static PyObject *
85142
_hmac_compute_sha1_impl(PyObject *module, PyObject *key, PyObject *msg)
86143
/*[clinic end generated code: output=79fd7689c83691d8 input=3b64dccc6bdbe4ba]*/
87144
{
88-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha1, 20, key, msg);
145+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha1_digest_func,
146+
Py_hmac_sha1_digest_size,
147+
key, msg);
89148
}
90149

91150
/*[clinic input]
@@ -101,7 +160,9 @@ static PyObject *
101160
_hmac_compute_sha2_224_impl(PyObject *module, PyObject *key, PyObject *msg)
102161
/*[clinic end generated code: output=7f21f1613e53979e input=bcaac7a3637484ce]*/
103162
{
104-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha2_224, 28, key, msg);
163+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha2_224_digest_func,
164+
Py_hmac_sha2_224_digest_size,
165+
key, msg);
105166
}
106167

107168
/*[clinic input]
@@ -117,7 +178,9 @@ static PyObject *
117178
_hmac_compute_sha2_256_impl(PyObject *module, PyObject *key, PyObject *msg)
118179
/*[clinic end generated code: output=d4a291f7d9a82459 input=6e2d1f6fe9c56d21]*/
119180
{
120-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha2_256, 32, key, msg);
181+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha2_256_digest_func,
182+
Py_hmac_sha2_256_digest_size,
183+
key, msg);
121184
}
122185

123186
/*[clinic input]
@@ -133,7 +196,9 @@ static PyObject *
133196
_hmac_compute_sha2_384_impl(PyObject *module, PyObject *key, PyObject *msg)
134197
/*[clinic end generated code: output=f211fa26e3700c27 input=9ce8de89dda79e62]*/
135198
{
136-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha2_384, 48, key, msg);
199+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha2_384_digest_func,
200+
Py_hmac_sha2_384_digest_size,
201+
key, msg);
137202
}
138203

139204
/*[clinic input]
@@ -149,7 +214,9 @@ static PyObject *
149214
_hmac_compute_sha2_512_impl(PyObject *module, PyObject *key, PyObject *msg)
150215
/*[clinic end generated code: output=d5c20373762cecca input=b964bb8487d7debd]*/
151216
{
152-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha2_512, 64, key, msg);
217+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha2_512_digest_func,
218+
Py_hmac_sha2_512_digest_size,
219+
key, msg);
153220
}
154221

155222
/*[clinic input]
@@ -165,7 +232,9 @@ static PyObject *
165232
_hmac_compute_sha3_224_impl(PyObject *module, PyObject *key, PyObject *msg)
166233
/*[clinic end generated code: output=a242ccac9ad9c22b input=d0ab0c7d189c3d87]*/
167234
{
168-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha3_224, 28, key, msg);
235+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha3_224_digest_func,
236+
Py_hmac_sha3_224_digest_size,
237+
key, msg);
169238
}
170239

171240
/*[clinic input]
@@ -181,7 +250,9 @@ static PyObject *
181250
_hmac_compute_sha3_256_impl(PyObject *module, PyObject *key, PyObject *msg)
182251
/*[clinic end generated code: output=b539dbb61af2fe0b input=f05d7b6364b35d02]*/
183252
{
184-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha3_256, 32, key, msg);
253+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha3_256_digest_func,
254+
Py_hmac_sha3_256_digest_size,
255+
key, msg);
185256
}
186257

187258
/*[clinic input]
@@ -197,7 +268,9 @@ static PyObject *
197268
_hmac_compute_sha3_384_impl(PyObject *module, PyObject *key, PyObject *msg)
198269
/*[clinic end generated code: output=5eb372fb5c4ffd3a input=d842d393e7aa05ae]*/
199270
{
200-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha3_384, 48, key, msg);
271+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha3_384_digest_func,
272+
Py_hmac_sha3_384_digest_size,
273+
key, msg);
201274
}
202275

203276
/*[clinic input]
@@ -213,7 +286,9 @@ static PyObject *
213286
_hmac_compute_sha3_512_impl(PyObject *module, PyObject *key, PyObject *msg)
214287
/*[clinic end generated code: output=154bcbf8c2eacac1 input=166fe5baaeaabfde]*/
215288
{
216-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_sha3_512, 64, key, msg);
289+
Py_HACL_HMAC_ONESHOT(Py_hmac_sha3_512_digest_func,
290+
Py_hmac_sha3_512_digest_size,
291+
key, msg);
217292
}
218293

219294
/*[clinic input]
@@ -229,7 +304,9 @@ static PyObject *
229304
_hmac_compute_blake2s_32_impl(PyObject *module, PyObject *key, PyObject *msg)
230305
/*[clinic end generated code: output=cfc730791bc62361 input=d22c36e7fe31a985]*/
231306
{
232-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_blake2s_32, 32, key, msg);
307+
Py_HACL_HMAC_ONESHOT(Py_hmac_blake2s_digest_func,
308+
Py_hmac_blake2s_digest_size,
309+
key, msg);
233310
}
234311

235312
/*[clinic input]
@@ -245,7 +322,9 @@ static PyObject *
245322
_hmac_compute_blake2b_32_impl(PyObject *module, PyObject *key, PyObject *msg)
246323
/*[clinic end generated code: output=765c5c4fb9124636 input=4a35ee058d172f4b]*/
247324
{
248-
Py_HACL_HMAC_ONESHOT(Hacl_HMAC_compute_blake2b_32, 64, key, msg);
325+
Py_HACL_HMAC_ONESHOT(Py_hmac_blake2b_digest_func,
326+
Py_hmac_blake2b_digest_size,
327+
key, msg);
249328
}
250329

251330
static PyMethodDef hmacmodule_methods[] = {

0 commit comments

Comments
 (0)