Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 1 | /* cryptmodule.c - by Steve Majewski |
| 2 | */ |
| 3 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 5 | |
| 6 | #include <sys/types.h> |
| 7 | |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 8 | /* Module crypt */ |
| 9 | |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 10 | /*[clinic input] |
| 11 | module crypt |
| 12 | [clinic start generated code]*/ |
Larry Hastings | 581ee36 | 2014-01-28 05:00:08 -0800 | [diff] [blame] | 13 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/ |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 14 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 15 | #include "clinic/_cryptmodule.c.h" |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 16 | |
| 17 | /*[clinic input] |
| 18 | crypt.crypt |
| 19 | |
Serhiy Storchaka | 7e810a6 | 2015-05-30 11:09:35 +0300 | [diff] [blame] | 20 | word: str |
| 21 | salt: str |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 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 | |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 33 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 34 | crypt_crypt_impl(PyObject *module, const char *word, const char *salt) |
| 35 | /*[clinic end generated code: output=0512284a03d2803c input=0e8edec9c364352b]*/ |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 36 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 37 | return Py_BuildValue("s", crypt(word, salt)); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Fred Drake | a664dbb | 2000-02-01 20:12:39 +0000 | [diff] [blame] | 40 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 41 | static PyMethodDef crypt_methods[] = { |
Antoine Pitrou | f5207e6 | 2014-01-14 21:00:27 +0100 | [diff] [blame] | 42 | CRYPT_CRYPT_METHODDEF |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 43 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 46 | |
| 47 | static struct PyModuleDef cryptmodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 48 | PyModuleDef_HEAD_INIT, |
Sean Reifscheider | e2dfefb | 2011-02-22 10:55:44 +0000 | [diff] [blame] | 49 | "_crypt", |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 50 | NULL, |
| 51 | -1, |
| 52 | crypt_methods, |
| 53 | NULL, |
| 54 | NULL, |
| 55 | NULL, |
| 56 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 59 | PyMODINIT_FUNC |
Sean Reifscheider | e2dfefb | 2011-02-22 10:55:44 +0000 | [diff] [blame] | 60 | PyInit__crypt(void) |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 61 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 62 | return PyModule_Create(&cryptmodule); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 63 | } |