• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_long.h"          // _PyLong_UnsignedLong_Converter()
10 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
11 
12 PyDoc_STRVAR(py_blake2b_new__doc__,
13 "blake2b(data=b\'\', /, *, digest_size=_blake2.blake2b.MAX_DIGEST_SIZE,\n"
14 "        key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
15 "        node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
16 "        usedforsecurity=True)\n"
17 "--\n"
18 "\n"
19 "Return a new BLAKE2b hash object.");
20 
21 static PyObject *
22 py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
23                     Py_buffer *key, Py_buffer *salt, Py_buffer *person,
24                     int fanout, int depth, unsigned long leaf_size,
25                     unsigned long long node_offset, int node_depth,
26                     int inner_size, int last_node, int usedforsecurity);
27 
28 static PyObject *
py_blake2b_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)29 py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
30 {
31     PyObject *return_value = NULL;
32     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
33 
34     #define NUM_KEYWORDS 12
35     static struct {
36         PyGC_Head _this_is_not_used;
37         PyObject_VAR_HEAD
38         PyObject *ob_item[NUM_KEYWORDS];
39     } _kwtuple = {
40         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
41         .ob_item = { &_Py_ID(digest_size), &_Py_ID(key), &_Py_ID(salt), &_Py_ID(person), &_Py_ID(fanout), &_Py_ID(depth), &_Py_ID(leaf_size), &_Py_ID(node_offset), &_Py_ID(node_depth), &_Py_ID(inner_size), &_Py_ID(last_node), &_Py_ID(usedforsecurity), },
42     };
43     #undef NUM_KEYWORDS
44     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
45 
46     #else  // !Py_BUILD_CORE
47     #  define KWTUPLE NULL
48     #endif  // !Py_BUILD_CORE
49 
50     static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", NULL};
51     static _PyArg_Parser _parser = {
52         .keywords = _keywords,
53         .fname = "blake2b",
54         .kwtuple = KWTUPLE,
55     };
56     #undef KWTUPLE
57     PyObject *argsbuf[13];
58     PyObject * const *fastargs;
59     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
60     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
61     PyObject *data = NULL;
62     int digest_size = BLAKE2B_OUTBYTES;
63     Py_buffer key = {NULL, NULL};
64     Py_buffer salt = {NULL, NULL};
65     Py_buffer person = {NULL, NULL};
66     int fanout = 1;
67     int depth = 1;
68     unsigned long leaf_size = 0;
69     unsigned long long node_offset = 0;
70     int node_depth = 0;
71     int inner_size = 0;
72     int last_node = 0;
73     int usedforsecurity = 1;
74 
75     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
76     if (!fastargs) {
77         goto exit;
78     }
79     if (nargs < 1) {
80         goto skip_optional_posonly;
81     }
82     noptargs--;
83     data = fastargs[0];
84 skip_optional_posonly:
85     if (!noptargs) {
86         goto skip_optional_kwonly;
87     }
88     if (fastargs[1]) {
89         digest_size = PyLong_AsInt(fastargs[1]);
90         if (digest_size == -1 && PyErr_Occurred()) {
91             goto exit;
92         }
93         if (!--noptargs) {
94             goto skip_optional_kwonly;
95         }
96     }
97     if (fastargs[2]) {
98         if (PyObject_GetBuffer(fastargs[2], &key, PyBUF_SIMPLE) != 0) {
99             goto exit;
100         }
101         if (!--noptargs) {
102             goto skip_optional_kwonly;
103         }
104     }
105     if (fastargs[3]) {
106         if (PyObject_GetBuffer(fastargs[3], &salt, PyBUF_SIMPLE) != 0) {
107             goto exit;
108         }
109         if (!--noptargs) {
110             goto skip_optional_kwonly;
111         }
112     }
113     if (fastargs[4]) {
114         if (PyObject_GetBuffer(fastargs[4], &person, PyBUF_SIMPLE) != 0) {
115             goto exit;
116         }
117         if (!--noptargs) {
118             goto skip_optional_kwonly;
119         }
120     }
121     if (fastargs[5]) {
122         fanout = PyLong_AsInt(fastargs[5]);
123         if (fanout == -1 && PyErr_Occurred()) {
124             goto exit;
125         }
126         if (!--noptargs) {
127             goto skip_optional_kwonly;
128         }
129     }
130     if (fastargs[6]) {
131         depth = PyLong_AsInt(fastargs[6]);
132         if (depth == -1 && PyErr_Occurred()) {
133             goto exit;
134         }
135         if (!--noptargs) {
136             goto skip_optional_kwonly;
137         }
138     }
139     if (fastargs[7]) {
140         if (!_PyLong_UnsignedLong_Converter(fastargs[7], &leaf_size)) {
141             goto exit;
142         }
143         if (!--noptargs) {
144             goto skip_optional_kwonly;
145         }
146     }
147     if (fastargs[8]) {
148         if (!_PyLong_UnsignedLongLong_Converter(fastargs[8], &node_offset)) {
149             goto exit;
150         }
151         if (!--noptargs) {
152             goto skip_optional_kwonly;
153         }
154     }
155     if (fastargs[9]) {
156         node_depth = PyLong_AsInt(fastargs[9]);
157         if (node_depth == -1 && PyErr_Occurred()) {
158             goto exit;
159         }
160         if (!--noptargs) {
161             goto skip_optional_kwonly;
162         }
163     }
164     if (fastargs[10]) {
165         inner_size = PyLong_AsInt(fastargs[10]);
166         if (inner_size == -1 && PyErr_Occurred()) {
167             goto exit;
168         }
169         if (!--noptargs) {
170             goto skip_optional_kwonly;
171         }
172     }
173     if (fastargs[11]) {
174         last_node = PyObject_IsTrue(fastargs[11]);
175         if (last_node < 0) {
176             goto exit;
177         }
178         if (!--noptargs) {
179             goto skip_optional_kwonly;
180         }
181     }
182     usedforsecurity = PyObject_IsTrue(fastargs[12]);
183     if (usedforsecurity < 0) {
184         goto exit;
185     }
186 skip_optional_kwonly:
187     return_value = py_blake2b_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
188 
189 exit:
190     /* Cleanup for key */
191     if (key.obj) {
192        PyBuffer_Release(&key);
193     }
194     /* Cleanup for salt */
195     if (salt.obj) {
196        PyBuffer_Release(&salt);
197     }
198     /* Cleanup for person */
199     if (person.obj) {
200        PyBuffer_Release(&person);
201     }
202 
203     return return_value;
204 }
205 
206 PyDoc_STRVAR(_blake2_blake2b_copy__doc__,
207 "copy($self, /)\n"
208 "--\n"
209 "\n"
210 "Return a copy of the hash object.");
211 
212 #define _BLAKE2_BLAKE2B_COPY_METHODDEF    \
213     {"copy", (PyCFunction)_blake2_blake2b_copy, METH_NOARGS, _blake2_blake2b_copy__doc__},
214 
215 static PyObject *
216 _blake2_blake2b_copy_impl(BLAKE2bObject *self);
217 
218 static PyObject *
_blake2_blake2b_copy(BLAKE2bObject * self,PyObject * Py_UNUSED (ignored))219 _blake2_blake2b_copy(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
220 {
221     return _blake2_blake2b_copy_impl(self);
222 }
223 
224 PyDoc_STRVAR(_blake2_blake2b_update__doc__,
225 "update($self, data, /)\n"
226 "--\n"
227 "\n"
228 "Update this hash object\'s state with the provided bytes-like object.");
229 
230 #define _BLAKE2_BLAKE2B_UPDATE_METHODDEF    \
231     {"update", (PyCFunction)_blake2_blake2b_update, METH_O, _blake2_blake2b_update__doc__},
232 
233 PyDoc_STRVAR(_blake2_blake2b_digest__doc__,
234 "digest($self, /)\n"
235 "--\n"
236 "\n"
237 "Return the digest value as a bytes object.");
238 
239 #define _BLAKE2_BLAKE2B_DIGEST_METHODDEF    \
240     {"digest", (PyCFunction)_blake2_blake2b_digest, METH_NOARGS, _blake2_blake2b_digest__doc__},
241 
242 static PyObject *
243 _blake2_blake2b_digest_impl(BLAKE2bObject *self);
244 
245 static PyObject *
_blake2_blake2b_digest(BLAKE2bObject * self,PyObject * Py_UNUSED (ignored))246 _blake2_blake2b_digest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
247 {
248     return _blake2_blake2b_digest_impl(self);
249 }
250 
251 PyDoc_STRVAR(_blake2_blake2b_hexdigest__doc__,
252 "hexdigest($self, /)\n"
253 "--\n"
254 "\n"
255 "Return the digest value as a string of hexadecimal digits.");
256 
257 #define _BLAKE2_BLAKE2B_HEXDIGEST_METHODDEF    \
258     {"hexdigest", (PyCFunction)_blake2_blake2b_hexdigest, METH_NOARGS, _blake2_blake2b_hexdigest__doc__},
259 
260 static PyObject *
261 _blake2_blake2b_hexdigest_impl(BLAKE2bObject *self);
262 
263 static PyObject *
_blake2_blake2b_hexdigest(BLAKE2bObject * self,PyObject * Py_UNUSED (ignored))264 _blake2_blake2b_hexdigest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
265 {
266     return _blake2_blake2b_hexdigest_impl(self);
267 }
268 /*[clinic end generated code: output=e18eeaee40623bfc input=a9049054013a1b77]*/
269