• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PyDoc_STRVAR(EVP_new__doc__,
69 "new($module, /, name, string=b\'\')\n"
70 "--\n"
71 "\n"
72 "Return a new hash object using the named algorithm.\n"
73 "\n"
74 "An optional string argument may be provided and will be\n"
75 "automatically hashed.\n"
76 "\n"
77 "The MD5 and SHA1 algorithms are always supported.");
78 
79 #define EVP_NEW_METHODDEF    \
80     {"new", (PyCFunction)(void(*)(void))EVP_new, METH_FASTCALL|METH_KEYWORDS, EVP_new__doc__},
81 
82 static PyObject *
83 EVP_new_impl(PyObject *module, PyObject *name_obj, PyObject *data_obj);
84 
85 static PyObject *
EVP_new(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)86 EVP_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
87 {
88     PyObject *return_value = NULL;
89     static const char * const _keywords[] = {"name", "string", NULL};
90     static _PyArg_Parser _parser = {NULL, _keywords, "new", 0};
91     PyObject *argsbuf[2];
92     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
93     PyObject *name_obj;
94     PyObject *data_obj = NULL;
95 
96     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
97     if (!args) {
98         goto exit;
99     }
100     name_obj = args[0];
101     if (!noptargs) {
102         goto skip_optional_pos;
103     }
104     data_obj = args[1];
105 skip_optional_pos:
106     return_value = EVP_new_impl(module, name_obj, data_obj);
107 
108 exit:
109     return return_value;
110 }
111 
112 PyDoc_STRVAR(_hashlib_openssl_md5__doc__,
113 "openssl_md5($module, /, string=b\'\')\n"
114 "--\n"
115 "\n"
116 "Returns a md5 hash object; optionally initialized with a string");
117 
118 #define _HASHLIB_OPENSSL_MD5_METHODDEF    \
119     {"openssl_md5", (PyCFunction)(void(*)(void))_hashlib_openssl_md5, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_md5__doc__},
120 
121 static PyObject *
122 _hashlib_openssl_md5_impl(PyObject *module, PyObject *data_obj);
123 
124 static PyObject *
_hashlib_openssl_md5(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)125 _hashlib_openssl_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
126 {
127     PyObject *return_value = NULL;
128     static const char * const _keywords[] = {"string", NULL};
129     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_md5", 0};
130     PyObject *argsbuf[1];
131     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
132     PyObject *data_obj = NULL;
133 
134     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
135     if (!args) {
136         goto exit;
137     }
138     if (!noptargs) {
139         goto skip_optional_pos;
140     }
141     data_obj = args[0];
142 skip_optional_pos:
143     return_value = _hashlib_openssl_md5_impl(module, data_obj);
144 
145 exit:
146     return return_value;
147 }
148 
149 PyDoc_STRVAR(_hashlib_openssl_sha1__doc__,
150 "openssl_sha1($module, /, string=b\'\')\n"
151 "--\n"
152 "\n"
153 "Returns a sha1 hash object; optionally initialized with a string");
154 
155 #define _HASHLIB_OPENSSL_SHA1_METHODDEF    \
156     {"openssl_sha1", (PyCFunction)(void(*)(void))_hashlib_openssl_sha1, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha1__doc__},
157 
158 static PyObject *
159 _hashlib_openssl_sha1_impl(PyObject *module, PyObject *data_obj);
160 
161 static PyObject *
_hashlib_openssl_sha1(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)162 _hashlib_openssl_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
163 {
164     PyObject *return_value = NULL;
165     static const char * const _keywords[] = {"string", NULL};
166     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_sha1", 0};
167     PyObject *argsbuf[1];
168     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
169     PyObject *data_obj = NULL;
170 
171     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
172     if (!args) {
173         goto exit;
174     }
175     if (!noptargs) {
176         goto skip_optional_pos;
177     }
178     data_obj = args[0];
179 skip_optional_pos:
180     return_value = _hashlib_openssl_sha1_impl(module, data_obj);
181 
182 exit:
183     return return_value;
184 }
185 
186 PyDoc_STRVAR(_hashlib_openssl_sha224__doc__,
187 "openssl_sha224($module, /, string=b\'\')\n"
188 "--\n"
189 "\n"
190 "Returns a sha224 hash object; optionally initialized with a string");
191 
192 #define _HASHLIB_OPENSSL_SHA224_METHODDEF    \
193     {"openssl_sha224", (PyCFunction)(void(*)(void))_hashlib_openssl_sha224, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha224__doc__},
194 
195 static PyObject *
196 _hashlib_openssl_sha224_impl(PyObject *module, PyObject *data_obj);
197 
198 static PyObject *
_hashlib_openssl_sha224(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)199 _hashlib_openssl_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
200 {
201     PyObject *return_value = NULL;
202     static const char * const _keywords[] = {"string", NULL};
203     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_sha224", 0};
204     PyObject *argsbuf[1];
205     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
206     PyObject *data_obj = NULL;
207 
208     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
209     if (!args) {
210         goto exit;
211     }
212     if (!noptargs) {
213         goto skip_optional_pos;
214     }
215     data_obj = args[0];
216 skip_optional_pos:
217     return_value = _hashlib_openssl_sha224_impl(module, data_obj);
218 
219 exit:
220     return return_value;
221 }
222 
223 PyDoc_STRVAR(_hashlib_openssl_sha256__doc__,
224 "openssl_sha256($module, /, string=b\'\')\n"
225 "--\n"
226 "\n"
227 "Returns a sha256 hash object; optionally initialized with a string");
228 
229 #define _HASHLIB_OPENSSL_SHA256_METHODDEF    \
230     {"openssl_sha256", (PyCFunction)(void(*)(void))_hashlib_openssl_sha256, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha256__doc__},
231 
232 static PyObject *
233 _hashlib_openssl_sha256_impl(PyObject *module, PyObject *data_obj);
234 
235 static PyObject *
_hashlib_openssl_sha256(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)236 _hashlib_openssl_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
237 {
238     PyObject *return_value = NULL;
239     static const char * const _keywords[] = {"string", NULL};
240     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_sha256", 0};
241     PyObject *argsbuf[1];
242     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
243     PyObject *data_obj = NULL;
244 
245     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
246     if (!args) {
247         goto exit;
248     }
249     if (!noptargs) {
250         goto skip_optional_pos;
251     }
252     data_obj = args[0];
253 skip_optional_pos:
254     return_value = _hashlib_openssl_sha256_impl(module, data_obj);
255 
256 exit:
257     return return_value;
258 }
259 
260 PyDoc_STRVAR(_hashlib_openssl_sha384__doc__,
261 "openssl_sha384($module, /, string=b\'\')\n"
262 "--\n"
263 "\n"
264 "Returns a sha384 hash object; optionally initialized with a string");
265 
266 #define _HASHLIB_OPENSSL_SHA384_METHODDEF    \
267     {"openssl_sha384", (PyCFunction)(void(*)(void))_hashlib_openssl_sha384, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha384__doc__},
268 
269 static PyObject *
270 _hashlib_openssl_sha384_impl(PyObject *module, PyObject *data_obj);
271 
272 static PyObject *
_hashlib_openssl_sha384(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)273 _hashlib_openssl_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
274 {
275     PyObject *return_value = NULL;
276     static const char * const _keywords[] = {"string", NULL};
277     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_sha384", 0};
278     PyObject *argsbuf[1];
279     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
280     PyObject *data_obj = NULL;
281 
282     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
283     if (!args) {
284         goto exit;
285     }
286     if (!noptargs) {
287         goto skip_optional_pos;
288     }
289     data_obj = args[0];
290 skip_optional_pos:
291     return_value = _hashlib_openssl_sha384_impl(module, data_obj);
292 
293 exit:
294     return return_value;
295 }
296 
297 PyDoc_STRVAR(_hashlib_openssl_sha512__doc__,
298 "openssl_sha512($module, /, string=b\'\')\n"
299 "--\n"
300 "\n"
301 "Returns a sha512 hash object; optionally initialized with a string");
302 
303 #define _HASHLIB_OPENSSL_SHA512_METHODDEF    \
304     {"openssl_sha512", (PyCFunction)(void(*)(void))_hashlib_openssl_sha512, METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha512__doc__},
305 
306 static PyObject *
307 _hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj);
308 
309 static PyObject *
_hashlib_openssl_sha512(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)310 _hashlib_openssl_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
311 {
312     PyObject *return_value = NULL;
313     static const char * const _keywords[] = {"string", NULL};
314     static _PyArg_Parser _parser = {NULL, _keywords, "openssl_sha512", 0};
315     PyObject *argsbuf[1];
316     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
317     PyObject *data_obj = NULL;
318 
319     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
320     if (!args) {
321         goto exit;
322     }
323     if (!noptargs) {
324         goto skip_optional_pos;
325     }
326     data_obj = args[0];
327 skip_optional_pos:
328     return_value = _hashlib_openssl_sha512_impl(module, data_obj);
329 
330 exit:
331     return return_value;
332 }
333 
334 PyDoc_STRVAR(pbkdf2_hmac__doc__,
335 "pbkdf2_hmac($module, /, hash_name, password, salt, iterations,\n"
336 "            dklen=None)\n"
337 "--\n"
338 "\n"
339 "Password based key derivation function 2 (PKCS #5 v2.0) with HMAC as pseudorandom function.");
340 
341 #define PBKDF2_HMAC_METHODDEF    \
342     {"pbkdf2_hmac", (PyCFunction)(void(*)(void))pbkdf2_hmac, METH_FASTCALL|METH_KEYWORDS, pbkdf2_hmac__doc__},
343 
344 static PyObject *
345 pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
346                  Py_buffer *password, Py_buffer *salt, long iterations,
347                  PyObject *dklen_obj);
348 
349 static PyObject *
pbkdf2_hmac(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)350 pbkdf2_hmac(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
351 {
352     PyObject *return_value = NULL;
353     static const char * const _keywords[] = {"hash_name", "password", "salt", "iterations", "dklen", NULL};
354     static _PyArg_Parser _parser = {NULL, _keywords, "pbkdf2_hmac", 0};
355     PyObject *argsbuf[5];
356     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
357     const char *hash_name;
358     Py_buffer password = {NULL, NULL};
359     Py_buffer salt = {NULL, NULL};
360     long iterations;
361     PyObject *dklen_obj = Py_None;
362 
363     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 5, 0, argsbuf);
364     if (!args) {
365         goto exit;
366     }
367     if (!PyUnicode_Check(args[0])) {
368         _PyArg_BadArgument("pbkdf2_hmac", "argument 'hash_name'", "str", args[0]);
369         goto exit;
370     }
371     Py_ssize_t hash_name_length;
372     hash_name = PyUnicode_AsUTF8AndSize(args[0], &hash_name_length);
373     if (hash_name == NULL) {
374         goto exit;
375     }
376     if (strlen(hash_name) != (size_t)hash_name_length) {
377         PyErr_SetString(PyExc_ValueError, "embedded null character");
378         goto exit;
379     }
380     if (PyObject_GetBuffer(args[1], &password, PyBUF_SIMPLE) != 0) {
381         goto exit;
382     }
383     if (!PyBuffer_IsContiguous(&password, 'C')) {
384         _PyArg_BadArgument("pbkdf2_hmac", "argument 'password'", "contiguous buffer", args[1]);
385         goto exit;
386     }
387     if (PyObject_GetBuffer(args[2], &salt, PyBUF_SIMPLE) != 0) {
388         goto exit;
389     }
390     if (!PyBuffer_IsContiguous(&salt, 'C')) {
391         _PyArg_BadArgument("pbkdf2_hmac", "argument 'salt'", "contiguous buffer", args[2]);
392         goto exit;
393     }
394     if (PyFloat_Check(args[3])) {
395         PyErr_SetString(PyExc_TypeError,
396                         "integer argument expected, got float" );
397         goto exit;
398     }
399     iterations = PyLong_AsLong(args[3]);
400     if (iterations == -1 && PyErr_Occurred()) {
401         goto exit;
402     }
403     if (!noptargs) {
404         goto skip_optional_pos;
405     }
406     dklen_obj = args[4];
407 skip_optional_pos:
408     return_value = pbkdf2_hmac_impl(module, hash_name, &password, &salt, iterations, dklen_obj);
409 
410 exit:
411     /* Cleanup for password */
412     if (password.obj) {
413        PyBuffer_Release(&password);
414     }
415     /* Cleanup for salt */
416     if (salt.obj) {
417        PyBuffer_Release(&salt);
418     }
419 
420     return return_value;
421 }
422 
423 #if (OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER))
424 
425 PyDoc_STRVAR(_hashlib_scrypt__doc__,
426 "scrypt($module, /, password, *, salt=None, n=None, r=None, p=None,\n"
427 "       maxmem=0, dklen=64)\n"
428 "--\n"
429 "\n"
430 "scrypt password-based key derivation function.");
431 
432 #define _HASHLIB_SCRYPT_METHODDEF    \
433     {"scrypt", (PyCFunction)(void(*)(void))_hashlib_scrypt, METH_FASTCALL|METH_KEYWORDS, _hashlib_scrypt__doc__},
434 
435 static PyObject *
436 _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
437                      PyObject *n_obj, PyObject *r_obj, PyObject *p_obj,
438                      long maxmem, long dklen);
439 
440 static PyObject *
_hashlib_scrypt(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)441 _hashlib_scrypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
442 {
443     PyObject *return_value = NULL;
444     static const char * const _keywords[] = {"password", "salt", "n", "r", "p", "maxmem", "dklen", NULL};
445     static _PyArg_Parser _parser = {NULL, _keywords, "scrypt", 0};
446     PyObject *argsbuf[7];
447     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
448     Py_buffer password = {NULL, NULL};
449     Py_buffer salt = {NULL, NULL};
450     PyObject *n_obj = Py_None;
451     PyObject *r_obj = Py_None;
452     PyObject *p_obj = Py_None;
453     long maxmem = 0;
454     long dklen = 64;
455 
456     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
457     if (!args) {
458         goto exit;
459     }
460     if (PyObject_GetBuffer(args[0], &password, PyBUF_SIMPLE) != 0) {
461         goto exit;
462     }
463     if (!PyBuffer_IsContiguous(&password, 'C')) {
464         _PyArg_BadArgument("scrypt", "argument 'password'", "contiguous buffer", args[0]);
465         goto exit;
466     }
467     if (!noptargs) {
468         goto skip_optional_kwonly;
469     }
470     if (args[1]) {
471         if (PyObject_GetBuffer(args[1], &salt, PyBUF_SIMPLE) != 0) {
472             goto exit;
473         }
474         if (!PyBuffer_IsContiguous(&salt, 'C')) {
475             _PyArg_BadArgument("scrypt", "argument 'salt'", "contiguous buffer", args[1]);
476             goto exit;
477         }
478         if (!--noptargs) {
479             goto skip_optional_kwonly;
480         }
481     }
482     if (args[2]) {
483         if (!PyLong_Check(args[2])) {
484             _PyArg_BadArgument("scrypt", "argument 'n'", "int", args[2]);
485             goto exit;
486         }
487         n_obj = args[2];
488         if (!--noptargs) {
489             goto skip_optional_kwonly;
490         }
491     }
492     if (args[3]) {
493         if (!PyLong_Check(args[3])) {
494             _PyArg_BadArgument("scrypt", "argument 'r'", "int", args[3]);
495             goto exit;
496         }
497         r_obj = args[3];
498         if (!--noptargs) {
499             goto skip_optional_kwonly;
500         }
501     }
502     if (args[4]) {
503         if (!PyLong_Check(args[4])) {
504             _PyArg_BadArgument("scrypt", "argument 'p'", "int", args[4]);
505             goto exit;
506         }
507         p_obj = args[4];
508         if (!--noptargs) {
509             goto skip_optional_kwonly;
510         }
511     }
512     if (args[5]) {
513         if (PyFloat_Check(args[5])) {
514             PyErr_SetString(PyExc_TypeError,
515                             "integer argument expected, got float" );
516             goto exit;
517         }
518         maxmem = PyLong_AsLong(args[5]);
519         if (maxmem == -1 && PyErr_Occurred()) {
520             goto exit;
521         }
522         if (!--noptargs) {
523             goto skip_optional_kwonly;
524         }
525     }
526     if (PyFloat_Check(args[6])) {
527         PyErr_SetString(PyExc_TypeError,
528                         "integer argument expected, got float" );
529         goto exit;
530     }
531     dklen = PyLong_AsLong(args[6]);
532     if (dklen == -1 && PyErr_Occurred()) {
533         goto exit;
534     }
535 skip_optional_kwonly:
536     return_value = _hashlib_scrypt_impl(module, &password, &salt, n_obj, r_obj, p_obj, maxmem, dklen);
537 
538 exit:
539     /* Cleanup for password */
540     if (password.obj) {
541        PyBuffer_Release(&password);
542     }
543     /* Cleanup for salt */
544     if (salt.obj) {
545        PyBuffer_Release(&salt);
546     }
547 
548     return return_value;
549 }
550 
551 #endif /* (OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)) */
552 
553 PyDoc_STRVAR(_hashlib_hmac_digest__doc__,
554 "hmac_digest($module, /, key, msg, digest)\n"
555 "--\n"
556 "\n"
557 "Single-shot HMAC.");
558 
559 #define _HASHLIB_HMAC_DIGEST_METHODDEF    \
560     {"hmac_digest", (PyCFunction)(void(*)(void))_hashlib_hmac_digest, METH_FASTCALL|METH_KEYWORDS, _hashlib_hmac_digest__doc__},
561 
562 static PyObject *
563 _hashlib_hmac_digest_impl(PyObject *module, Py_buffer *key, Py_buffer *msg,
564                           const char *digest);
565 
566 static PyObject *
_hashlib_hmac_digest(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)567 _hashlib_hmac_digest(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
568 {
569     PyObject *return_value = NULL;
570     static const char * const _keywords[] = {"key", "msg", "digest", NULL};
571     static _PyArg_Parser _parser = {NULL, _keywords, "hmac_digest", 0};
572     PyObject *argsbuf[3];
573     Py_buffer key = {NULL, NULL};
574     Py_buffer msg = {NULL, NULL};
575     const char *digest;
576 
577     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
578     if (!args) {
579         goto exit;
580     }
581     if (PyObject_GetBuffer(args[0], &key, PyBUF_SIMPLE) != 0) {
582         goto exit;
583     }
584     if (!PyBuffer_IsContiguous(&key, 'C')) {
585         _PyArg_BadArgument("hmac_digest", "argument 'key'", "contiguous buffer", args[0]);
586         goto exit;
587     }
588     if (PyObject_GetBuffer(args[1], &msg, PyBUF_SIMPLE) != 0) {
589         goto exit;
590     }
591     if (!PyBuffer_IsContiguous(&msg, 'C')) {
592         _PyArg_BadArgument("hmac_digest", "argument 'msg'", "contiguous buffer", args[1]);
593         goto exit;
594     }
595     if (!PyUnicode_Check(args[2])) {
596         _PyArg_BadArgument("hmac_digest", "argument 'digest'", "str", args[2]);
597         goto exit;
598     }
599     Py_ssize_t digest_length;
600     digest = PyUnicode_AsUTF8AndSize(args[2], &digest_length);
601     if (digest == NULL) {
602         goto exit;
603     }
604     if (strlen(digest) != (size_t)digest_length) {
605         PyErr_SetString(PyExc_ValueError, "embedded null character");
606         goto exit;
607     }
608     return_value = _hashlib_hmac_digest_impl(module, &key, &msg, digest);
609 
610 exit:
611     /* Cleanup for key */
612     if (key.obj) {
613        PyBuffer_Release(&key);
614     }
615     /* Cleanup for msg */
616     if (msg.obj) {
617        PyBuffer_Release(&msg);
618     }
619 
620     return return_value;
621 }
622 
623 #ifndef _HASHLIB_SCRYPT_METHODDEF
624     #define _HASHLIB_SCRYPT_METHODDEF
625 #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
626 /*[clinic end generated code: output=38c2637f67e9bb79 input=a9049054013a1b77]*/
627