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