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