blob: 58d179e6a3d2d15b3f4db5f098ba2af732e11fe0 [file] [log] [blame]
Guido van Rossume4c61311994-05-06 14:25:39 +00001/* cryptmodule.c - by Steve Majewski
2 */
3
Roger E. Masse56c345b1996-12-09 23:14:26 +00004#include "Python.h"
Guido van Rossume4c61311994-05-06 14:25:39 +00005
6#include <sys/types.h>
7
Guido van Rossume4c61311994-05-06 14:25:39 +00008/* Module crypt */
9
Antoine Pitrouf5207e62014-01-14 21:00:27 +010010/*[clinic input]
11module crypt
12[clinic start generated code]*/
Larry Hastings581ee362014-01-28 05:00:08 -080013/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/
Guido van Rossume4c61311994-05-06 14:25:39 +000014
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030015#include "clinic/_cryptmodule.c.h"
Antoine Pitrouf5207e62014-01-14 21:00:27 +010016
17/*[clinic input]
18crypt.crypt
19
Serhiy Storchaka7e810a62015-05-30 11:09:35 +030020 word: str
21 salt: str
Antoine Pitrouf5207e62014-01-14 21:00:27 +010022 /
23
24Hash 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
27character string, possibly prefixed with $digit$ to indicate the method)
28will be used to perturb the encryption algorithm and produce distinct
29results for a given *word*.
30
31[clinic start generated code]*/
32
Antoine Pitrouf5207e62014-01-14 21:00:27 +010033static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034crypt_crypt_impl(PyObject *module, const char *word, const char *salt)
35/*[clinic end generated code: output=0512284a03d2803c input=0e8edec9c364352b]*/
Antoine Pitrouf5207e62014-01-14 21:00:27 +010036{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000037 return Py_BuildValue("s", crypt(word, salt));
Guido van Rossume4c61311994-05-06 14:25:39 +000038}
39
Fred Drakea664dbb2000-02-01 20:12:39 +000040
Roger E. Masse56c345b1996-12-09 23:14:26 +000041static PyMethodDef crypt_methods[] = {
Antoine Pitrouf5207e62014-01-14 21:00:27 +010042 CRYPT_CRYPT_METHODDEF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000043 {NULL, NULL} /* sentinel */
Guido van Rossume4c61311994-05-06 14:25:39 +000044};
45
Martin v. Löwis1a214512008-06-11 05:26:20 +000046
47static struct PyModuleDef cryptmodule = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000048 PyModuleDef_HEAD_INIT,
Sean Reifscheidere2dfefb2011-02-22 10:55:44 +000049 "_crypt",
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000050 NULL,
51 -1,
52 crypt_methods,
53 NULL,
54 NULL,
55 NULL,
56 NULL
Martin v. Löwis1a214512008-06-11 05:26:20 +000057};
58
Mark Hammondfe51c6d2002-08-02 02:27:13 +000059PyMODINIT_FUNC
Sean Reifscheidere2dfefb2011-02-22 10:55:44 +000060PyInit__crypt(void)
Guido van Rossume4c61311994-05-06 14:25:39 +000061{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000062 return PyModule_Create(&cryptmodule);
Guido van Rossume4c61311994-05-06 14:25:39 +000063}