You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4 KiB

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