/* MD5 module */ /* This module provides an interface to the MD5 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. */ /* MD5 objects */ #ifndef Py_BUILD_CORE_BUILTIN #define Py_BUILD_CORE_MODULE … #endif #include "Python.h" #include "hashlib.h" /*[clinic input] module _md5 class MD5Type "MD5object *" "&PyType_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=6e5261719957a912]*/ /* Some useful types */ #if SIZEOF_INT == 4 MD5_INT32; /* 32-bit integer */ MD5_INT64; /* 64-bit integer */ #else /* not defined. compilation will die. */ #endif /* The MD5 block size and message digest sizes, in bytes */ #define MD5_BLOCKSIZE … #define MD5_DIGESTSIZE … #include "_hacl/Hacl_Hash_MD5.h" MD5object; #include "clinic/md5module.c.h" MD5State; static inline MD5State* md5_get_state(PyObject *module) { … } static MD5object * newMD5object(MD5State * st) { … } /* Internal methods for a hash object */ static int MD5_traverse(PyObject *ptr, visitproc visit, void *arg) { … } static void MD5_dealloc(MD5object *ptr) { … } /* External methods for a hash object */ /*[clinic input] MD5Type.copy cls: defining_class Return a copy of the hash object. [clinic start generated code]*/ static PyObject * MD5Type_copy_impl(MD5object *self, PyTypeObject *cls) /*[clinic end generated code: output=bf055e08244bf5ee input=d89087dcfb2a8620]*/ { … } /*[clinic input] MD5Type.digest Return the digest value as a bytes object. [clinic start generated code]*/ static PyObject * MD5Type_digest_impl(MD5object *self) /*[clinic end generated code: output=eb691dc4190a07ec input=bc0c4397c2994be6]*/ { … } /*[clinic input] MD5Type.hexdigest Return the digest value as a string of hexadecimal digits. [clinic start generated code]*/ static PyObject * MD5Type_hexdigest_impl(MD5object *self) /*[clinic end generated code: output=17badced1f3ac932 input=b60b19de644798dd]*/ { … } static void update(Hacl_Hash_MD5_state_t *state, uint8_t *buf, Py_ssize_t len) { … } /*[clinic input] MD5Type.update obj: object / Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * MD5Type_update(MD5object *self, PyObject *obj) /*[clinic end generated code: output=f6ad168416338423 input=6e1efcd9ecf17032]*/ { … } static PyMethodDef MD5_methods[] = …; static PyObject * MD5_get_block_size(PyObject *self, void *closure) { … } static PyObject * MD5_get_name(PyObject *self, void *closure) { … } static PyObject * md5_get_digest_size(PyObject *self, void *closure) { … } static PyGetSetDef MD5_getseters[] = …; static PyType_Slot md5_type_slots[] = …; static PyType_Spec md5_type_spec = …; /* The single module-level function: new() */ /*[clinic input] _md5.md5 string: object(c_default="NULL") = b'' * usedforsecurity: bool = True Return a new MD5 hash object; optionally initialized with a string. [clinic start generated code]*/ static PyObject * _md5_md5_impl(PyObject *module, PyObject *string, int usedforsecurity) /*[clinic end generated code: output=587071f76254a4ac input=7a144a1905636985]*/ { … } /* List of functions exported by this module */ static struct PyMethodDef MD5_functions[] = …; static int _md5_traverse(PyObject *module, visitproc visit, void *arg) { … } static int _md5_clear(PyObject *module) { … } static void _md5_free(void *module) { … } /* Initialize this module. */ static int md5_exec(PyObject *m) { … } static PyModuleDef_Slot _md5_slots[] = …; static struct PyModuleDef _md5module = …; PyMODINIT_FUNC PyInit__md5(void) { … }