ยปCore Development>Code coverage>Modules/_blake2/blake2module.c

Python code coverage for Modules/_blake2/blake2module.c

#countcontent
1n/a/*
2n/a * Written in 2013 by Dmitry Chestnykh <dmitry@codingrobots.com>
3n/a * Modified for CPython by Christian Heimes <christian@python.org>
4n/a *
5n/a * To the extent possible under law, the author have dedicated all
6n/a * copyright and related and neighboring rights to this software to
7n/a * the public domain worldwide. This software is distributed without
8n/a * any warranty. http://creativecommons.org/publicdomain/zero/1.0/
9n/a */
10n/a
11n/a#include "Python.h"
12n/a
13n/a#include "impl/blake2.h"
14n/a
15n/aextern PyTypeObject PyBlake2_BLAKE2bType;
16n/aextern PyTypeObject PyBlake2_BLAKE2sType;
17n/a
18n/a
19n/aPyDoc_STRVAR(blake2mod__doc__,
20n/a"_blake2b provides BLAKE2b for hashlib\n"
21n/a);
22n/a
23n/a
24n/astatic struct PyMethodDef blake2mod_functions[] = {
25n/a {NULL, NULL}
26n/a};
27n/a
28n/astatic struct PyModuleDef blake2_module = {
29n/a PyModuleDef_HEAD_INIT,
30n/a "_blake2",
31n/a blake2mod__doc__,
32n/a -1,
33n/a blake2mod_functions,
34n/a NULL,
35n/a NULL,
36n/a NULL,
37n/a NULL
38n/a};
39n/a
40n/a#define ADD_INT(d, name, value) do { \
41n/a PyObject *x = PyLong_FromLong(value); \
42n/a if (!x) { \
43n/a Py_DECREF(m); \
44n/a return NULL; \
45n/a } \
46n/a if (PyDict_SetItemString(d, name, x) < 0) { \
47n/a Py_DECREF(m); \
48n/a return NULL; \
49n/a } \
50n/a Py_DECREF(x); \
51n/a} while(0)
52n/a
53n/a
54n/aPyMODINIT_FUNC
55n/aPyInit__blake2(void)
56n/a{
57n/a PyObject *m;
58n/a PyObject *d;
59n/a
60n/a m = PyModule_Create(&blake2_module);
61n/a if (m == NULL)
62n/a return NULL;
63n/a
64n/a /* BLAKE2b */
65n/a Py_TYPE(&PyBlake2_BLAKE2bType) = &PyType_Type;
66n/a if (PyType_Ready(&PyBlake2_BLAKE2bType) < 0) {
67n/a return NULL;
68n/a }
69n/a
70n/a Py_INCREF(&PyBlake2_BLAKE2bType);
71n/a PyModule_AddObject(m, "blake2b", (PyObject *)&PyBlake2_BLAKE2bType);
72n/a
73n/a d = PyBlake2_BLAKE2bType.tp_dict;
74n/a ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES);
75n/a ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES);
76n/a ADD_INT(d, "MAX_KEY_SIZE", BLAKE2B_KEYBYTES);
77n/a ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES);
78n/a
79n/a PyModule_AddIntConstant(m, "BLAKE2B_SALT_SIZE", BLAKE2B_SALTBYTES);
80n/a PyModule_AddIntConstant(m, "BLAKE2B_PERSON_SIZE", BLAKE2B_PERSONALBYTES);
81n/a PyModule_AddIntConstant(m, "BLAKE2B_MAX_KEY_SIZE", BLAKE2B_KEYBYTES);
82n/a PyModule_AddIntConstant(m, "BLAKE2B_MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES);
83n/a
84n/a /* BLAKE2s */
85n/a Py_TYPE(&PyBlake2_BLAKE2sType) = &PyType_Type;
86n/a if (PyType_Ready(&PyBlake2_BLAKE2sType) < 0) {
87n/a return NULL;
88n/a }
89n/a
90n/a Py_INCREF(&PyBlake2_BLAKE2sType);
91n/a PyModule_AddObject(m, "blake2s", (PyObject *)&PyBlake2_BLAKE2sType);
92n/a
93n/a d = PyBlake2_BLAKE2sType.tp_dict;
94n/a ADD_INT(d, "SALT_SIZE", BLAKE2S_SALTBYTES);
95n/a ADD_INT(d, "PERSON_SIZE", BLAKE2S_PERSONALBYTES);
96n/a ADD_INT(d, "MAX_KEY_SIZE", BLAKE2S_KEYBYTES);
97n/a ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES);
98n/a
99n/a PyModule_AddIntConstant(m, "BLAKE2S_SALT_SIZE", BLAKE2S_SALTBYTES);
100n/a PyModule_AddIntConstant(m, "BLAKE2S_PERSON_SIZE", BLAKE2S_PERSONALBYTES);
101n/a PyModule_AddIntConstant(m, "BLAKE2S_MAX_KEY_SIZE", BLAKE2S_KEYBYTES);
102n/a PyModule_AddIntConstant(m, "BLAKE2S_MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES);
103n/a
104n/a return m;
105n/a}