sha3module.c.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(py_sha3_new__doc__,
  9. "sha3_224(data=b\'\', /, *, usedforsecurity=True)\n"
  10. "--\n"
  11. "\n"
  12. "Return a new SHA3 hash object.");
  13. static PyObject *
  14. py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity);
  15. static PyObject *
  16. py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  17. {
  18. PyObject *return_value = NULL;
  19. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  20. #define NUM_KEYWORDS 1
  21. static struct {
  22. PyGC_Head _this_is_not_used;
  23. PyObject_VAR_HEAD
  24. PyObject *ob_item[NUM_KEYWORDS];
  25. } _kwtuple = {
  26. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  27. .ob_item = { &_Py_ID(usedforsecurity), },
  28. };
  29. #undef NUM_KEYWORDS
  30. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  31. #else // !Py_BUILD_CORE
  32. # define KWTUPLE NULL
  33. #endif // !Py_BUILD_CORE
  34. static const char * const _keywords[] = {"", "usedforsecurity", NULL};
  35. static _PyArg_Parser _parser = {
  36. .keywords = _keywords,
  37. .fname = "sha3_224",
  38. .kwtuple = KWTUPLE,
  39. };
  40. #undef KWTUPLE
  41. PyObject *argsbuf[2];
  42. PyObject * const *fastargs;
  43. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  44. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
  45. PyObject *data = NULL;
  46. int usedforsecurity = 1;
  47. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
  48. if (!fastargs) {
  49. goto exit;
  50. }
  51. if (nargs < 1) {
  52. goto skip_optional_posonly;
  53. }
  54. noptargs--;
  55. data = fastargs[0];
  56. skip_optional_posonly:
  57. if (!noptargs) {
  58. goto skip_optional_kwonly;
  59. }
  60. usedforsecurity = PyObject_IsTrue(fastargs[1]);
  61. if (usedforsecurity < 0) {
  62. goto exit;
  63. }
  64. skip_optional_kwonly:
  65. return_value = py_sha3_new_impl(type, data, usedforsecurity);
  66. exit:
  67. return return_value;
  68. }
  69. PyDoc_STRVAR(_sha3_sha3_224_copy__doc__,
  70. "copy($self, /)\n"
  71. "--\n"
  72. "\n"
  73. "Return a copy of the hash object.");
  74. #define _SHA3_SHA3_224_COPY_METHODDEF \
  75. {"copy", (PyCFunction)_sha3_sha3_224_copy, METH_NOARGS, _sha3_sha3_224_copy__doc__},
  76. static PyObject *
  77. _sha3_sha3_224_copy_impl(SHA3object *self);
  78. static PyObject *
  79. _sha3_sha3_224_copy(SHA3object *self, PyObject *Py_UNUSED(ignored))
  80. {
  81. return _sha3_sha3_224_copy_impl(self);
  82. }
  83. PyDoc_STRVAR(_sha3_sha3_224_digest__doc__,
  84. "digest($self, /)\n"
  85. "--\n"
  86. "\n"
  87. "Return the digest value as a bytes object.");
  88. #define _SHA3_SHA3_224_DIGEST_METHODDEF \
  89. {"digest", (PyCFunction)_sha3_sha3_224_digest, METH_NOARGS, _sha3_sha3_224_digest__doc__},
  90. static PyObject *
  91. _sha3_sha3_224_digest_impl(SHA3object *self);
  92. static PyObject *
  93. _sha3_sha3_224_digest(SHA3object *self, PyObject *Py_UNUSED(ignored))
  94. {
  95. return _sha3_sha3_224_digest_impl(self);
  96. }
  97. PyDoc_STRVAR(_sha3_sha3_224_hexdigest__doc__,
  98. "hexdigest($self, /)\n"
  99. "--\n"
  100. "\n"
  101. "Return the digest value as a string of hexadecimal digits.");
  102. #define _SHA3_SHA3_224_HEXDIGEST_METHODDEF \
  103. {"hexdigest", (PyCFunction)_sha3_sha3_224_hexdigest, METH_NOARGS, _sha3_sha3_224_hexdigest__doc__},
  104. static PyObject *
  105. _sha3_sha3_224_hexdigest_impl(SHA3object *self);
  106. static PyObject *
  107. _sha3_sha3_224_hexdigest(SHA3object *self, PyObject *Py_UNUSED(ignored))
  108. {
  109. return _sha3_sha3_224_hexdigest_impl(self);
  110. }
  111. PyDoc_STRVAR(_sha3_sha3_224_update__doc__,
  112. "update($self, data, /)\n"
  113. "--\n"
  114. "\n"
  115. "Update this hash object\'s state with the provided bytes-like object.");
  116. #define _SHA3_SHA3_224_UPDATE_METHODDEF \
  117. {"update", (PyCFunction)_sha3_sha3_224_update, METH_O, _sha3_sha3_224_update__doc__},
  118. PyDoc_STRVAR(_sha3_shake_128_digest__doc__,
  119. "digest($self, length, /)\n"
  120. "--\n"
  121. "\n"
  122. "Return the digest value as a bytes object.");
  123. #define _SHA3_SHAKE_128_DIGEST_METHODDEF \
  124. {"digest", (PyCFunction)_sha3_shake_128_digest, METH_O, _sha3_shake_128_digest__doc__},
  125. static PyObject *
  126. _sha3_shake_128_digest_impl(SHA3object *self, unsigned long length);
  127. static PyObject *
  128. _sha3_shake_128_digest(SHA3object *self, PyObject *arg)
  129. {
  130. PyObject *return_value = NULL;
  131. unsigned long length;
  132. if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
  133. goto exit;
  134. }
  135. return_value = _sha3_shake_128_digest_impl(self, length);
  136. exit:
  137. return return_value;
  138. }
  139. PyDoc_STRVAR(_sha3_shake_128_hexdigest__doc__,
  140. "hexdigest($self, length, /)\n"
  141. "--\n"
  142. "\n"
  143. "Return the digest value as a string of hexadecimal digits.");
  144. #define _SHA3_SHAKE_128_HEXDIGEST_METHODDEF \
  145. {"hexdigest", (PyCFunction)_sha3_shake_128_hexdigest, METH_O, _sha3_shake_128_hexdigest__doc__},
  146. static PyObject *
  147. _sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length);
  148. static PyObject *
  149. _sha3_shake_128_hexdigest(SHA3object *self, PyObject *arg)
  150. {
  151. PyObject *return_value = NULL;
  152. unsigned long length;
  153. if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
  154. goto exit;
  155. }
  156. return_value = _sha3_shake_128_hexdigest_impl(self, length);
  157. exit:
  158. return return_value;
  159. }
  160. /*[clinic end generated code: output=907cb475f3dc9ee0 input=a9049054013a1b77]*/