Debian Codegraph @

Modules/clinic/blake2module.c.h

raw
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, string=None)\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_obj, 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 PyObject *string);
28
29 static PyObject *
30 py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
31 {
32 PyObject *return_value = NULL;
33 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
34
35 #define NUM_KEYWORDS 14
36 static struct {
37 PyGC_Head _this_is_not_used;
38 PyObject_VAR_HEAD
39 Py_hash_t ob_hash;
40 PyObject *ob_item[NUM_KEYWORDS];
41 } _kwtuple = {
42 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
43 .ob_hash = -1,
44 .ob_item = { &_Py_ID(data), &_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), &_Py_ID(string), },
45 };
46 #undef NUM_KEYWORDS
47 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
48
49 #else // !Py_BUILD_CORE
50 # define KWTUPLE NULL
51 #endif // !Py_BUILD_CORE
52
53 static const char * const _keywords[] = {"data", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", "string", NULL};
54 static _PyArg_Parser _parser = {
55 .keywords = _keywords,
56 .fname = "blake2b",
57 .kwtuple = KWTUPLE,
58 };
59 #undef KWTUPLE
60 PyObject *argsbuf[14];
61 PyObject * const *fastargs;
62 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
63 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
64 PyObject *data_obj = NULL;
65 int digest_size = HACL_HASH_BLAKE2B_OUT_BYTES;
66 Py_buffer key = {.buf = "", .obj = NULL, .len = 0};
67 Py_buffer salt = {.buf = "", .obj = NULL, .len = 0};
68 Py_buffer person = {.buf = "", .obj = NULL, .len = 0};
69 int fanout = 1;
70 int depth = 1;
71 unsigned long leaf_size = 0;
72 unsigned long long node_offset = 0;
73 int node_depth = 0;
74 int inner_size = 0;
75 int last_node = 0;
76 int usedforsecurity = 1;
77 PyObject *string = NULL;
78
79 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
80 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
81 if (!fastargs) {
82 goto exit;
83 }
84 if (!noptargs) {
85 goto skip_optional_pos;
86 }
87 if (fastargs[0]) {
88 data_obj = fastargs[0];
89 if (!--noptargs) {
90 goto skip_optional_pos;
91 }
92 }
93 skip_optional_pos:
94 if (!noptargs) {
95 goto skip_optional_kwonly;
96 }
97 if (fastargs[1]) {
98 digest_size = PyLong_AsInt(fastargs[1]);
99 if (digest_size == -1 && PyErr_Occurred()) {
100 goto exit;
101 }
102 if (!--noptargs) {
103 goto skip_optional_kwonly;
104 }
105 }
106 if (fastargs[2]) {
107 if (PyObject_GetBuffer(fastargs[2], &key, PyBUF_SIMPLE) != 0) {
108 goto exit;
109 }
110 if (!--noptargs) {
111 goto skip_optional_kwonly;
112 }
113 }
114 if (fastargs[3]) {
115 if (PyObject_GetBuffer(fastargs[3], &salt, PyBUF_SIMPLE) != 0) {
116 goto exit;
117 }
118 if (!--noptargs) {
119 goto skip_optional_kwonly;
120 }
121 }
122 if (fastargs[4]) {
123 if (PyObject_GetBuffer(fastargs[4], &person, PyBUF_SIMPLE) != 0) {
124 goto exit;
125 }
126 if (!--noptargs) {
127 goto skip_optional_kwonly;
128 }
129 }
130 if (fastargs[5]) {
131 fanout = PyLong_AsInt(fastargs[5]);
132 if (fanout == -1 && PyErr_Occurred()) {
133 goto exit;
134 }
135 if (!--noptargs) {
136 goto skip_optional_kwonly;
137 }
138 }
139 if (fastargs[6]) {
140 depth = PyLong_AsInt(fastargs[6]);
141 if (depth == -1 && PyErr_Occurred()) {
142 goto exit;
143 }
144 if (!--noptargs) {
145 goto skip_optional_kwonly;
146 }
147 }
148 if (fastargs[7]) {
149 if (!_PyLong_UnsignedLong_Converter(fastargs[7], &leaf_size)) {
150 goto exit;
151 }
152 if (!--noptargs) {
153 goto skip_optional_kwonly;
154 }
155 }
156 if (fastargs[8]) {
157 if (!_PyLong_UnsignedLongLong_Converter(fastargs[8], &node_offset)) {
158 goto exit;
159 }
160 if (!--noptargs) {
161 goto skip_optional_kwonly;
162 }
163 }
164 if (fastargs[9]) {
165 node_depth = PyLong_AsInt(fastargs[9]);
166 if (node_depth == -1 && PyErr_Occurred()) {
167 goto exit;
168 }
169 if (!--noptargs) {
170 goto skip_optional_kwonly;
171 }
172 }
173 if (fastargs[10]) {
174 inner_size = PyLong_AsInt(fastargs[10]);
175 if (inner_size == -1 && PyErr_Occurred()) {
176 goto exit;
177 }
178 if (!--noptargs) {
179 goto skip_optional_kwonly;
180 }
181 }
182 if (fastargs[11]) {
183 last_node = PyObject_IsTrue(fastargs[11]);
184 if (last_node < 0) {
185 goto exit;
186 }
187 if (!--noptargs) {
188 goto skip_optional_kwonly;
189 }
190 }
191 if (fastargs[12]) {
192 usedforsecurity = PyObject_IsTrue(fastargs[12]);
193 if (usedforsecurity < 0) {
194 goto exit;
195 }
196 if (!--noptargs) {
197 goto skip_optional_kwonly;
198 }
199 }
200 string = fastargs[13];
201 skip_optional_kwonly:
202 return_value = py_blake2b_new_impl(type, data_obj, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity, string);
203
204 exit:
205 /* Cleanup for key */
206 if (key.obj) {
207 PyBuffer_Release(&key);
208 }
209 /* Cleanup for salt */
210 if (salt.obj) {
211 PyBuffer_Release(&salt);
212 }
213 /* Cleanup for person */
214 if (person.obj) {
215 PyBuffer_Release(&person);
216 }
217
218 return return_value;
219 }
220
221 PyDoc_STRVAR(py_blake2s_new__doc__,
222 "blake2s(data=b\'\', *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
223 " key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
224 " node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
225 " usedforsecurity=True, string=None)\n"
226 "--\n"
227 "\n"
228 "Return a new BLAKE2s hash object.");
229
230 static PyObject *
231 py_blake2s_new_impl(PyTypeObject *type, PyObject *data_obj, int digest_size,
232 Py_buffer *key, Py_buffer *salt, Py_buffer *person,
233 int fanout, int depth, unsigned long leaf_size,
234 unsigned long long node_offset, int node_depth,
235 int inner_size, int last_node, int usedforsecurity,
236 PyObject *string);
237
238 static PyObject *
239 py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
240 {
241 PyObject *return_value = NULL;
242 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
243
244 #define NUM_KEYWORDS 14
245 static struct {
246 PyGC_Head _this_is_not_used;
247 PyObject_VAR_HEAD
248 Py_hash_t ob_hash;
249 PyObject *ob_item[NUM_KEYWORDS];
250 } _kwtuple = {
251 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
252 .ob_hash = -1,
253 .ob_item = { &_Py_ID(data), &_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), &_Py_ID(string), },
254 };
255 #undef NUM_KEYWORDS
256 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
257
258 #else // !Py_BUILD_CORE
259 # define KWTUPLE NULL
260 #endif // !Py_BUILD_CORE
261
262 static const char * const _keywords[] = {"data", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", "string", NULL};
263 static _PyArg_Parser _parser = {
264 .keywords = _keywords,
265 .fname = "blake2s",
266 .kwtuple = KWTUPLE,
267 };
268 #undef KWTUPLE
269 PyObject *argsbuf[14];
270 PyObject * const *fastargs;
271 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
272 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
273 PyObject *data_obj = NULL;
274 int digest_size = HACL_HASH_BLAKE2S_OUT_BYTES;
275 Py_buffer key = {.buf = "", .obj = NULL, .len = 0};
276 Py_buffer salt = {.buf = "", .obj = NULL, .len = 0};
277 Py_buffer person = {.buf = "", .obj = NULL, .len = 0};
278 int fanout = 1;
279 int depth = 1;
280 unsigned long leaf_size = 0;
281 unsigned long long node_offset = 0;
282 int node_depth = 0;
283 int inner_size = 0;
284 int last_node = 0;
285 int usedforsecurity = 1;
286 PyObject *string = NULL;
287
288 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
289 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
290 if (!fastargs) {
291 goto exit;
292 }
293 if (!noptargs) {
294 goto skip_optional_pos;
295 }
296 if (fastargs[0]) {
297 data_obj = fastargs[0];
298 if (!--noptargs) {
299 goto skip_optional_pos;
300 }
301 }
302 skip_optional_pos:
303 if (!noptargs) {
304 goto skip_optional_kwonly;
305 }
306 if (fastargs[1]) {
307 digest_size = PyLong_AsInt(fastargs[1]);
308 if (digest_size == -1 && PyErr_Occurred()) {
309 goto exit;
310 }
311 if (!--noptargs) {
312 goto skip_optional_kwonly;
313 }
314 }
315 if (fastargs[2]) {
316 if (PyObject_GetBuffer(fastargs[2], &key, PyBUF_SIMPLE) != 0) {
317 goto exit;
318 }
319 if (!--noptargs) {
320 goto skip_optional_kwonly;
321 }
322 }
323 if (fastargs[3]) {
324 if (PyObject_GetBuffer(fastargs[3], &salt, PyBUF_SIMPLE) != 0) {
325 goto exit;
326 }
327 if (!--noptargs) {
328 goto skip_optional_kwonly;
329 }
330 }
331 if (fastargs[4]) {
332 if (PyObject_GetBuffer(fastargs[4], &person, PyBUF_SIMPLE) != 0) {
333 goto exit;
334 }
335 if (!--noptargs) {
336 goto skip_optional_kwonly;
337 }
338 }
339 if (fastargs[5]) {
340 fanout = PyLong_AsInt(fastargs[5]);
341 if (fanout == -1 && PyErr_Occurred()) {
342 goto exit;
343 }
344 if (!--noptargs) {
345 goto skip_optional_kwonly;
346 }
347 }
348 if (fastargs[6]) {
349 depth = PyLong_AsInt(fastargs[6]);
350 if (depth == -1 && PyErr_Occurred()) {
351 goto exit;
352 }
353 if (!--noptargs) {
354 goto skip_optional_kwonly;
355 }
356 }
357 if (fastargs[7]) {
358 if (!_PyLong_UnsignedLong_Converter(fastargs[7], &leaf_size)) {
359 goto exit;
360 }
361 if (!--noptargs) {
362 goto skip_optional_kwonly;
363 }
364 }
365 if (fastargs[8]) {
366 if (!_PyLong_UnsignedLongLong_Converter(fastargs[8], &node_offset)) {
367 goto exit;
368 }
369 if (!--noptargs) {
370 goto skip_optional_kwonly;
371 }
372 }
373 if (fastargs[9]) {
374 node_depth = PyLong_AsInt(fastargs[9]);
375 if (node_depth == -1 && PyErr_Occurred()) {
376 goto exit;
377 }
378 if (!--noptargs) {
379 goto skip_optional_kwonly;
380 }
381 }
382 if (fastargs[10]) {
383 inner_size = PyLong_AsInt(fastargs[10]);
384 if (inner_size == -1 && PyErr_Occurred()) {
385 goto exit;
386 }
387 if (!--noptargs) {
388 goto skip_optional_kwonly;
389 }
390 }
391 if (fastargs[11]) {
392 last_node = PyObject_IsTrue(fastargs[11]);
393 if (last_node < 0) {
394 goto exit;
395 }
396 if (!--noptargs) {
397 goto skip_optional_kwonly;
398 }
399 }
400 if (fastargs[12]) {
401 usedforsecurity = PyObject_IsTrue(fastargs[12]);
402 if (usedforsecurity < 0) {
403 goto exit;
404 }
405 if (!--noptargs) {
406 goto skip_optional_kwonly;
407 }
408 }
409 string = fastargs[13];
410 skip_optional_kwonly:
411 return_value = py_blake2s_new_impl(type, data_obj, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity, string);
412
413 exit:
414 /* Cleanup for key */
415 if (key.obj) {
416 PyBuffer_Release(&key);
417 }
418 /* Cleanup for salt */
419 if (salt.obj) {
420 PyBuffer_Release(&salt);
421 }
422 /* Cleanup for person */
423 if (person.obj) {
424 PyBuffer_Release(&person);
425 }
426
427 return return_value;
428 }
429
430 PyDoc_STRVAR(_blake2_blake2b_copy__doc__,
431 "copy($self, /)\n"
432 "--\n"
433 "\n"
434 "Return a copy of the hash object.");
435
436 #define _BLAKE2_BLAKE2B_COPY_METHODDEF \
437 {"copy", (PyCFunction)_blake2_blake2b_copy, METH_NOARGS, _blake2_blake2b_copy__doc__},
438
439 static PyObject *
440 _blake2_blake2b_copy_impl(Blake2Object *self);
441
442 static PyObject *
443 _blake2_blake2b_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
444 {
445 return _blake2_blake2b_copy_impl((Blake2Object *)self);
446 }
447
448 PyDoc_STRVAR(_blake2_blake2b_update__doc__,
449 "update($self, data, /)\n"
450 "--\n"
451 "\n"
452 "Update this hash object\'s state with the provided bytes-like object.");
453
454 #define _BLAKE2_BLAKE2B_UPDATE_METHODDEF \
455 {"update", (PyCFunction)_blake2_blake2b_update, METH_O, _blake2_blake2b_update__doc__},
456
457 static PyObject *
458 _blake2_blake2b_update_impl(Blake2Object *self, PyObject *data);
459
460 static PyObject *
461 _blake2_blake2b_update(PyObject *self, PyObject *data)
462 {
463 PyObject *return_value = NULL;
464
465 return_value = _blake2_blake2b_update_impl((Blake2Object *)self, data);
466
467 return return_value;
468 }
469
470 PyDoc_STRVAR(_blake2_blake2b_digest__doc__,
471 "digest($self, /)\n"
472 "--\n"
473 "\n"
474 "Return the digest value as a bytes object.");
475
476 #define _BLAKE2_BLAKE2B_DIGEST_METHODDEF \
477 {"digest", (PyCFunction)_blake2_blake2b_digest, METH_NOARGS, _blake2_blake2b_digest__doc__},
478
479 static PyObject *
480 _blake2_blake2b_digest_impl(Blake2Object *self);
481
482 static PyObject *
483 _blake2_blake2b_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
484 {
485 return _blake2_blake2b_digest_impl((Blake2Object *)self);
486 }
487
488 PyDoc_STRVAR(_blake2_blake2b_hexdigest__doc__,
489 "hexdigest($self, /)\n"
490 "--\n"
491 "\n"
492 "Return the digest value as a string of hexadecimal digits.");
493
494 #define _BLAKE2_BLAKE2B_HEXDIGEST_METHODDEF \
495 {"hexdigest", (PyCFunction)_blake2_blake2b_hexdigest, METH_NOARGS, _blake2_blake2b_hexdigest__doc__},
496
497 static PyObject *
498 _blake2_blake2b_hexdigest_impl(Blake2Object *self);
499
500 static PyObject *
501 _blake2_blake2b_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
502 {
503 return _blake2_blake2b_hexdigest_impl((Blake2Object *)self);
504 }
505 /*[clinic end generated code: output=bf30e70c312718cb input=a9049054013a1b77]*/