9910101111 Jonathan Protzenko ([email protected] ) 12+ 1213
1314 Copyright (C) 2005-2007 Gregory P. Smith ([email protected] ) 1415 Licensed to PSF under a Contributor Agreement.
1516
1617*/
1718
18- /* SHA objects */
1919#ifndef Py_BUILD_CORE_BUILTIN
2020# define Py_BUILD_CORE_MODULE 1
2121#endif
2222
2323#include "Python.h"
24- #include "pycore_bitutils.h" // _Py_bswap32()
2524#include "pycore_moduleobject.h" // _PyModule_GetState()
2625#include "pycore_typeobject.h" // _PyType_GetModuleState()
2726#include "pycore_strhex.h" // _Py_strhex()
2827
2928#include "hashlib.h"
3029
31- /*[clinic input]
32- module _sha2
33- class SHA256Type "SHA256object *" "&PyType_Type"
34- class SHA512Type "SHA512object *" "&PyType_Type"
35- [clinic start generated code]*/
36- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b5315a7b611c9afc]*/
37-
30+ #include "_hacl/Hacl_Hash_SHA2.h"
3831
3932/* The SHA block sizes and maximum message digest sizes, in bytes */
4033
@@ -43,9 +36,7 @@ class SHA512Type "SHA512object *" "&PyType_Type"
4336#define SHA512_BLOCKSIZE 128
4437#define SHA512_DIGESTSIZE 64
4538
46- /* Our SHA2 implementations defer to the HACL* verified library. */
47-
48- #include "_hacl/Hacl_Hash_SHA2.h"
39+ // --- Module objects ---------------------------------------------------------
4940
5041// TODO: Get rid of int digestsize in favor of Hacl state info?
5142
@@ -64,7 +55,7 @@ typedef struct {
6455#define _SHA256object_CAST (op ) ((SHA256object *)(op))
6556#define _SHA512object_CAST (op ) ((SHA512object *)(op))
6657
67- #include "clinic/sha2module.c.h"
58+ // --- Module state -----------------------------------------------------------
6859
6960/* We shall use run-time type information in the remainder of this module to
7061 * tell apart SHA2-224 and SHA2-256 */
@@ -83,6 +74,19 @@ sha2_get_state(PyObject *module)
8374 return (sha2_state * )state ;
8475}
8576
77+ // --- Module clinic configuration --------------------------------------------
78+
79+ /*[clinic input]
80+ module _sha2
81+ class SHA256Type "SHA256object *" "&PyType_Type"
82+ class SHA512Type "SHA512object *" "&PyType_Type"
83+ [clinic start generated code]*/
84+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b5315a7b611c9afc]*/
85+
86+ #include "clinic/sha2module.c.h"
87+
88+ // --- SHA-2 object interface -------------------------------------------------
89+
8690static int
8791SHA256copy (SHA256object * src , SHA256object * dest )
8892{
0 commit comments