|
| 1 | +/* |
| 2 | + * @author Bénédikt Tran |
| 3 | + * @date December 2024 |
| 4 | + * |
| 5 | + * Implement the HMAC algorithm as described by RFC 2104 using HACL*. |
| 6 | + * |
| 7 | + * Using HACL* implementation implicitly assumes that the caller wants |
| 8 | + * a formally verified implementation. In particular, only algorithms |
| 9 | + * given by their names will be recognized. |
| 10 | + * |
| 11 | + * Some algorithms exposed by `_hashlib` such as truncated SHA-2-512-224/256 |
| 12 | + * are not yet implemented by the HACL* project. Nonetheless, the supported |
| 13 | + * HMAC algorithms form a subset of those supported by '_hashlib'. |
| 14 | + */ |
| 15 | + |
| 16 | +#ifndef Py_BUILD_CORE_BUILTIN |
| 17 | +# define Py_BUILD_CORE_MODULE 1 |
| 18 | +#endif |
| 19 | + |
| 20 | +#include "Python.h" |
| 21 | + |
| 22 | +// --- HMAC module clinic configuration --------------------------------------- |
| 23 | + |
| 24 | +/*[clinic input] |
| 25 | +module _hmac |
| 26 | +[clinic start generated code]*/ |
| 27 | +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=799f0f10157d561f]*/ |
| 28 | + |
| 29 | +// --- HMAC module methods ---------------------------------------------------- |
| 30 | + |
| 31 | +static PyMethodDef hmacmodule_methods[] = { |
| 32 | + {NULL, NULL, 0, NULL} /* sentinel */ |
| 33 | +}; |
| 34 | + |
| 35 | +// --- HMAC module initialization and finalization functions ------------------ |
| 36 | + |
| 37 | +static struct PyModuleDef_Slot hmacmodule_slots[] = { |
| 38 | + {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, |
| 39 | + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, |
| 40 | + {0, NULL} /* sentinel */ |
| 41 | +}; |
| 42 | + |
| 43 | +static struct PyModuleDef _hmacmodule = { |
| 44 | + PyModuleDef_HEAD_INIT, |
| 45 | + .m_name = "_hmac", |
| 46 | + .m_size = sizeof(hmacmodule_state), |
| 47 | + .m_methods = hmacmodule_methods, |
| 48 | + .m_slots = hmacmodule_slots, |
| 49 | +}; |
| 50 | + |
| 51 | +PyMODINIT_FUNC |
| 52 | +PyInit__hmac(void) |
| 53 | +{ |
| 54 | + return PyModuleDef_Init(&_hmacmodule); |
| 55 | +} |
0 commit comments