_hashopenssl.c.h 53 KB

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