Branch data Line data Source code
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 : :
10 : :
11 : : PyDoc_STRVAR(EVP_copy__doc__,
12 : : "copy($self, /)\n"
13 : : "--\n"
14 : : "\n"
15 : : "Return a copy of the hash object.");
16 : :
17 : : #define EVP_COPY_METHODDEF \
18 : : {"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__},
19 : :
20 : : static PyObject *
21 : : EVP_copy_impl(EVPobject *self);
22 : :
23 : : static PyObject *
24 : 0 : EVP_copy(EVPobject *self, PyObject *Py_UNUSED(ignored))
25 : : {
26 : 0 : return EVP_copy_impl(self);
27 : : }
28 : :
29 : : PyDoc_STRVAR(EVP_digest__doc__,
30 : : "digest($self, /)\n"
31 : : "--\n"
32 : : "\n"
33 : : "Return the digest value as a bytes object.");
34 : :
35 : : #define EVP_DIGEST_METHODDEF \
36 : : {"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__},
37 : :
38 : : static PyObject *
39 : : EVP_digest_impl(EVPobject *self);
40 : :
41 : : static PyObject *
42 : 0 : EVP_digest(EVPobject *self, PyObject *Py_UNUSED(ignored))
43 : : {
44 : 0 : return EVP_digest_impl(self);
45 : : }
46 : :
47 : : PyDoc_STRVAR(EVP_hexdigest__doc__,
48 : : "hexdigest($self, /)\n"
49 : : "--\n"
50 : : "\n"
51 : : "Return the digest value as a string of hexadecimal digits.");
52 : :
53 : : #define EVP_HEXDIGEST_METHODDEF \
54 : : {"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, EVP_hexdigest__doc__},
55 : :
56 : : static PyObject *
57 : : EVP_hexdigest_impl(EVPobject *self);
58 : :
59 : : static PyObject *
60 : 0 : EVP_hexdigest(EVPobject *self, PyObject *Py_UNUSED(ignored))
61 : : {
62 : 0 : return EVP_hexdigest_impl(self);
63 : : }
64 : :
65 : : PyDoc_STRVAR(EVP_update__doc__,
66 : : "update($self, obj, /)\n"
67 : : "--\n"
68 : : "\n"
69 : : "Update this hash object\'s state with the provided string.");
70 : :
71 : : #define EVP_UPDATE_METHODDEF \
72 : : {"update", (PyCFunction)EVP_update, METH_O, EVP_update__doc__},
73 : :
74 : : #if defined(PY_OPENSSL_HAS_SHAKE)
75 : :
76 : : PyDoc_STRVAR(EVPXOF_digest__doc__,
77 : : "digest($self, /, length)\n"
78 : : "--\n"
79 : : "\n"
80 : : "Return the digest value as a bytes object.");
81 : :
82 : : #define EVPXOF_DIGEST_METHODDEF \
83 : : {"digest", _PyCFunction_CAST(EVPXOF_digest), METH_FASTCALL|METH_KEYWORDS, EVPXOF_digest__doc__},
84 : :
85 : : static PyObject *
86 : : EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length);
87 : :
88 : : static PyObject *
89 : 0 : EVPXOF_digest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
90 : : {
91 : 0 : PyObject *return_value = NULL;
92 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
93 : :
94 : : #define NUM_KEYWORDS 1
95 : : static struct {
96 : : PyGC_Head _this_is_not_used;
97 : : PyObject_VAR_HEAD
98 : : PyObject *ob_item[NUM_KEYWORDS];
99 : : } _kwtuple = {
100 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
101 : : .ob_item = { &_Py_ID(length), },
102 : : };
103 : : #undef NUM_KEYWORDS
104 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
105 : :
106 : : #else // !Py_BUILD_CORE
107 : : # define KWTUPLE NULL
108 : : #endif // !Py_BUILD_CORE
109 : :
110 : : static const char * const _keywords[] = {"length", NULL};
111 : : static _PyArg_Parser _parser = {
112 : : .keywords = _keywords,
113 : : .fname = "digest",
114 : : .kwtuple = KWTUPLE,
115 : : };
116 : : #undef KWTUPLE
117 : : PyObject *argsbuf[1];
118 : : Py_ssize_t length;
119 : :
120 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
121 [ # # ]: 0 : if (!args) {
122 : 0 : goto exit;
123 : : }
124 : : {
125 : 0 : Py_ssize_t ival = -1;
126 : 0 : PyObject *iobj = _PyNumber_Index(args[0]);
127 [ # # ]: 0 : if (iobj != NULL) {
128 : 0 : ival = PyLong_AsSsize_t(iobj);
129 : 0 : Py_DECREF(iobj);
130 : : }
131 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
132 : 0 : goto exit;
133 : : }
134 : 0 : length = ival;
135 : : }
136 : 0 : return_value = EVPXOF_digest_impl(self, length);
137 : :
138 : 0 : exit:
139 : 0 : return return_value;
140 : : }
141 : :
142 : : #endif /* defined(PY_OPENSSL_HAS_SHAKE) */
143 : :
144 : : #if defined(PY_OPENSSL_HAS_SHAKE)
145 : :
146 : : PyDoc_STRVAR(EVPXOF_hexdigest__doc__,
147 : : "hexdigest($self, /, length)\n"
148 : : "--\n"
149 : : "\n"
150 : : "Return the digest value as a string of hexadecimal digits.");
151 : :
152 : : #define EVPXOF_HEXDIGEST_METHODDEF \
153 : : {"hexdigest", _PyCFunction_CAST(EVPXOF_hexdigest), METH_FASTCALL|METH_KEYWORDS, EVPXOF_hexdigest__doc__},
154 : :
155 : : static PyObject *
156 : : EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length);
157 : :
158 : : static PyObject *
159 : 0 : EVPXOF_hexdigest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
160 : : {
161 : 0 : PyObject *return_value = NULL;
162 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
163 : :
164 : : #define NUM_KEYWORDS 1
165 : : static struct {
166 : : PyGC_Head _this_is_not_used;
167 : : PyObject_VAR_HEAD
168 : : PyObject *ob_item[NUM_KEYWORDS];
169 : : } _kwtuple = {
170 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
171 : : .ob_item = { &_Py_ID(length), },
172 : : };
173 : : #undef NUM_KEYWORDS
174 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
175 : :
176 : : #else // !Py_BUILD_CORE
177 : : # define KWTUPLE NULL
178 : : #endif // !Py_BUILD_CORE
179 : :
180 : : static const char * const _keywords[] = {"length", NULL};
181 : : static _PyArg_Parser _parser = {
182 : : .keywords = _keywords,
183 : : .fname = "hexdigest",
184 : : .kwtuple = KWTUPLE,
185 : : };
186 : : #undef KWTUPLE
187 : : PyObject *argsbuf[1];
188 : : Py_ssize_t length;
189 : :
190 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
191 [ # # ]: 0 : if (!args) {
192 : 0 : goto exit;
193 : : }
194 : : {
195 : 0 : Py_ssize_t ival = -1;
196 : 0 : PyObject *iobj = _PyNumber_Index(args[0]);
197 [ # # ]: 0 : if (iobj != NULL) {
198 : 0 : ival = PyLong_AsSsize_t(iobj);
199 : 0 : Py_DECREF(iobj);
200 : : }
201 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
202 : 0 : goto exit;
203 : : }
204 : 0 : length = ival;
205 : : }
206 : 0 : return_value = EVPXOF_hexdigest_impl(self, length);
207 : :
208 : 0 : exit:
209 : 0 : return return_value;
210 : : }
211 : :
212 : : #endif /* defined(PY_OPENSSL_HAS_SHAKE) */
213 : :
214 : : PyDoc_STRVAR(EVP_new__doc__,
215 : : "new($module, /, name, string=b\'\', *, usedforsecurity=True)\n"
216 : : "--\n"
217 : : "\n"
218 : : "Return a new hash object using the named algorithm.\n"
219 : : "\n"
220 : : "An optional string argument may be provided and will be\n"
221 : : "automatically hashed.\n"
222 : : "\n"
223 : : "The MD5 and SHA1 algorithms are always supported.");
224 : :
225 : : #define EVP_NEW_METHODDEF \
226 : : {"new", _PyCFunction_CAST(EVP_new), METH_FASTCALL|METH_KEYWORDS, EVP_new__doc__},
227 : :
228 : : static PyObject *
229 : : EVP_new_impl(PyObject *module, PyObject *name_obj, PyObject *data_obj,
230 : : int usedforsecurity);
231 : :
232 : : static PyObject *
233 : 0 : EVP_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
234 : : {
235 : 0 : PyObject *return_value = NULL;
236 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
237 : :
238 : : #define NUM_KEYWORDS 3
239 : : static struct {
240 : : PyGC_Head _this_is_not_used;
241 : : PyObject_VAR_HEAD
242 : : PyObject *ob_item[NUM_KEYWORDS];
243 : : } _kwtuple = {
244 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
245 : : .ob_item = { &_Py_ID(name), &_Py_ID(string), &_Py_ID(usedforsecurity), },
246 : : };
247 : : #undef NUM_KEYWORDS
248 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
249 : :
250 : : #else // !Py_BUILD_CORE
251 : : # define KWTUPLE NULL
252 : : #endif // !Py_BUILD_CORE
253 : :
254 : : static const char * const _keywords[] = {"name", "string", "usedforsecurity", NULL};
255 : : static _PyArg_Parser _parser = {
256 : : .keywords = _keywords,
257 : : .fname = "new",
258 : : .kwtuple = KWTUPLE,
259 : : };
260 : : #undef KWTUPLE
261 : : PyObject *argsbuf[3];
262 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
263 : : PyObject *name_obj;
264 : 0 : PyObject *data_obj = NULL;
265 : 0 : int usedforsecurity = 1;
266 : :
267 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
268 [ # # ]: 0 : if (!args) {
269 : 0 : goto exit;
270 : : }
271 : 0 : name_obj = args[0];
272 [ # # ]: 0 : if (!noptargs) {
273 : 0 : goto skip_optional_pos;
274 : : }
275 [ # # ]: 0 : if (args[1]) {
276 : 0 : data_obj = args[1];
277 [ # # ]: 0 : if (!--noptargs) {
278 : 0 : goto skip_optional_pos;
279 : : }
280 : : }
281 : 0 : skip_optional_pos:
282 [ # # ]: 0 : if (!noptargs) {
283 : 0 : goto skip_optional_kwonly;
284 : : }
285 : 0 : usedforsecurity = PyObject_IsTrue(args[2]);
286 [ # # ]: 0 : if (usedforsecurity < 0) {
287 : 0 : goto exit;
288 : : }
289 : 0 : skip_optional_kwonly:
290 : 0 : return_value = EVP_new_impl(module, name_obj, data_obj, usedforsecurity);
291 : :
292 : 0 : exit:
293 : 0 : return return_value;
294 : : }
295 : :
296 : : PyDoc_STRVAR(_hashlib_openssl_md5__doc__,
297 : : "openssl_md5($module, /, string=b\'\', *, usedforsecurity=True)\n"
298 : : "--\n"
299 : : "\n"
300 : : "Returns a md5 hash object; optionally initialized with a string");
301 : :
302 : : #define _HASHLIB_OPENSSL_MD5_METHODDEF \
303 : : {"openssl_md5", _PyCFunction_CAST(_hashlib_openssl_md5), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_md5__doc__},
304 : :
305 : : static PyObject *
306 : : _hashlib_openssl_md5_impl(PyObject *module, PyObject *data_obj,
307 : : int usedforsecurity);
308 : :
309 : : static PyObject *
310 : 1 : _hashlib_openssl_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
311 : : {
312 : 1 : PyObject *return_value = NULL;
313 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
314 : :
315 : : #define NUM_KEYWORDS 2
316 : : static struct {
317 : : PyGC_Head _this_is_not_used;
318 : : PyObject_VAR_HEAD
319 : : PyObject *ob_item[NUM_KEYWORDS];
320 : : } _kwtuple = {
321 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
322 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
323 : : };
324 : : #undef NUM_KEYWORDS
325 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
326 : :
327 : : #else // !Py_BUILD_CORE
328 : : # define KWTUPLE NULL
329 : : #endif // !Py_BUILD_CORE
330 : :
331 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
332 : : static _PyArg_Parser _parser = {
333 : : .keywords = _keywords,
334 : : .fname = "openssl_md5",
335 : : .kwtuple = KWTUPLE,
336 : : };
337 : : #undef KWTUPLE
338 : : PyObject *argsbuf[2];
339 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
340 : 1 : PyObject *data_obj = NULL;
341 : 1 : int usedforsecurity = 1;
342 : :
343 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
344 [ - + ]: 1 : if (!args) {
345 : 0 : goto exit;
346 : : }
347 [ - + ]: 1 : if (!noptargs) {
348 : 0 : goto skip_optional_pos;
349 : : }
350 [ + - ]: 1 : if (args[0]) {
351 : 0 : data_obj = args[0];
352 [ # # ]: 0 : if (!--noptargs) {
353 : 0 : goto skip_optional_pos;
354 : : }
355 : : }
356 : 1 : skip_optional_pos:
357 [ - + ]: 1 : if (!noptargs) {
358 : 0 : goto skip_optional_kwonly;
359 : : }
360 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
361 [ - + ]: 1 : if (usedforsecurity < 0) {
362 : 0 : goto exit;
363 : : }
364 : 1 : skip_optional_kwonly:
365 : 1 : return_value = _hashlib_openssl_md5_impl(module, data_obj, usedforsecurity);
366 : :
367 : 1 : exit:
368 : 1 : return return_value;
369 : : }
370 : :
371 : : PyDoc_STRVAR(_hashlib_openssl_sha1__doc__,
372 : : "openssl_sha1($module, /, string=b\'\', *, usedforsecurity=True)\n"
373 : : "--\n"
374 : : "\n"
375 : : "Returns a sha1 hash object; optionally initialized with a string");
376 : :
377 : : #define _HASHLIB_OPENSSL_SHA1_METHODDEF \
378 : : {"openssl_sha1", _PyCFunction_CAST(_hashlib_openssl_sha1), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha1__doc__},
379 : :
380 : : static PyObject *
381 : : _hashlib_openssl_sha1_impl(PyObject *module, PyObject *data_obj,
382 : : int usedforsecurity);
383 : :
384 : : static PyObject *
385 : 1 : _hashlib_openssl_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
386 : : {
387 : 1 : PyObject *return_value = NULL;
388 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
389 : :
390 : : #define NUM_KEYWORDS 2
391 : : static struct {
392 : : PyGC_Head _this_is_not_used;
393 : : PyObject_VAR_HEAD
394 : : PyObject *ob_item[NUM_KEYWORDS];
395 : : } _kwtuple = {
396 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
397 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
398 : : };
399 : : #undef NUM_KEYWORDS
400 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
401 : :
402 : : #else // !Py_BUILD_CORE
403 : : # define KWTUPLE NULL
404 : : #endif // !Py_BUILD_CORE
405 : :
406 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
407 : : static _PyArg_Parser _parser = {
408 : : .keywords = _keywords,
409 : : .fname = "openssl_sha1",
410 : : .kwtuple = KWTUPLE,
411 : : };
412 : : #undef KWTUPLE
413 : : PyObject *argsbuf[2];
414 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
415 : 1 : PyObject *data_obj = NULL;
416 : 1 : int usedforsecurity = 1;
417 : :
418 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
419 [ - + ]: 1 : if (!args) {
420 : 0 : goto exit;
421 : : }
422 [ - + ]: 1 : if (!noptargs) {
423 : 0 : goto skip_optional_pos;
424 : : }
425 [ + - ]: 1 : if (args[0]) {
426 : 0 : data_obj = args[0];
427 [ # # ]: 0 : if (!--noptargs) {
428 : 0 : goto skip_optional_pos;
429 : : }
430 : : }
431 : 1 : skip_optional_pos:
432 [ - + ]: 1 : if (!noptargs) {
433 : 0 : goto skip_optional_kwonly;
434 : : }
435 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
436 [ - + ]: 1 : if (usedforsecurity < 0) {
437 : 0 : goto exit;
438 : : }
439 : 1 : skip_optional_kwonly:
440 : 1 : return_value = _hashlib_openssl_sha1_impl(module, data_obj, usedforsecurity);
441 : :
442 : 1 : exit:
443 : 1 : return return_value;
444 : : }
445 : :
446 : : PyDoc_STRVAR(_hashlib_openssl_sha224__doc__,
447 : : "openssl_sha224($module, /, string=b\'\', *, usedforsecurity=True)\n"
448 : : "--\n"
449 : : "\n"
450 : : "Returns a sha224 hash object; optionally initialized with a string");
451 : :
452 : : #define _HASHLIB_OPENSSL_SHA224_METHODDEF \
453 : : {"openssl_sha224", _PyCFunction_CAST(_hashlib_openssl_sha224), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha224__doc__},
454 : :
455 : : static PyObject *
456 : : _hashlib_openssl_sha224_impl(PyObject *module, PyObject *data_obj,
457 : : int usedforsecurity);
458 : :
459 : : static PyObject *
460 : 1 : _hashlib_openssl_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461 : : {
462 : 1 : PyObject *return_value = NULL;
463 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
464 : :
465 : : #define NUM_KEYWORDS 2
466 : : static struct {
467 : : PyGC_Head _this_is_not_used;
468 : : PyObject_VAR_HEAD
469 : : PyObject *ob_item[NUM_KEYWORDS];
470 : : } _kwtuple = {
471 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
472 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
473 : : };
474 : : #undef NUM_KEYWORDS
475 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
476 : :
477 : : #else // !Py_BUILD_CORE
478 : : # define KWTUPLE NULL
479 : : #endif // !Py_BUILD_CORE
480 : :
481 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
482 : : static _PyArg_Parser _parser = {
483 : : .keywords = _keywords,
484 : : .fname = "openssl_sha224",
485 : : .kwtuple = KWTUPLE,
486 : : };
487 : : #undef KWTUPLE
488 : : PyObject *argsbuf[2];
489 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
490 : 1 : PyObject *data_obj = NULL;
491 : 1 : int usedforsecurity = 1;
492 : :
493 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
494 [ - + ]: 1 : if (!args) {
495 : 0 : goto exit;
496 : : }
497 [ - + ]: 1 : if (!noptargs) {
498 : 0 : goto skip_optional_pos;
499 : : }
500 [ + - ]: 1 : if (args[0]) {
501 : 0 : data_obj = args[0];
502 [ # # ]: 0 : if (!--noptargs) {
503 : 0 : goto skip_optional_pos;
504 : : }
505 : : }
506 : 1 : skip_optional_pos:
507 [ - + ]: 1 : if (!noptargs) {
508 : 0 : goto skip_optional_kwonly;
509 : : }
510 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
511 [ - + ]: 1 : if (usedforsecurity < 0) {
512 : 0 : goto exit;
513 : : }
514 : 1 : skip_optional_kwonly:
515 : 1 : return_value = _hashlib_openssl_sha224_impl(module, data_obj, usedforsecurity);
516 : :
517 : 1 : exit:
518 : 1 : return return_value;
519 : : }
520 : :
521 : : PyDoc_STRVAR(_hashlib_openssl_sha256__doc__,
522 : : "openssl_sha256($module, /, string=b\'\', *, usedforsecurity=True)\n"
523 : : "--\n"
524 : : "\n"
525 : : "Returns a sha256 hash object; optionally initialized with a string");
526 : :
527 : : #define _HASHLIB_OPENSSL_SHA256_METHODDEF \
528 : : {"openssl_sha256", _PyCFunction_CAST(_hashlib_openssl_sha256), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha256__doc__},
529 : :
530 : : static PyObject *
531 : : _hashlib_openssl_sha256_impl(PyObject *module, PyObject *data_obj,
532 : : int usedforsecurity);
533 : :
534 : : static PyObject *
535 : 1 : _hashlib_openssl_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
536 : : {
537 : 1 : PyObject *return_value = NULL;
538 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
539 : :
540 : : #define NUM_KEYWORDS 2
541 : : static struct {
542 : : PyGC_Head _this_is_not_used;
543 : : PyObject_VAR_HEAD
544 : : PyObject *ob_item[NUM_KEYWORDS];
545 : : } _kwtuple = {
546 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
547 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
548 : : };
549 : : #undef NUM_KEYWORDS
550 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
551 : :
552 : : #else // !Py_BUILD_CORE
553 : : # define KWTUPLE NULL
554 : : #endif // !Py_BUILD_CORE
555 : :
556 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
557 : : static _PyArg_Parser _parser = {
558 : : .keywords = _keywords,
559 : : .fname = "openssl_sha256",
560 : : .kwtuple = KWTUPLE,
561 : : };
562 : : #undef KWTUPLE
563 : : PyObject *argsbuf[2];
564 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
565 : 1 : PyObject *data_obj = NULL;
566 : 1 : int usedforsecurity = 1;
567 : :
568 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
569 [ - + ]: 1 : if (!args) {
570 : 0 : goto exit;
571 : : }
572 [ - + ]: 1 : if (!noptargs) {
573 : 0 : goto skip_optional_pos;
574 : : }
575 [ + - ]: 1 : if (args[0]) {
576 : 0 : data_obj = args[0];
577 [ # # ]: 0 : if (!--noptargs) {
578 : 0 : goto skip_optional_pos;
579 : : }
580 : : }
581 : 1 : skip_optional_pos:
582 [ - + ]: 1 : if (!noptargs) {
583 : 0 : goto skip_optional_kwonly;
584 : : }
585 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
586 [ - + ]: 1 : if (usedforsecurity < 0) {
587 : 0 : goto exit;
588 : : }
589 : 1 : skip_optional_kwonly:
590 : 1 : return_value = _hashlib_openssl_sha256_impl(module, data_obj, usedforsecurity);
591 : :
592 : 1 : exit:
593 : 1 : return return_value;
594 : : }
595 : :
596 : : PyDoc_STRVAR(_hashlib_openssl_sha384__doc__,
597 : : "openssl_sha384($module, /, string=b\'\', *, usedforsecurity=True)\n"
598 : : "--\n"
599 : : "\n"
600 : : "Returns a sha384 hash object; optionally initialized with a string");
601 : :
602 : : #define _HASHLIB_OPENSSL_SHA384_METHODDEF \
603 : : {"openssl_sha384", _PyCFunction_CAST(_hashlib_openssl_sha384), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha384__doc__},
604 : :
605 : : static PyObject *
606 : : _hashlib_openssl_sha384_impl(PyObject *module, PyObject *data_obj,
607 : : int usedforsecurity);
608 : :
609 : : static PyObject *
610 : 1 : _hashlib_openssl_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
611 : : {
612 : 1 : PyObject *return_value = NULL;
613 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
614 : :
615 : : #define NUM_KEYWORDS 2
616 : : static struct {
617 : : PyGC_Head _this_is_not_used;
618 : : PyObject_VAR_HEAD
619 : : PyObject *ob_item[NUM_KEYWORDS];
620 : : } _kwtuple = {
621 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
622 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
623 : : };
624 : : #undef NUM_KEYWORDS
625 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
626 : :
627 : : #else // !Py_BUILD_CORE
628 : : # define KWTUPLE NULL
629 : : #endif // !Py_BUILD_CORE
630 : :
631 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
632 : : static _PyArg_Parser _parser = {
633 : : .keywords = _keywords,
634 : : .fname = "openssl_sha384",
635 : : .kwtuple = KWTUPLE,
636 : : };
637 : : #undef KWTUPLE
638 : : PyObject *argsbuf[2];
639 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
640 : 1 : PyObject *data_obj = NULL;
641 : 1 : int usedforsecurity = 1;
642 : :
643 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
644 [ - + ]: 1 : if (!args) {
645 : 0 : goto exit;
646 : : }
647 [ - + ]: 1 : if (!noptargs) {
648 : 0 : goto skip_optional_pos;
649 : : }
650 [ + - ]: 1 : if (args[0]) {
651 : 0 : data_obj = args[0];
652 [ # # ]: 0 : if (!--noptargs) {
653 : 0 : goto skip_optional_pos;
654 : : }
655 : : }
656 : 1 : skip_optional_pos:
657 [ - + ]: 1 : if (!noptargs) {
658 : 0 : goto skip_optional_kwonly;
659 : : }
660 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
661 [ - + ]: 1 : if (usedforsecurity < 0) {
662 : 0 : goto exit;
663 : : }
664 : 1 : skip_optional_kwonly:
665 : 1 : return_value = _hashlib_openssl_sha384_impl(module, data_obj, usedforsecurity);
666 : :
667 : 1 : exit:
668 : 1 : return return_value;
669 : : }
670 : :
671 : : PyDoc_STRVAR(_hashlib_openssl_sha512__doc__,
672 : : "openssl_sha512($module, /, string=b\'\', *, usedforsecurity=True)\n"
673 : : "--\n"
674 : : "\n"
675 : : "Returns a sha512 hash object; optionally initialized with a string");
676 : :
677 : : #define _HASHLIB_OPENSSL_SHA512_METHODDEF \
678 : : {"openssl_sha512", _PyCFunction_CAST(_hashlib_openssl_sha512), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha512__doc__},
679 : :
680 : : static PyObject *
681 : : _hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj,
682 : : int usedforsecurity);
683 : :
684 : : static PyObject *
685 : 1 : _hashlib_openssl_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
686 : : {
687 : 1 : PyObject *return_value = NULL;
688 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
689 : :
690 : : #define NUM_KEYWORDS 2
691 : : static struct {
692 : : PyGC_Head _this_is_not_used;
693 : : PyObject_VAR_HEAD
694 : : PyObject *ob_item[NUM_KEYWORDS];
695 : : } _kwtuple = {
696 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
697 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
698 : : };
699 : : #undef NUM_KEYWORDS
700 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
701 : :
702 : : #else // !Py_BUILD_CORE
703 : : # define KWTUPLE NULL
704 : : #endif // !Py_BUILD_CORE
705 : :
706 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
707 : : static _PyArg_Parser _parser = {
708 : : .keywords = _keywords,
709 : : .fname = "openssl_sha512",
710 : : .kwtuple = KWTUPLE,
711 : : };
712 : : #undef KWTUPLE
713 : : PyObject *argsbuf[2];
714 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
715 : 1 : PyObject *data_obj = NULL;
716 : 1 : int usedforsecurity = 1;
717 : :
718 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
719 [ - + ]: 1 : if (!args) {
720 : 0 : goto exit;
721 : : }
722 [ - + ]: 1 : if (!noptargs) {
723 : 0 : goto skip_optional_pos;
724 : : }
725 [ + - ]: 1 : if (args[0]) {
726 : 0 : data_obj = args[0];
727 [ # # ]: 0 : if (!--noptargs) {
728 : 0 : goto skip_optional_pos;
729 : : }
730 : : }
731 : 1 : skip_optional_pos:
732 [ - + ]: 1 : if (!noptargs) {
733 : 0 : goto skip_optional_kwonly;
734 : : }
735 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
736 [ - + ]: 1 : if (usedforsecurity < 0) {
737 : 0 : goto exit;
738 : : }
739 : 1 : skip_optional_kwonly:
740 : 1 : return_value = _hashlib_openssl_sha512_impl(module, data_obj, usedforsecurity);
741 : :
742 : 1 : exit:
743 : 1 : return return_value;
744 : : }
745 : :
746 : : #if defined(PY_OPENSSL_HAS_SHA3)
747 : :
748 : : PyDoc_STRVAR(_hashlib_openssl_sha3_224__doc__,
749 : : "openssl_sha3_224($module, /, string=b\'\', *, usedforsecurity=True)\n"
750 : : "--\n"
751 : : "\n"
752 : : "Returns a sha3-224 hash object; optionally initialized with a string");
753 : :
754 : : #define _HASHLIB_OPENSSL_SHA3_224_METHODDEF \
755 : : {"openssl_sha3_224", _PyCFunction_CAST(_hashlib_openssl_sha3_224), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha3_224__doc__},
756 : :
757 : : static PyObject *
758 : : _hashlib_openssl_sha3_224_impl(PyObject *module, PyObject *data_obj,
759 : : int usedforsecurity);
760 : :
761 : : static PyObject *
762 : 1 : _hashlib_openssl_sha3_224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
763 : : {
764 : 1 : PyObject *return_value = NULL;
765 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
766 : :
767 : : #define NUM_KEYWORDS 2
768 : : static struct {
769 : : PyGC_Head _this_is_not_used;
770 : : PyObject_VAR_HEAD
771 : : PyObject *ob_item[NUM_KEYWORDS];
772 : : } _kwtuple = {
773 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
774 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
775 : : };
776 : : #undef NUM_KEYWORDS
777 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
778 : :
779 : : #else // !Py_BUILD_CORE
780 : : # define KWTUPLE NULL
781 : : #endif // !Py_BUILD_CORE
782 : :
783 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
784 : : static _PyArg_Parser _parser = {
785 : : .keywords = _keywords,
786 : : .fname = "openssl_sha3_224",
787 : : .kwtuple = KWTUPLE,
788 : : };
789 : : #undef KWTUPLE
790 : : PyObject *argsbuf[2];
791 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
792 : 1 : PyObject *data_obj = NULL;
793 : 1 : int usedforsecurity = 1;
794 : :
795 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
796 [ - + ]: 1 : if (!args) {
797 : 0 : goto exit;
798 : : }
799 [ - + ]: 1 : if (!noptargs) {
800 : 0 : goto skip_optional_pos;
801 : : }
802 [ + - ]: 1 : if (args[0]) {
803 : 0 : data_obj = args[0];
804 [ # # ]: 0 : if (!--noptargs) {
805 : 0 : goto skip_optional_pos;
806 : : }
807 : : }
808 : 1 : skip_optional_pos:
809 [ - + ]: 1 : if (!noptargs) {
810 : 0 : goto skip_optional_kwonly;
811 : : }
812 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
813 [ - + ]: 1 : if (usedforsecurity < 0) {
814 : 0 : goto exit;
815 : : }
816 : 1 : skip_optional_kwonly:
817 : 1 : return_value = _hashlib_openssl_sha3_224_impl(module, data_obj, usedforsecurity);
818 : :
819 : 1 : exit:
820 : 1 : return return_value;
821 : : }
822 : :
823 : : #endif /* defined(PY_OPENSSL_HAS_SHA3) */
824 : :
825 : : #if defined(PY_OPENSSL_HAS_SHA3)
826 : :
827 : : PyDoc_STRVAR(_hashlib_openssl_sha3_256__doc__,
828 : : "openssl_sha3_256($module, /, string=b\'\', *, usedforsecurity=True)\n"
829 : : "--\n"
830 : : "\n"
831 : : "Returns a sha3-256 hash object; optionally initialized with a string");
832 : :
833 : : #define _HASHLIB_OPENSSL_SHA3_256_METHODDEF \
834 : : {"openssl_sha3_256", _PyCFunction_CAST(_hashlib_openssl_sha3_256), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha3_256__doc__},
835 : :
836 : : static PyObject *
837 : : _hashlib_openssl_sha3_256_impl(PyObject *module, PyObject *data_obj,
838 : : int usedforsecurity);
839 : :
840 : : static PyObject *
841 : 1 : _hashlib_openssl_sha3_256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
842 : : {
843 : 1 : PyObject *return_value = NULL;
844 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
845 : :
846 : : #define NUM_KEYWORDS 2
847 : : static struct {
848 : : PyGC_Head _this_is_not_used;
849 : : PyObject_VAR_HEAD
850 : : PyObject *ob_item[NUM_KEYWORDS];
851 : : } _kwtuple = {
852 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
853 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
854 : : };
855 : : #undef NUM_KEYWORDS
856 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
857 : :
858 : : #else // !Py_BUILD_CORE
859 : : # define KWTUPLE NULL
860 : : #endif // !Py_BUILD_CORE
861 : :
862 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
863 : : static _PyArg_Parser _parser = {
864 : : .keywords = _keywords,
865 : : .fname = "openssl_sha3_256",
866 : : .kwtuple = KWTUPLE,
867 : : };
868 : : #undef KWTUPLE
869 : : PyObject *argsbuf[2];
870 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
871 : 1 : PyObject *data_obj = NULL;
872 : 1 : int usedforsecurity = 1;
873 : :
874 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
875 [ - + ]: 1 : if (!args) {
876 : 0 : goto exit;
877 : : }
878 [ - + ]: 1 : if (!noptargs) {
879 : 0 : goto skip_optional_pos;
880 : : }
881 [ + - ]: 1 : if (args[0]) {
882 : 0 : data_obj = args[0];
883 [ # # ]: 0 : if (!--noptargs) {
884 : 0 : goto skip_optional_pos;
885 : : }
886 : : }
887 : 1 : skip_optional_pos:
888 [ - + ]: 1 : if (!noptargs) {
889 : 0 : goto skip_optional_kwonly;
890 : : }
891 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
892 [ - + ]: 1 : if (usedforsecurity < 0) {
893 : 0 : goto exit;
894 : : }
895 : 1 : skip_optional_kwonly:
896 : 1 : return_value = _hashlib_openssl_sha3_256_impl(module, data_obj, usedforsecurity);
897 : :
898 : 1 : exit:
899 : 1 : return return_value;
900 : : }
901 : :
902 : : #endif /* defined(PY_OPENSSL_HAS_SHA3) */
903 : :
904 : : #if defined(PY_OPENSSL_HAS_SHA3)
905 : :
906 : : PyDoc_STRVAR(_hashlib_openssl_sha3_384__doc__,
907 : : "openssl_sha3_384($module, /, string=b\'\', *, usedforsecurity=True)\n"
908 : : "--\n"
909 : : "\n"
910 : : "Returns a sha3-384 hash object; optionally initialized with a string");
911 : :
912 : : #define _HASHLIB_OPENSSL_SHA3_384_METHODDEF \
913 : : {"openssl_sha3_384", _PyCFunction_CAST(_hashlib_openssl_sha3_384), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha3_384__doc__},
914 : :
915 : : static PyObject *
916 : : _hashlib_openssl_sha3_384_impl(PyObject *module, PyObject *data_obj,
917 : : int usedforsecurity);
918 : :
919 : : static PyObject *
920 : 1 : _hashlib_openssl_sha3_384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
921 : : {
922 : 1 : PyObject *return_value = NULL;
923 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
924 : :
925 : : #define NUM_KEYWORDS 2
926 : : static struct {
927 : : PyGC_Head _this_is_not_used;
928 : : PyObject_VAR_HEAD
929 : : PyObject *ob_item[NUM_KEYWORDS];
930 : : } _kwtuple = {
931 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
932 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
933 : : };
934 : : #undef NUM_KEYWORDS
935 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
936 : :
937 : : #else // !Py_BUILD_CORE
938 : : # define KWTUPLE NULL
939 : : #endif // !Py_BUILD_CORE
940 : :
941 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
942 : : static _PyArg_Parser _parser = {
943 : : .keywords = _keywords,
944 : : .fname = "openssl_sha3_384",
945 : : .kwtuple = KWTUPLE,
946 : : };
947 : : #undef KWTUPLE
948 : : PyObject *argsbuf[2];
949 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
950 : 1 : PyObject *data_obj = NULL;
951 : 1 : int usedforsecurity = 1;
952 : :
953 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
954 [ - + ]: 1 : if (!args) {
955 : 0 : goto exit;
956 : : }
957 [ - + ]: 1 : if (!noptargs) {
958 : 0 : goto skip_optional_pos;
959 : : }
960 [ + - ]: 1 : if (args[0]) {
961 : 0 : data_obj = args[0];
962 [ # # ]: 0 : if (!--noptargs) {
963 : 0 : goto skip_optional_pos;
964 : : }
965 : : }
966 : 1 : skip_optional_pos:
967 [ - + ]: 1 : if (!noptargs) {
968 : 0 : goto skip_optional_kwonly;
969 : : }
970 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
971 [ - + ]: 1 : if (usedforsecurity < 0) {
972 : 0 : goto exit;
973 : : }
974 : 1 : skip_optional_kwonly:
975 : 1 : return_value = _hashlib_openssl_sha3_384_impl(module, data_obj, usedforsecurity);
976 : :
977 : 1 : exit:
978 : 1 : return return_value;
979 : : }
980 : :
981 : : #endif /* defined(PY_OPENSSL_HAS_SHA3) */
982 : :
983 : : #if defined(PY_OPENSSL_HAS_SHA3)
984 : :
985 : : PyDoc_STRVAR(_hashlib_openssl_sha3_512__doc__,
986 : : "openssl_sha3_512($module, /, string=b\'\', *, usedforsecurity=True)\n"
987 : : "--\n"
988 : : "\n"
989 : : "Returns a sha3-512 hash object; optionally initialized with a string");
990 : :
991 : : #define _HASHLIB_OPENSSL_SHA3_512_METHODDEF \
992 : : {"openssl_sha3_512", _PyCFunction_CAST(_hashlib_openssl_sha3_512), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha3_512__doc__},
993 : :
994 : : static PyObject *
995 : : _hashlib_openssl_sha3_512_impl(PyObject *module, PyObject *data_obj,
996 : : int usedforsecurity);
997 : :
998 : : static PyObject *
999 : 1 : _hashlib_openssl_sha3_512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1000 : : {
1001 : 1 : PyObject *return_value = NULL;
1002 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1003 : :
1004 : : #define NUM_KEYWORDS 2
1005 : : static struct {
1006 : : PyGC_Head _this_is_not_used;
1007 : : PyObject_VAR_HEAD
1008 : : PyObject *ob_item[NUM_KEYWORDS];
1009 : : } _kwtuple = {
1010 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1011 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
1012 : : };
1013 : : #undef NUM_KEYWORDS
1014 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1015 : :
1016 : : #else // !Py_BUILD_CORE
1017 : : # define KWTUPLE NULL
1018 : : #endif // !Py_BUILD_CORE
1019 : :
1020 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
1021 : : static _PyArg_Parser _parser = {
1022 : : .keywords = _keywords,
1023 : : .fname = "openssl_sha3_512",
1024 : : .kwtuple = KWTUPLE,
1025 : : };
1026 : : #undef KWTUPLE
1027 : : PyObject *argsbuf[2];
1028 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1029 : 1 : PyObject *data_obj = NULL;
1030 : 1 : int usedforsecurity = 1;
1031 : :
1032 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
1033 [ - + ]: 1 : if (!args) {
1034 : 0 : goto exit;
1035 : : }
1036 [ - + ]: 1 : if (!noptargs) {
1037 : 0 : goto skip_optional_pos;
1038 : : }
1039 [ + - ]: 1 : if (args[0]) {
1040 : 0 : data_obj = args[0];
1041 [ # # ]: 0 : if (!--noptargs) {
1042 : 0 : goto skip_optional_pos;
1043 : : }
1044 : : }
1045 : 1 : skip_optional_pos:
1046 [ - + ]: 1 : if (!noptargs) {
1047 : 0 : goto skip_optional_kwonly;
1048 : : }
1049 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
1050 [ - + ]: 1 : if (usedforsecurity < 0) {
1051 : 0 : goto exit;
1052 : : }
1053 : 1 : skip_optional_kwonly:
1054 : 1 : return_value = _hashlib_openssl_sha3_512_impl(module, data_obj, usedforsecurity);
1055 : :
1056 : 1 : exit:
1057 : 1 : return return_value;
1058 : : }
1059 : :
1060 : : #endif /* defined(PY_OPENSSL_HAS_SHA3) */
1061 : :
1062 : : #if defined(PY_OPENSSL_HAS_SHAKE)
1063 : :
1064 : : PyDoc_STRVAR(_hashlib_openssl_shake_128__doc__,
1065 : : "openssl_shake_128($module, /, string=b\'\', *, usedforsecurity=True)\n"
1066 : : "--\n"
1067 : : "\n"
1068 : : "Returns a shake-128 variable hash object; optionally initialized with a string");
1069 : :
1070 : : #define _HASHLIB_OPENSSL_SHAKE_128_METHODDEF \
1071 : : {"openssl_shake_128", _PyCFunction_CAST(_hashlib_openssl_shake_128), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_shake_128__doc__},
1072 : :
1073 : : static PyObject *
1074 : : _hashlib_openssl_shake_128_impl(PyObject *module, PyObject *data_obj,
1075 : : int usedforsecurity);
1076 : :
1077 : : static PyObject *
1078 : 1 : _hashlib_openssl_shake_128(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1079 : : {
1080 : 1 : PyObject *return_value = NULL;
1081 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1082 : :
1083 : : #define NUM_KEYWORDS 2
1084 : : static struct {
1085 : : PyGC_Head _this_is_not_used;
1086 : : PyObject_VAR_HEAD
1087 : : PyObject *ob_item[NUM_KEYWORDS];
1088 : : } _kwtuple = {
1089 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1090 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
1091 : : };
1092 : : #undef NUM_KEYWORDS
1093 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1094 : :
1095 : : #else // !Py_BUILD_CORE
1096 : : # define KWTUPLE NULL
1097 : : #endif // !Py_BUILD_CORE
1098 : :
1099 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
1100 : : static _PyArg_Parser _parser = {
1101 : : .keywords = _keywords,
1102 : : .fname = "openssl_shake_128",
1103 : : .kwtuple = KWTUPLE,
1104 : : };
1105 : : #undef KWTUPLE
1106 : : PyObject *argsbuf[2];
1107 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1108 : 1 : PyObject *data_obj = NULL;
1109 : 1 : int usedforsecurity = 1;
1110 : :
1111 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
1112 [ - + ]: 1 : if (!args) {
1113 : 0 : goto exit;
1114 : : }
1115 [ - + ]: 1 : if (!noptargs) {
1116 : 0 : goto skip_optional_pos;
1117 : : }
1118 [ + - ]: 1 : if (args[0]) {
1119 : 0 : data_obj = args[0];
1120 [ # # ]: 0 : if (!--noptargs) {
1121 : 0 : goto skip_optional_pos;
1122 : : }
1123 : : }
1124 : 1 : skip_optional_pos:
1125 [ - + ]: 1 : if (!noptargs) {
1126 : 0 : goto skip_optional_kwonly;
1127 : : }
1128 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
1129 [ - + ]: 1 : if (usedforsecurity < 0) {
1130 : 0 : goto exit;
1131 : : }
1132 : 1 : skip_optional_kwonly:
1133 : 1 : return_value = _hashlib_openssl_shake_128_impl(module, data_obj, usedforsecurity);
1134 : :
1135 : 1 : exit:
1136 : 1 : return return_value;
1137 : : }
1138 : :
1139 : : #endif /* defined(PY_OPENSSL_HAS_SHAKE) */
1140 : :
1141 : : #if defined(PY_OPENSSL_HAS_SHAKE)
1142 : :
1143 : : PyDoc_STRVAR(_hashlib_openssl_shake_256__doc__,
1144 : : "openssl_shake_256($module, /, string=b\'\', *, usedforsecurity=True)\n"
1145 : : "--\n"
1146 : : "\n"
1147 : : "Returns a shake-256 variable hash object; optionally initialized with a string");
1148 : :
1149 : : #define _HASHLIB_OPENSSL_SHAKE_256_METHODDEF \
1150 : : {"openssl_shake_256", _PyCFunction_CAST(_hashlib_openssl_shake_256), METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_shake_256__doc__},
1151 : :
1152 : : static PyObject *
1153 : : _hashlib_openssl_shake_256_impl(PyObject *module, PyObject *data_obj,
1154 : : int usedforsecurity);
1155 : :
1156 : : static PyObject *
1157 : 1 : _hashlib_openssl_shake_256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1158 : : {
1159 : 1 : PyObject *return_value = NULL;
1160 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1161 : :
1162 : : #define NUM_KEYWORDS 2
1163 : : static struct {
1164 : : PyGC_Head _this_is_not_used;
1165 : : PyObject_VAR_HEAD
1166 : : PyObject *ob_item[NUM_KEYWORDS];
1167 : : } _kwtuple = {
1168 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1169 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
1170 : : };
1171 : : #undef NUM_KEYWORDS
1172 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1173 : :
1174 : : #else // !Py_BUILD_CORE
1175 : : # define KWTUPLE NULL
1176 : : #endif // !Py_BUILD_CORE
1177 : :
1178 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
1179 : : static _PyArg_Parser _parser = {
1180 : : .keywords = _keywords,
1181 : : .fname = "openssl_shake_256",
1182 : : .kwtuple = KWTUPLE,
1183 : : };
1184 : : #undef KWTUPLE
1185 : : PyObject *argsbuf[2];
1186 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1187 : 1 : PyObject *data_obj = NULL;
1188 : 1 : int usedforsecurity = 1;
1189 : :
1190 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- - - - ]
1191 [ - + ]: 1 : if (!args) {
1192 : 0 : goto exit;
1193 : : }
1194 [ - + ]: 1 : if (!noptargs) {
1195 : 0 : goto skip_optional_pos;
1196 : : }
1197 [ + - ]: 1 : if (args[0]) {
1198 : 0 : data_obj = args[0];
1199 [ # # ]: 0 : if (!--noptargs) {
1200 : 0 : goto skip_optional_pos;
1201 : : }
1202 : : }
1203 : 1 : skip_optional_pos:
1204 [ - + ]: 1 : if (!noptargs) {
1205 : 0 : goto skip_optional_kwonly;
1206 : : }
1207 : 1 : usedforsecurity = PyObject_IsTrue(args[1]);
1208 [ - + ]: 1 : if (usedforsecurity < 0) {
1209 : 0 : goto exit;
1210 : : }
1211 : 1 : skip_optional_kwonly:
1212 : 1 : return_value = _hashlib_openssl_shake_256_impl(module, data_obj, usedforsecurity);
1213 : :
1214 : 1 : exit:
1215 : 1 : return return_value;
1216 : : }
1217 : :
1218 : : #endif /* defined(PY_OPENSSL_HAS_SHAKE) */
1219 : :
1220 : : PyDoc_STRVAR(pbkdf2_hmac__doc__,
1221 : : "pbkdf2_hmac($module, /, hash_name, password, salt, iterations,\n"
1222 : : " dklen=None)\n"
1223 : : "--\n"
1224 : : "\n"
1225 : : "Password based key derivation function 2 (PKCS #5 v2.0) with HMAC as pseudorandom function.");
1226 : :
1227 : : #define PBKDF2_HMAC_METHODDEF \
1228 : : {"pbkdf2_hmac", _PyCFunction_CAST(pbkdf2_hmac), METH_FASTCALL|METH_KEYWORDS, pbkdf2_hmac__doc__},
1229 : :
1230 : : static PyObject *
1231 : : pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
1232 : : Py_buffer *password, Py_buffer *salt, long iterations,
1233 : : PyObject *dklen_obj);
1234 : :
1235 : : static PyObject *
1236 : 0 : pbkdf2_hmac(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1237 : : {
1238 : 0 : PyObject *return_value = NULL;
1239 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1240 : :
1241 : : #define NUM_KEYWORDS 5
1242 : : static struct {
1243 : : PyGC_Head _this_is_not_used;
1244 : : PyObject_VAR_HEAD
1245 : : PyObject *ob_item[NUM_KEYWORDS];
1246 : : } _kwtuple = {
1247 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1248 : : .ob_item = { &_Py_ID(hash_name), &_Py_ID(password), &_Py_ID(salt), &_Py_ID(iterations), &_Py_ID(dklen), },
1249 : : };
1250 : : #undef NUM_KEYWORDS
1251 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1252 : :
1253 : : #else // !Py_BUILD_CORE
1254 : : # define KWTUPLE NULL
1255 : : #endif // !Py_BUILD_CORE
1256 : :
1257 : : static const char * const _keywords[] = {"hash_name", "password", "salt", "iterations", "dklen", NULL};
1258 : : static _PyArg_Parser _parser = {
1259 : : .keywords = _keywords,
1260 : : .fname = "pbkdf2_hmac",
1261 : : .kwtuple = KWTUPLE,
1262 : : };
1263 : : #undef KWTUPLE
1264 : : PyObject *argsbuf[5];
1265 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
1266 : : const char *hash_name;
1267 : 0 : Py_buffer password = {NULL, NULL};
1268 : 0 : Py_buffer salt = {NULL, NULL};
1269 : : long iterations;
1270 : 0 : PyObject *dklen_obj = Py_None;
1271 : :
1272 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 5, 0, argsbuf);
# # # # ]
1273 [ # # ]: 0 : if (!args) {
1274 : 0 : goto exit;
1275 : : }
1276 [ # # ]: 0 : if (!PyUnicode_Check(args[0])) {
1277 : 0 : _PyArg_BadArgument("pbkdf2_hmac", "argument 'hash_name'", "str", args[0]);
1278 : 0 : goto exit;
1279 : : }
1280 : : Py_ssize_t hash_name_length;
1281 : 0 : hash_name = PyUnicode_AsUTF8AndSize(args[0], &hash_name_length);
1282 [ # # ]: 0 : if (hash_name == NULL) {
1283 : 0 : goto exit;
1284 : : }
1285 [ # # ]: 0 : if (strlen(hash_name) != (size_t)hash_name_length) {
1286 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
1287 : 0 : goto exit;
1288 : : }
1289 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &password, PyBUF_SIMPLE) != 0) {
1290 : 0 : goto exit;
1291 : : }
1292 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&password, 'C')) {
1293 : 0 : _PyArg_BadArgument("pbkdf2_hmac", "argument 'password'", "contiguous buffer", args[1]);
1294 : 0 : goto exit;
1295 : : }
1296 [ # # ]: 0 : if (PyObject_GetBuffer(args[2], &salt, PyBUF_SIMPLE) != 0) {
1297 : 0 : goto exit;
1298 : : }
1299 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&salt, 'C')) {
1300 : 0 : _PyArg_BadArgument("pbkdf2_hmac", "argument 'salt'", "contiguous buffer", args[2]);
1301 : 0 : goto exit;
1302 : : }
1303 : 0 : iterations = PyLong_AsLong(args[3]);
1304 [ # # # # ]: 0 : if (iterations == -1 && PyErr_Occurred()) {
1305 : 0 : goto exit;
1306 : : }
1307 [ # # ]: 0 : if (!noptargs) {
1308 : 0 : goto skip_optional_pos;
1309 : : }
1310 : 0 : dklen_obj = args[4];
1311 : 0 : skip_optional_pos:
1312 : 0 : return_value = pbkdf2_hmac_impl(module, hash_name, &password, &salt, iterations, dklen_obj);
1313 : :
1314 : 0 : exit:
1315 : : /* Cleanup for password */
1316 [ # # ]: 0 : if (password.obj) {
1317 : 0 : PyBuffer_Release(&password);
1318 : : }
1319 : : /* Cleanup for salt */
1320 [ # # ]: 0 : if (salt.obj) {
1321 : 0 : PyBuffer_Release(&salt);
1322 : : }
1323 : :
1324 : 0 : return return_value;
1325 : : }
1326 : :
1327 : : #if defined(PY_OPENSSL_HAS_SCRYPT)
1328 : :
1329 : : PyDoc_STRVAR(_hashlib_scrypt__doc__,
1330 : : "scrypt($module, /, password, *, salt=None, n=None, r=None, p=None,\n"
1331 : : " maxmem=0, dklen=64)\n"
1332 : : "--\n"
1333 : : "\n"
1334 : : "scrypt password-based key derivation function.");
1335 : :
1336 : : #define _HASHLIB_SCRYPT_METHODDEF \
1337 : : {"scrypt", _PyCFunction_CAST(_hashlib_scrypt), METH_FASTCALL|METH_KEYWORDS, _hashlib_scrypt__doc__},
1338 : :
1339 : : static PyObject *
1340 : : _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
1341 : : PyObject *n_obj, PyObject *r_obj, PyObject *p_obj,
1342 : : long maxmem, long dklen);
1343 : :
1344 : : static PyObject *
1345 : 0 : _hashlib_scrypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1346 : : {
1347 : 0 : PyObject *return_value = NULL;
1348 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1349 : :
1350 : : #define NUM_KEYWORDS 7
1351 : : static struct {
1352 : : PyGC_Head _this_is_not_used;
1353 : : PyObject_VAR_HEAD
1354 : : PyObject *ob_item[NUM_KEYWORDS];
1355 : : } _kwtuple = {
1356 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1357 : : .ob_item = { &_Py_ID(password), &_Py_ID(salt), &_Py_ID(n), &_Py_ID(r), &_Py_ID(p), &_Py_ID(maxmem), &_Py_ID(dklen), },
1358 : : };
1359 : : #undef NUM_KEYWORDS
1360 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1361 : :
1362 : : #else // !Py_BUILD_CORE
1363 : : # define KWTUPLE NULL
1364 : : #endif // !Py_BUILD_CORE
1365 : :
1366 : : static const char * const _keywords[] = {"password", "salt", "n", "r", "p", "maxmem", "dklen", NULL};
1367 : : static _PyArg_Parser _parser = {
1368 : : .keywords = _keywords,
1369 : : .fname = "scrypt",
1370 : : .kwtuple = KWTUPLE,
1371 : : };
1372 : : #undef KWTUPLE
1373 : : PyObject *argsbuf[7];
1374 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1375 : 0 : Py_buffer password = {NULL, NULL};
1376 : 0 : Py_buffer salt = {NULL, NULL};
1377 : 0 : PyObject *n_obj = Py_None;
1378 : 0 : PyObject *r_obj = Py_None;
1379 : 0 : PyObject *p_obj = Py_None;
1380 : 0 : long maxmem = 0;
1381 : 0 : long dklen = 64;
1382 : :
1383 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1384 [ # # ]: 0 : if (!args) {
1385 : 0 : goto exit;
1386 : : }
1387 [ # # ]: 0 : if (PyObject_GetBuffer(args[0], &password, PyBUF_SIMPLE) != 0) {
1388 : 0 : goto exit;
1389 : : }
1390 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&password, 'C')) {
1391 : 0 : _PyArg_BadArgument("scrypt", "argument 'password'", "contiguous buffer", args[0]);
1392 : 0 : goto exit;
1393 : : }
1394 [ # # ]: 0 : if (!noptargs) {
1395 : 0 : goto skip_optional_kwonly;
1396 : : }
1397 [ # # ]: 0 : if (args[1]) {
1398 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &salt, PyBUF_SIMPLE) != 0) {
1399 : 0 : goto exit;
1400 : : }
1401 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&salt, 'C')) {
1402 : 0 : _PyArg_BadArgument("scrypt", "argument 'salt'", "contiguous buffer", args[1]);
1403 : 0 : goto exit;
1404 : : }
1405 [ # # ]: 0 : if (!--noptargs) {
1406 : 0 : goto skip_optional_kwonly;
1407 : : }
1408 : : }
1409 [ # # ]: 0 : if (args[2]) {
1410 [ # # ]: 0 : if (!PyLong_Check(args[2])) {
1411 : 0 : _PyArg_BadArgument("scrypt", "argument 'n'", "int", args[2]);
1412 : 0 : goto exit;
1413 : : }
1414 : 0 : n_obj = args[2];
1415 [ # # ]: 0 : if (!--noptargs) {
1416 : 0 : goto skip_optional_kwonly;
1417 : : }
1418 : : }
1419 [ # # ]: 0 : if (args[3]) {
1420 [ # # ]: 0 : if (!PyLong_Check(args[3])) {
1421 : 0 : _PyArg_BadArgument("scrypt", "argument 'r'", "int", args[3]);
1422 : 0 : goto exit;
1423 : : }
1424 : 0 : r_obj = args[3];
1425 [ # # ]: 0 : if (!--noptargs) {
1426 : 0 : goto skip_optional_kwonly;
1427 : : }
1428 : : }
1429 [ # # ]: 0 : if (args[4]) {
1430 [ # # ]: 0 : if (!PyLong_Check(args[4])) {
1431 : 0 : _PyArg_BadArgument("scrypt", "argument 'p'", "int", args[4]);
1432 : 0 : goto exit;
1433 : : }
1434 : 0 : p_obj = args[4];
1435 [ # # ]: 0 : if (!--noptargs) {
1436 : 0 : goto skip_optional_kwonly;
1437 : : }
1438 : : }
1439 [ # # ]: 0 : if (args[5]) {
1440 : 0 : maxmem = PyLong_AsLong(args[5]);
1441 [ # # # # ]: 0 : if (maxmem == -1 && PyErr_Occurred()) {
1442 : 0 : goto exit;
1443 : : }
1444 [ # # ]: 0 : if (!--noptargs) {
1445 : 0 : goto skip_optional_kwonly;
1446 : : }
1447 : : }
1448 : 0 : dklen = PyLong_AsLong(args[6]);
1449 [ # # # # ]: 0 : if (dklen == -1 && PyErr_Occurred()) {
1450 : 0 : goto exit;
1451 : : }
1452 : 0 : skip_optional_kwonly:
1453 : 0 : return_value = _hashlib_scrypt_impl(module, &password, &salt, n_obj, r_obj, p_obj, maxmem, dklen);
1454 : :
1455 : 0 : exit:
1456 : : /* Cleanup for password */
1457 [ # # ]: 0 : if (password.obj) {
1458 : 0 : PyBuffer_Release(&password);
1459 : : }
1460 : : /* Cleanup for salt */
1461 [ # # ]: 0 : if (salt.obj) {
1462 : 0 : PyBuffer_Release(&salt);
1463 : : }
1464 : :
1465 : 0 : return return_value;
1466 : : }
1467 : :
1468 : : #endif /* defined(PY_OPENSSL_HAS_SCRYPT) */
1469 : :
1470 : : PyDoc_STRVAR(_hashlib_hmac_singleshot__doc__,
1471 : : "hmac_digest($module, /, key, msg, digest)\n"
1472 : : "--\n"
1473 : : "\n"
1474 : : "Single-shot HMAC.");
1475 : :
1476 : : #define _HASHLIB_HMAC_SINGLESHOT_METHODDEF \
1477 : : {"hmac_digest", _PyCFunction_CAST(_hashlib_hmac_singleshot), METH_FASTCALL|METH_KEYWORDS, _hashlib_hmac_singleshot__doc__},
1478 : :
1479 : : static PyObject *
1480 : : _hashlib_hmac_singleshot_impl(PyObject *module, Py_buffer *key,
1481 : : Py_buffer *msg, PyObject *digest);
1482 : :
1483 : : static PyObject *
1484 : 0 : _hashlib_hmac_singleshot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1485 : : {
1486 : 0 : PyObject *return_value = NULL;
1487 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1488 : :
1489 : : #define NUM_KEYWORDS 3
1490 : : static struct {
1491 : : PyGC_Head _this_is_not_used;
1492 : : PyObject_VAR_HEAD
1493 : : PyObject *ob_item[NUM_KEYWORDS];
1494 : : } _kwtuple = {
1495 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1496 : : .ob_item = { &_Py_ID(key), &_Py_ID(msg), &_Py_ID(digest), },
1497 : : };
1498 : : #undef NUM_KEYWORDS
1499 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1500 : :
1501 : : #else // !Py_BUILD_CORE
1502 : : # define KWTUPLE NULL
1503 : : #endif // !Py_BUILD_CORE
1504 : :
1505 : : static const char * const _keywords[] = {"key", "msg", "digest", NULL};
1506 : : static _PyArg_Parser _parser = {
1507 : : .keywords = _keywords,
1508 : : .fname = "hmac_digest",
1509 : : .kwtuple = KWTUPLE,
1510 : : };
1511 : : #undef KWTUPLE
1512 : : PyObject *argsbuf[3];
1513 : 0 : Py_buffer key = {NULL, NULL};
1514 : 0 : Py_buffer msg = {NULL, NULL};
1515 : : PyObject *digest;
1516 : :
1517 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
1518 [ # # ]: 0 : if (!args) {
1519 : 0 : goto exit;
1520 : : }
1521 [ # # ]: 0 : if (PyObject_GetBuffer(args[0], &key, PyBUF_SIMPLE) != 0) {
1522 : 0 : goto exit;
1523 : : }
1524 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&key, 'C')) {
1525 : 0 : _PyArg_BadArgument("hmac_digest", "argument 'key'", "contiguous buffer", args[0]);
1526 : 0 : goto exit;
1527 : : }
1528 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &msg, PyBUF_SIMPLE) != 0) {
1529 : 0 : goto exit;
1530 : : }
1531 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&msg, 'C')) {
1532 : 0 : _PyArg_BadArgument("hmac_digest", "argument 'msg'", "contiguous buffer", args[1]);
1533 : 0 : goto exit;
1534 : : }
1535 : 0 : digest = args[2];
1536 : 0 : return_value = _hashlib_hmac_singleshot_impl(module, &key, &msg, digest);
1537 : :
1538 : 0 : exit:
1539 : : /* Cleanup for key */
1540 [ # # ]: 0 : if (key.obj) {
1541 : 0 : PyBuffer_Release(&key);
1542 : : }
1543 : : /* Cleanup for msg */
1544 [ # # ]: 0 : if (msg.obj) {
1545 : 0 : PyBuffer_Release(&msg);
1546 : : }
1547 : :
1548 : 0 : return return_value;
1549 : : }
1550 : :
1551 : : PyDoc_STRVAR(_hashlib_hmac_new__doc__,
1552 : : "hmac_new($module, /, key, msg=b\'\', digestmod=None)\n"
1553 : : "--\n"
1554 : : "\n"
1555 : : "Return a new hmac object.");
1556 : :
1557 : : #define _HASHLIB_HMAC_NEW_METHODDEF \
1558 : : {"hmac_new", _PyCFunction_CAST(_hashlib_hmac_new), METH_FASTCALL|METH_KEYWORDS, _hashlib_hmac_new__doc__},
1559 : :
1560 : : static PyObject *
1561 : : _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
1562 : : PyObject *digestmod);
1563 : :
1564 : : static PyObject *
1565 : 0 : _hashlib_hmac_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1566 : : {
1567 : 0 : PyObject *return_value = NULL;
1568 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1569 : :
1570 : : #define NUM_KEYWORDS 3
1571 : : static struct {
1572 : : PyGC_Head _this_is_not_used;
1573 : : PyObject_VAR_HEAD
1574 : : PyObject *ob_item[NUM_KEYWORDS];
1575 : : } _kwtuple = {
1576 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1577 : : .ob_item = { &_Py_ID(key), &_Py_ID(msg), &_Py_ID(digestmod), },
1578 : : };
1579 : : #undef NUM_KEYWORDS
1580 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1581 : :
1582 : : #else // !Py_BUILD_CORE
1583 : : # define KWTUPLE NULL
1584 : : #endif // !Py_BUILD_CORE
1585 : :
1586 : : static const char * const _keywords[] = {"key", "msg", "digestmod", NULL};
1587 : : static _PyArg_Parser _parser = {
1588 : : .keywords = _keywords,
1589 : : .fname = "hmac_new",
1590 : : .kwtuple = KWTUPLE,
1591 : : };
1592 : : #undef KWTUPLE
1593 : : PyObject *argsbuf[3];
1594 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1595 : 0 : Py_buffer key = {NULL, NULL};
1596 : 0 : PyObject *msg_obj = NULL;
1597 : 0 : PyObject *digestmod = NULL;
1598 : :
1599 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
# # # # ]
1600 [ # # ]: 0 : if (!args) {
1601 : 0 : goto exit;
1602 : : }
1603 [ # # ]: 0 : if (PyObject_GetBuffer(args[0], &key, PyBUF_SIMPLE) != 0) {
1604 : 0 : goto exit;
1605 : : }
1606 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&key, 'C')) {
1607 : 0 : _PyArg_BadArgument("hmac_new", "argument 'key'", "contiguous buffer", args[0]);
1608 : 0 : goto exit;
1609 : : }
1610 [ # # ]: 0 : if (!noptargs) {
1611 : 0 : goto skip_optional_pos;
1612 : : }
1613 [ # # ]: 0 : if (args[1]) {
1614 : 0 : msg_obj = args[1];
1615 [ # # ]: 0 : if (!--noptargs) {
1616 : 0 : goto skip_optional_pos;
1617 : : }
1618 : : }
1619 : 0 : digestmod = args[2];
1620 : 0 : skip_optional_pos:
1621 : 0 : return_value = _hashlib_hmac_new_impl(module, &key, msg_obj, digestmod);
1622 : :
1623 : 0 : exit:
1624 : : /* Cleanup for key */
1625 [ # # ]: 0 : if (key.obj) {
1626 : 0 : PyBuffer_Release(&key);
1627 : : }
1628 : :
1629 : 0 : return return_value;
1630 : : }
1631 : :
1632 : : PyDoc_STRVAR(_hashlib_HMAC_copy__doc__,
1633 : : "copy($self, /)\n"
1634 : : "--\n"
1635 : : "\n"
1636 : : "Return a copy (\"clone\") of the HMAC object.");
1637 : :
1638 : : #define _HASHLIB_HMAC_COPY_METHODDEF \
1639 : : {"copy", (PyCFunction)_hashlib_HMAC_copy, METH_NOARGS, _hashlib_HMAC_copy__doc__},
1640 : :
1641 : : static PyObject *
1642 : : _hashlib_HMAC_copy_impl(HMACobject *self);
1643 : :
1644 : : static PyObject *
1645 : 0 : _hashlib_HMAC_copy(HMACobject *self, PyObject *Py_UNUSED(ignored))
1646 : : {
1647 : 0 : return _hashlib_HMAC_copy_impl(self);
1648 : : }
1649 : :
1650 : : PyDoc_STRVAR(_hashlib_HMAC_update__doc__,
1651 : : "update($self, /, msg)\n"
1652 : : "--\n"
1653 : : "\n"
1654 : : "Update the HMAC object with msg.");
1655 : :
1656 : : #define _HASHLIB_HMAC_UPDATE_METHODDEF \
1657 : : {"update", _PyCFunction_CAST(_hashlib_HMAC_update), METH_FASTCALL|METH_KEYWORDS, _hashlib_HMAC_update__doc__},
1658 : :
1659 : : static PyObject *
1660 : : _hashlib_HMAC_update_impl(HMACobject *self, PyObject *msg);
1661 : :
1662 : : static PyObject *
1663 : 0 : _hashlib_HMAC_update(HMACobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1664 : : {
1665 : 0 : PyObject *return_value = NULL;
1666 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1667 : :
1668 : : #define NUM_KEYWORDS 1
1669 : : static struct {
1670 : : PyGC_Head _this_is_not_used;
1671 : : PyObject_VAR_HEAD
1672 : : PyObject *ob_item[NUM_KEYWORDS];
1673 : : } _kwtuple = {
1674 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1675 : : .ob_item = { &_Py_ID(msg), },
1676 : : };
1677 : : #undef NUM_KEYWORDS
1678 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1679 : :
1680 : : #else // !Py_BUILD_CORE
1681 : : # define KWTUPLE NULL
1682 : : #endif // !Py_BUILD_CORE
1683 : :
1684 : : static const char * const _keywords[] = {"msg", NULL};
1685 : : static _PyArg_Parser _parser = {
1686 : : .keywords = _keywords,
1687 : : .fname = "update",
1688 : : .kwtuple = KWTUPLE,
1689 : : };
1690 : : #undef KWTUPLE
1691 : : PyObject *argsbuf[1];
1692 : : PyObject *msg;
1693 : :
1694 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1695 [ # # ]: 0 : if (!args) {
1696 : 0 : goto exit;
1697 : : }
1698 : 0 : msg = args[0];
1699 : 0 : return_value = _hashlib_HMAC_update_impl(self, msg);
1700 : :
1701 : 0 : exit:
1702 : 0 : return return_value;
1703 : : }
1704 : :
1705 : : PyDoc_STRVAR(_hashlib_HMAC_digest__doc__,
1706 : : "digest($self, /)\n"
1707 : : "--\n"
1708 : : "\n"
1709 : : "Return the digest of the bytes passed to the update() method so far.");
1710 : :
1711 : : #define _HASHLIB_HMAC_DIGEST_METHODDEF \
1712 : : {"digest", (PyCFunction)_hashlib_HMAC_digest, METH_NOARGS, _hashlib_HMAC_digest__doc__},
1713 : :
1714 : : static PyObject *
1715 : : _hashlib_HMAC_digest_impl(HMACobject *self);
1716 : :
1717 : : static PyObject *
1718 : 0 : _hashlib_HMAC_digest(HMACobject *self, PyObject *Py_UNUSED(ignored))
1719 : : {
1720 : 0 : return _hashlib_HMAC_digest_impl(self);
1721 : : }
1722 : :
1723 : : PyDoc_STRVAR(_hashlib_HMAC_hexdigest__doc__,
1724 : : "hexdigest($self, /)\n"
1725 : : "--\n"
1726 : : "\n"
1727 : : "Return hexadecimal digest of the bytes passed to the update() method so far.\n"
1728 : : "\n"
1729 : : "This may be used to exchange the value safely in email or other non-binary\n"
1730 : : "environments.");
1731 : :
1732 : : #define _HASHLIB_HMAC_HEXDIGEST_METHODDEF \
1733 : : {"hexdigest", (PyCFunction)_hashlib_HMAC_hexdigest, METH_NOARGS, _hashlib_HMAC_hexdigest__doc__},
1734 : :
1735 : : static PyObject *
1736 : : _hashlib_HMAC_hexdigest_impl(HMACobject *self);
1737 : :
1738 : : static PyObject *
1739 : 0 : _hashlib_HMAC_hexdigest(HMACobject *self, PyObject *Py_UNUSED(ignored))
1740 : : {
1741 : 0 : return _hashlib_HMAC_hexdigest_impl(self);
1742 : : }
1743 : :
1744 : : PyDoc_STRVAR(_hashlib_get_fips_mode__doc__,
1745 : : "get_fips_mode($module, /)\n"
1746 : : "--\n"
1747 : : "\n"
1748 : : "Determine the OpenSSL FIPS mode of operation.\n"
1749 : : "\n"
1750 : : "For OpenSSL 3.0.0 and newer it returns the state of the default provider\n"
1751 : : "in the default OSSL context. It\'s not quite the same as FIPS_mode() but good\n"
1752 : : "enough for unittests.\n"
1753 : : "\n"
1754 : : "Effectively any non-zero return value indicates FIPS mode;\n"
1755 : : "values other than 1 may have additional significance.");
1756 : :
1757 : : #define _HASHLIB_GET_FIPS_MODE_METHODDEF \
1758 : : {"get_fips_mode", (PyCFunction)_hashlib_get_fips_mode, METH_NOARGS, _hashlib_get_fips_mode__doc__},
1759 : :
1760 : : static int
1761 : : _hashlib_get_fips_mode_impl(PyObject *module);
1762 : :
1763 : : static PyObject *
1764 : 0 : _hashlib_get_fips_mode(PyObject *module, PyObject *Py_UNUSED(ignored))
1765 : : {
1766 : 0 : PyObject *return_value = NULL;
1767 : : int _return_value;
1768 : :
1769 : 0 : _return_value = _hashlib_get_fips_mode_impl(module);
1770 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
1771 : 0 : goto exit;
1772 : : }
1773 : 0 : return_value = PyLong_FromLong((long)_return_value);
1774 : :
1775 : 0 : exit:
1776 : 0 : return return_value;
1777 : : }
1778 : :
1779 : : PyDoc_STRVAR(_hashlib_compare_digest__doc__,
1780 : : "compare_digest($module, a, b, /)\n"
1781 : : "--\n"
1782 : : "\n"
1783 : : "Return \'a == b\'.\n"
1784 : : "\n"
1785 : : "This function uses an approach designed to prevent\n"
1786 : : "timing analysis, making it appropriate for cryptography.\n"
1787 : : "\n"
1788 : : "a and b must both be of the same type: either str (ASCII only),\n"
1789 : : "or any bytes-like object.\n"
1790 : : "\n"
1791 : : "Note: If a and b are of different lengths, or if an error occurs,\n"
1792 : : "a timing attack could theoretically reveal information about the\n"
1793 : : "types and lengths of a and b--but not their values.");
1794 : :
1795 : : #define _HASHLIB_COMPARE_DIGEST_METHODDEF \
1796 : : {"compare_digest", _PyCFunction_CAST(_hashlib_compare_digest), METH_FASTCALL, _hashlib_compare_digest__doc__},
1797 : :
1798 : : static PyObject *
1799 : : _hashlib_compare_digest_impl(PyObject *module, PyObject *a, PyObject *b);
1800 : :
1801 : : static PyObject *
1802 : 0 : _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1803 : : {
1804 : 0 : PyObject *return_value = NULL;
1805 : : PyObject *a;
1806 : : PyObject *b;
1807 : :
1808 [ # # # # : 0 : if (!_PyArg_CheckPositional("compare_digest", nargs, 2, 2)) {
# # ]
1809 : 0 : goto exit;
1810 : : }
1811 : 0 : a = args[0];
1812 : 0 : b = args[1];
1813 : 0 : return_value = _hashlib_compare_digest_impl(module, a, b);
1814 : :
1815 : 0 : exit:
1816 : 0 : return return_value;
1817 : : }
1818 : :
1819 : : #ifndef EVPXOF_DIGEST_METHODDEF
1820 : : #define EVPXOF_DIGEST_METHODDEF
1821 : : #endif /* !defined(EVPXOF_DIGEST_METHODDEF) */
1822 : :
1823 : : #ifndef EVPXOF_HEXDIGEST_METHODDEF
1824 : : #define EVPXOF_HEXDIGEST_METHODDEF
1825 : : #endif /* !defined(EVPXOF_HEXDIGEST_METHODDEF) */
1826 : :
1827 : : #ifndef _HASHLIB_OPENSSL_SHA3_224_METHODDEF
1828 : : #define _HASHLIB_OPENSSL_SHA3_224_METHODDEF
1829 : : #endif /* !defined(_HASHLIB_OPENSSL_SHA3_224_METHODDEF) */
1830 : :
1831 : : #ifndef _HASHLIB_OPENSSL_SHA3_256_METHODDEF
1832 : : #define _HASHLIB_OPENSSL_SHA3_256_METHODDEF
1833 : : #endif /* !defined(_HASHLIB_OPENSSL_SHA3_256_METHODDEF) */
1834 : :
1835 : : #ifndef _HASHLIB_OPENSSL_SHA3_384_METHODDEF
1836 : : #define _HASHLIB_OPENSSL_SHA3_384_METHODDEF
1837 : : #endif /* !defined(_HASHLIB_OPENSSL_SHA3_384_METHODDEF) */
1838 : :
1839 : : #ifndef _HASHLIB_OPENSSL_SHA3_512_METHODDEF
1840 : : #define _HASHLIB_OPENSSL_SHA3_512_METHODDEF
1841 : : #endif /* !defined(_HASHLIB_OPENSSL_SHA3_512_METHODDEF) */
1842 : :
1843 : : #ifndef _HASHLIB_OPENSSL_SHAKE_128_METHODDEF
1844 : : #define _HASHLIB_OPENSSL_SHAKE_128_METHODDEF
1845 : : #endif /* !defined(_HASHLIB_OPENSSL_SHAKE_128_METHODDEF) */
1846 : :
1847 : : #ifndef _HASHLIB_OPENSSL_SHAKE_256_METHODDEF
1848 : : #define _HASHLIB_OPENSSL_SHAKE_256_METHODDEF
1849 : : #endif /* !defined(_HASHLIB_OPENSSL_SHAKE_256_METHODDEF) */
1850 : :
1851 : : #ifndef _HASHLIB_SCRYPT_METHODDEF
1852 : : #define _HASHLIB_SCRYPT_METHODDEF
1853 : : #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
1854 : : /*[clinic end generated code: output=b339e255db698147 input=a9049054013a1b77]*/
|