/* SHA1 module */ /* This module provides an interface to the SHA1 algorithm */ /* See below for information about the original code this module was based upon. Additional work performed by: Andrew Kuchling ([email protected]) Greg Stein ([email protected]) Trevor Perrin ([email protected]) Copyright (C) 2005-2007 Gregory P. Smith ([email protected]) Licensed to PSF under a Contributor Agreement. */ /* SHA1 objects */ #ifndef Py_BUILD_CORE_BUILTIN #define Py_BUILD_CORE_MODULE … #endif #include "Python.h" #include "hashlib.h" #include "pycore_strhex.h" // _Py_strhex() #include "pycore_typeobject.h" // _PyType_GetModuleState() /*[clinic input] module _sha1 class SHA1Type "SHA1object *" "&PyType_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3dc9a20d1becb759]*/ /* Some useful types */ #if SIZEOF_INT == 4 SHA1_INT32; /* 32-bit integer */ SHA1_INT64; /* 64-bit integer */ #else /* not defined. compilation will die. */ #endif /* The SHA1 block size and message digest sizes, in bytes */ #define SHA1_BLOCKSIZE … #define SHA1_DIGESTSIZE … #include "_hacl/Hacl_Hash_SHA1.h" SHA1object; #include "clinic/sha1module.c.h" SHA1State; static inline SHA1State* sha1_get_state(PyObject *module) { … } static SHA1object * newSHA1object(SHA1State *st) { … } /* Internal methods for a hash object */ static int SHA1_traverse(PyObject *ptr, visitproc visit, void *arg) { … } static void SHA1_dealloc(SHA1object *ptr) { … } /* External methods for a hash object */ /*[clinic input] SHA1Type.copy cls: defining_class Return a copy of the hash object. [clinic start generated code]*/ static PyObject * SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls) /*[clinic end generated code: output=b32d4461ce8bc7a7 input=6c22e66fcc34c58e]*/ { … } /*[clinic input] SHA1Type.digest Return the digest value as a bytes object. [clinic start generated code]*/ static PyObject * SHA1Type_digest_impl(SHA1object *self) /*[clinic end generated code: output=2f05302a7aa2b5cb input=13824b35407444bd]*/ { … } /*[clinic input] SHA1Type.hexdigest Return the digest value as a string of hexadecimal digits. [clinic start generated code]*/ static PyObject * SHA1Type_hexdigest_impl(SHA1object *self) /*[clinic end generated code: output=4161fd71e68c6659 input=97691055c0c74ab0]*/ { … } static void update(Hacl_Hash_SHA1_state_t *state, uint8_t *buf, Py_ssize_t len) { … } /*[clinic input] SHA1Type.update obj: object / Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * SHA1Type_update(SHA1object *self, PyObject *obj) /*[clinic end generated code: output=d9902f0e5015e9ae input=aad8e07812edbba3]*/ { … } static PyMethodDef SHA1_methods[] = …; static PyObject * SHA1_get_block_size(PyObject *self, void *closure) { … } static PyObject * SHA1_get_name(PyObject *self, void *closure) { … } static PyObject * sha1_get_digest_size(PyObject *self, void *closure) { … } static PyGetSetDef SHA1_getseters[] = …; static PyType_Slot sha1_type_slots[] = …; static PyType_Spec sha1_type_spec = …; /* The single module-level function: new() */ /*[clinic input] _sha1.sha1 string: object(c_default="NULL") = b'' * usedforsecurity: bool = True Return a new SHA1 hash object; optionally initialized with a string. [clinic start generated code]*/ static PyObject * _sha1_sha1_impl(PyObject *module, PyObject *string, int usedforsecurity) /*[clinic end generated code: output=6f8b3af05126e18e input=bd54b68e2bf36a8a]*/ { … } /* List of functions exported by this module */ static struct PyMethodDef SHA1_functions[] = …; static int _sha1_traverse(PyObject *module, visitproc visit, void *arg) { … } static int _sha1_clear(PyObject *module) { … } static void _sha1_free(void *module) { … } static int _sha1_exec(PyObject *module) { … } /* Initialize this module. */ static PyModuleDef_Slot _sha1_slots[] = …; static struct PyModuleDef _sha1module = …; PyMODINIT_FUNC PyInit__sha1(void) { … }