sha2module.c.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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(SHA256Type_copy__doc__,
  9. "copy($self, /)\n"
  10. "--\n"
  11. "\n"
  12. "Return a copy of the hash object.");
  13. #define SHA256TYPE_COPY_METHODDEF \
  14. {"copy", _PyCFunction_CAST(SHA256Type_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, SHA256Type_copy__doc__},
  15. static PyObject *
  16. SHA256Type_copy_impl(SHA256object *self, PyTypeObject *cls);
  17. static PyObject *
  18. SHA256Type_copy(SHA256object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  19. {
  20. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  21. PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
  22. return NULL;
  23. }
  24. return SHA256Type_copy_impl(self, cls);
  25. }
  26. PyDoc_STRVAR(SHA512Type_copy__doc__,
  27. "copy($self, /)\n"
  28. "--\n"
  29. "\n"
  30. "Return a copy of the hash object.");
  31. #define SHA512TYPE_COPY_METHODDEF \
  32. {"copy", _PyCFunction_CAST(SHA512Type_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, SHA512Type_copy__doc__},
  33. static PyObject *
  34. SHA512Type_copy_impl(SHA512object *self, PyTypeObject *cls);
  35. static PyObject *
  36. SHA512Type_copy(SHA512object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  37. {
  38. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  39. PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
  40. return NULL;
  41. }
  42. return SHA512Type_copy_impl(self, cls);
  43. }
  44. PyDoc_STRVAR(SHA256Type_digest__doc__,
  45. "digest($self, /)\n"
  46. "--\n"
  47. "\n"
  48. "Return the digest value as a bytes object.");
  49. #define SHA256TYPE_DIGEST_METHODDEF \
  50. {"digest", (PyCFunction)SHA256Type_digest, METH_NOARGS, SHA256Type_digest__doc__},
  51. static PyObject *
  52. SHA256Type_digest_impl(SHA256object *self);
  53. static PyObject *
  54. SHA256Type_digest(SHA256object *self, PyObject *Py_UNUSED(ignored))
  55. {
  56. return SHA256Type_digest_impl(self);
  57. }
  58. PyDoc_STRVAR(SHA512Type_digest__doc__,
  59. "digest($self, /)\n"
  60. "--\n"
  61. "\n"
  62. "Return the digest value as a bytes object.");
  63. #define SHA512TYPE_DIGEST_METHODDEF \
  64. {"digest", (PyCFunction)SHA512Type_digest, METH_NOARGS, SHA512Type_digest__doc__},
  65. static PyObject *
  66. SHA512Type_digest_impl(SHA512object *self);
  67. static PyObject *
  68. SHA512Type_digest(SHA512object *self, PyObject *Py_UNUSED(ignored))
  69. {
  70. return SHA512Type_digest_impl(self);
  71. }
  72. PyDoc_STRVAR(SHA256Type_hexdigest__doc__,
  73. "hexdigest($self, /)\n"
  74. "--\n"
  75. "\n"
  76. "Return the digest value as a string of hexadecimal digits.");
  77. #define SHA256TYPE_HEXDIGEST_METHODDEF \
  78. {"hexdigest", (PyCFunction)SHA256Type_hexdigest, METH_NOARGS, SHA256Type_hexdigest__doc__},
  79. static PyObject *
  80. SHA256Type_hexdigest_impl(SHA256object *self);
  81. static PyObject *
  82. SHA256Type_hexdigest(SHA256object *self, PyObject *Py_UNUSED(ignored))
  83. {
  84. return SHA256Type_hexdigest_impl(self);
  85. }
  86. PyDoc_STRVAR(SHA512Type_hexdigest__doc__,
  87. "hexdigest($self, /)\n"
  88. "--\n"
  89. "\n"
  90. "Return the digest value as a string of hexadecimal digits.");
  91. #define SHA512TYPE_HEXDIGEST_METHODDEF \
  92. {"hexdigest", (PyCFunction)SHA512Type_hexdigest, METH_NOARGS, SHA512Type_hexdigest__doc__},
  93. static PyObject *
  94. SHA512Type_hexdigest_impl(SHA512object *self);
  95. static PyObject *
  96. SHA512Type_hexdigest(SHA512object *self, PyObject *Py_UNUSED(ignored))
  97. {
  98. return SHA512Type_hexdigest_impl(self);
  99. }
  100. PyDoc_STRVAR(SHA256Type_update__doc__,
  101. "update($self, obj, /)\n"
  102. "--\n"
  103. "\n"
  104. "Update this hash object\'s state with the provided string.");
  105. #define SHA256TYPE_UPDATE_METHODDEF \
  106. {"update", (PyCFunction)SHA256Type_update, METH_O, SHA256Type_update__doc__},
  107. PyDoc_STRVAR(SHA512Type_update__doc__,
  108. "update($self, obj, /)\n"
  109. "--\n"
  110. "\n"
  111. "Update this hash object\'s state with the provided string.");
  112. #define SHA512TYPE_UPDATE_METHODDEF \
  113. {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__},
  114. PyDoc_STRVAR(_sha2_sha256__doc__,
  115. "sha256($module, /, string=b\'\', *, usedforsecurity=True)\n"
  116. "--\n"
  117. "\n"
  118. "Return a new SHA-256 hash object; optionally initialized with a string.");
  119. #define _SHA2_SHA256_METHODDEF \
  120. {"sha256", _PyCFunction_CAST(_sha2_sha256), METH_FASTCALL|METH_KEYWORDS, _sha2_sha256__doc__},
  121. static PyObject *
  122. _sha2_sha256_impl(PyObject *module, PyObject *string, int usedforsecurity);
  123. static PyObject *
  124. _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  125. {
  126. PyObject *return_value = NULL;
  127. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  128. #define NUM_KEYWORDS 2
  129. static struct {
  130. PyGC_Head _this_is_not_used;
  131. PyObject_VAR_HEAD
  132. PyObject *ob_item[NUM_KEYWORDS];
  133. } _kwtuple = {
  134. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  135. .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
  136. };
  137. #undef NUM_KEYWORDS
  138. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  139. #else // !Py_BUILD_CORE
  140. # define KWTUPLE NULL
  141. #endif // !Py_BUILD_CORE
  142. static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
  143. static _PyArg_Parser _parser = {
  144. .keywords = _keywords,
  145. .fname = "sha256",
  146. .kwtuple = KWTUPLE,
  147. };
  148. #undef KWTUPLE
  149. PyObject *argsbuf[2];
  150. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  151. PyObject *string = NULL;
  152. int usedforsecurity = 1;
  153. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  154. if (!args) {
  155. goto exit;
  156. }
  157. if (!noptargs) {
  158. goto skip_optional_pos;
  159. }
  160. if (args[0]) {
  161. string = args[0];
  162. if (!--noptargs) {
  163. goto skip_optional_pos;
  164. }
  165. }
  166. skip_optional_pos:
  167. if (!noptargs) {
  168. goto skip_optional_kwonly;
  169. }
  170. usedforsecurity = PyObject_IsTrue(args[1]);
  171. if (usedforsecurity < 0) {
  172. goto exit;
  173. }
  174. skip_optional_kwonly:
  175. return_value = _sha2_sha256_impl(module, string, usedforsecurity);
  176. exit:
  177. return return_value;
  178. }
  179. PyDoc_STRVAR(_sha2_sha224__doc__,
  180. "sha224($module, /, string=b\'\', *, usedforsecurity=True)\n"
  181. "--\n"
  182. "\n"
  183. "Return a new SHA-224 hash object; optionally initialized with a string.");
  184. #define _SHA2_SHA224_METHODDEF \
  185. {"sha224", _PyCFunction_CAST(_sha2_sha224), METH_FASTCALL|METH_KEYWORDS, _sha2_sha224__doc__},
  186. static PyObject *
  187. _sha2_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity);
  188. static PyObject *
  189. _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  190. {
  191. PyObject *return_value = NULL;
  192. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  193. #define NUM_KEYWORDS 2
  194. static struct {
  195. PyGC_Head _this_is_not_used;
  196. PyObject_VAR_HEAD
  197. PyObject *ob_item[NUM_KEYWORDS];
  198. } _kwtuple = {
  199. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  200. .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
  201. };
  202. #undef NUM_KEYWORDS
  203. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  204. #else // !Py_BUILD_CORE
  205. # define KWTUPLE NULL
  206. #endif // !Py_BUILD_CORE
  207. static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
  208. static _PyArg_Parser _parser = {
  209. .keywords = _keywords,
  210. .fname = "sha224",
  211. .kwtuple = KWTUPLE,
  212. };
  213. #undef KWTUPLE
  214. PyObject *argsbuf[2];
  215. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  216. PyObject *string = NULL;
  217. int usedforsecurity = 1;
  218. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  219. if (!args) {
  220. goto exit;
  221. }
  222. if (!noptargs) {
  223. goto skip_optional_pos;
  224. }
  225. if (args[0]) {
  226. string = args[0];
  227. if (!--noptargs) {
  228. goto skip_optional_pos;
  229. }
  230. }
  231. skip_optional_pos:
  232. if (!noptargs) {
  233. goto skip_optional_kwonly;
  234. }
  235. usedforsecurity = PyObject_IsTrue(args[1]);
  236. if (usedforsecurity < 0) {
  237. goto exit;
  238. }
  239. skip_optional_kwonly:
  240. return_value = _sha2_sha224_impl(module, string, usedforsecurity);
  241. exit:
  242. return return_value;
  243. }
  244. PyDoc_STRVAR(_sha2_sha512__doc__,
  245. "sha512($module, /, string=b\'\', *, usedforsecurity=True)\n"
  246. "--\n"
  247. "\n"
  248. "Return a new SHA-512 hash object; optionally initialized with a string.");
  249. #define _SHA2_SHA512_METHODDEF \
  250. {"sha512", _PyCFunction_CAST(_sha2_sha512), METH_FASTCALL|METH_KEYWORDS, _sha2_sha512__doc__},
  251. static PyObject *
  252. _sha2_sha512_impl(PyObject *module, PyObject *string, int usedforsecurity);
  253. static PyObject *
  254. _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  255. {
  256. PyObject *return_value = NULL;
  257. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  258. #define NUM_KEYWORDS 2
  259. static struct {
  260. PyGC_Head _this_is_not_used;
  261. PyObject_VAR_HEAD
  262. PyObject *ob_item[NUM_KEYWORDS];
  263. } _kwtuple = {
  264. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  265. .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
  266. };
  267. #undef NUM_KEYWORDS
  268. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  269. #else // !Py_BUILD_CORE
  270. # define KWTUPLE NULL
  271. #endif // !Py_BUILD_CORE
  272. static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
  273. static _PyArg_Parser _parser = {
  274. .keywords = _keywords,
  275. .fname = "sha512",
  276. .kwtuple = KWTUPLE,
  277. };
  278. #undef KWTUPLE
  279. PyObject *argsbuf[2];
  280. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  281. PyObject *string = NULL;
  282. int usedforsecurity = 1;
  283. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  284. if (!args) {
  285. goto exit;
  286. }
  287. if (!noptargs) {
  288. goto skip_optional_pos;
  289. }
  290. if (args[0]) {
  291. string = args[0];
  292. if (!--noptargs) {
  293. goto skip_optional_pos;
  294. }
  295. }
  296. skip_optional_pos:
  297. if (!noptargs) {
  298. goto skip_optional_kwonly;
  299. }
  300. usedforsecurity = PyObject_IsTrue(args[1]);
  301. if (usedforsecurity < 0) {
  302. goto exit;
  303. }
  304. skip_optional_kwonly:
  305. return_value = _sha2_sha512_impl(module, string, usedforsecurity);
  306. exit:
  307. return return_value;
  308. }
  309. PyDoc_STRVAR(_sha2_sha384__doc__,
  310. "sha384($module, /, string=b\'\', *, usedforsecurity=True)\n"
  311. "--\n"
  312. "\n"
  313. "Return a new SHA-384 hash object; optionally initialized with a string.");
  314. #define _SHA2_SHA384_METHODDEF \
  315. {"sha384", _PyCFunction_CAST(_sha2_sha384), METH_FASTCALL|METH_KEYWORDS, _sha2_sha384__doc__},
  316. static PyObject *
  317. _sha2_sha384_impl(PyObject *module, PyObject *string, int usedforsecurity);
  318. static PyObject *
  319. _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  320. {
  321. PyObject *return_value = NULL;
  322. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  323. #define NUM_KEYWORDS 2
  324. static struct {
  325. PyGC_Head _this_is_not_used;
  326. PyObject_VAR_HEAD
  327. PyObject *ob_item[NUM_KEYWORDS];
  328. } _kwtuple = {
  329. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  330. .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
  331. };
  332. #undef NUM_KEYWORDS
  333. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  334. #else // !Py_BUILD_CORE
  335. # define KWTUPLE NULL
  336. #endif // !Py_BUILD_CORE
  337. static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
  338. static _PyArg_Parser _parser = {
  339. .keywords = _keywords,
  340. .fname = "sha384",
  341. .kwtuple = KWTUPLE,
  342. };
  343. #undef KWTUPLE
  344. PyObject *argsbuf[2];
  345. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  346. PyObject *string = NULL;
  347. int usedforsecurity = 1;
  348. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  349. if (!args) {
  350. goto exit;
  351. }
  352. if (!noptargs) {
  353. goto skip_optional_pos;
  354. }
  355. if (args[0]) {
  356. string = args[0];
  357. if (!--noptargs) {
  358. goto skip_optional_pos;
  359. }
  360. }
  361. skip_optional_pos:
  362. if (!noptargs) {
  363. goto skip_optional_kwonly;
  364. }
  365. usedforsecurity = PyObject_IsTrue(args[1]);
  366. if (usedforsecurity < 0) {
  367. goto exit;
  368. }
  369. skip_optional_kwonly:
  370. return_value = _sha2_sha384_impl(module, string, usedforsecurity);
  371. exit:
  372. return return_value;
  373. }
  374. /*[clinic end generated code: output=d83a27cd9522cf22 input=a9049054013a1b77]*/