1 /* cryptmodule.c - by Steve Majewski 2 */ 3 4 #include "Python.h" 5 6 #include <sys/types.h> 7 8 /* Module crypt */ 9 10 /*[clinic input] 11 module crypt 12 [clinic start generated code]*/ 13 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/ 14 15 #include "clinic/_cryptmodule.c.h" 16 17 /*[clinic input] 18 crypt.crypt 19 20 word: str 21 salt: str 22 / 23 24 Hash a *word* with the given *salt* and return the hashed password. 25 26 *word* will usually be a user's password. *salt* (either a random 2 or 16 27 character string, possibly prefixed with $digit$ to indicate the method) 28 will be used to perturb the encryption algorithm and produce distinct 29 results for a given *word*. 30 31 [clinic start generated code]*/ 32 33 static PyObject * 34 crypt_crypt_impl(PyObject *module, const char *word, const char *salt) 35 /*[clinic end generated code: output=0512284a03d2803c input=0e8edec9c364352b]*/ 36 { 37 /* On some platforms (AtheOS) crypt returns NULL for an invalid 38 salt. Return None in that case. XXX Maybe raise an exception? */ 39 return Py_BuildValue("s", crypt(word, salt)); 40 } 41 42 43 static PyMethodDef crypt_methods[] = { 44 CRYPT_CRYPT_METHODDEF 45 {NULL, NULL} /* sentinel */ 46 }; 47 48 49 static struct PyModuleDef cryptmodule = { 50 PyModuleDef_HEAD_INIT, 51 "_crypt", 52 NULL, 53 -1, 54 crypt_methods, 55 NULL, 56 NULL, 57 NULL, 58 NULL 59 }; 60 61 PyMODINIT_FUNC 62 PyInit__crypt(void) 63 { 64 return PyModule_Create(&cryptmodule); 65 } 66