Debian Codegraph @

Modules/clinic/sha3module.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(py_sha3_new__doc__,
13 "sha3_224(data=b\'\', *, usedforsecurity=True, string=None)\n"
14 "--\n"
15 "\n"
16 "Return a new SHA3 hash object.");
17
18 static PyObject *
19 py_sha3_new_impl(PyTypeObject *type, PyObject *data_obj, int usedforsecurity,
20 PyObject *string);
21
22 static PyObject *
23 py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
24 {
25 PyObject *return_value = NULL;
26 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
27
28 #define NUM_KEYWORDS 3
29 static struct {
30 PyGC_Head _this_is_not_used;
31 PyObject_VAR_HEAD
32 Py_hash_t ob_hash;
33 PyObject *ob_item[NUM_KEYWORDS];
34 } _kwtuple = {
35 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36 .ob_hash = -1,
37 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
38 };
39 #undef NUM_KEYWORDS
40 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
41
42 #else // !Py_BUILD_CORE
43 # define KWTUPLE NULL
44 #endif // !Py_BUILD_CORE
45
46 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
47 static _PyArg_Parser _parser = {
48 .keywords = _keywords,
49 .fname = "sha3_224",
50 .kwtuple = KWTUPLE,
51 };
52 #undef KWTUPLE
53 PyObject *argsbuf[3];
54 PyObject * const *fastargs;
55 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
56 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
57 PyObject *data_obj = NULL;
58 int usedforsecurity = 1;
59 PyObject *string = NULL;
60
61 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
62 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
63 if (!fastargs) {
64 goto exit;
65 }
66 if (!noptargs) {
67 goto skip_optional_pos;
68 }
69 if (fastargs[0]) {
70 data_obj = fastargs[0];
71 if (!--noptargs) {
72 goto skip_optional_pos;
73 }
74 }
75 skip_optional_pos:
76 if (!noptargs) {
77 goto skip_optional_kwonly;
78 }
79 if (fastargs[1]) {
80 usedforsecurity = PyObject_IsTrue(fastargs[1]);
81 if (usedforsecurity < 0) {
82 goto exit;
83 }
84 if (!--noptargs) {
85 goto skip_optional_kwonly;
86 }
87 }
88 string = fastargs[2];
89 skip_optional_kwonly:
90 return_value = py_sha3_new_impl(type, data_obj, usedforsecurity, string);
91
92 exit:
93 return return_value;
94 }
95
96 PyDoc_STRVAR(_sha3_sha3_224_copy__doc__,
97 "copy($self, /)\n"
98 "--\n"
99 "\n"
100 "Return a copy of the hash object.");
101
102 #define _SHA3_SHA3_224_COPY_METHODDEF \
103 {"copy", (PyCFunction)_sha3_sha3_224_copy, METH_NOARGS, _sha3_sha3_224_copy__doc__},
104
105 static PyObject *
106 _sha3_sha3_224_copy_impl(SHA3object *self);
107
108 static PyObject *
109 _sha3_sha3_224_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
110 {
111 return _sha3_sha3_224_copy_impl((SHA3object *)self);
112 }
113
114 PyDoc_STRVAR(_sha3_sha3_224_digest__doc__,
115 "digest($self, /)\n"
116 "--\n"
117 "\n"
118 "Return the digest value as a bytes object.");
119
120 #define _SHA3_SHA3_224_DIGEST_METHODDEF \
121 {"digest", (PyCFunction)_sha3_sha3_224_digest, METH_NOARGS, _sha3_sha3_224_digest__doc__},
122
123 static PyObject *
124 _sha3_sha3_224_digest_impl(SHA3object *self);
125
126 static PyObject *
127 _sha3_sha3_224_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
128 {
129 return _sha3_sha3_224_digest_impl((SHA3object *)self);
130 }
131
132 PyDoc_STRVAR(_sha3_sha3_224_hexdigest__doc__,
133 "hexdigest($self, /)\n"
134 "--\n"
135 "\n"
136 "Return the digest value as a string of hexadecimal digits.");
137
138 #define _SHA3_SHA3_224_HEXDIGEST_METHODDEF \
139 {"hexdigest", (PyCFunction)_sha3_sha3_224_hexdigest, METH_NOARGS, _sha3_sha3_224_hexdigest__doc__},
140
141 static PyObject *
142 _sha3_sha3_224_hexdigest_impl(SHA3object *self);
143
144 static PyObject *
145 _sha3_sha3_224_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
146 {
147 return _sha3_sha3_224_hexdigest_impl((SHA3object *)self);
148 }
149
150 PyDoc_STRVAR(_sha3_sha3_224_update__doc__,
151 "update($self, data, /)\n"
152 "--\n"
153 "\n"
154 "Update this hash object\'s state with the provided bytes-like object.");
155
156 #define _SHA3_SHA3_224_UPDATE_METHODDEF \
157 {"update", (PyCFunction)_sha3_sha3_224_update, METH_O, _sha3_sha3_224_update__doc__},
158
159 static PyObject *
160 _sha3_sha3_224_update_impl(SHA3object *self, PyObject *data);
161
162 static PyObject *
163 _sha3_sha3_224_update(PyObject *self, PyObject *data)
164 {
165 PyObject *return_value = NULL;
166
167 return_value = _sha3_sha3_224_update_impl((SHA3object *)self, data);
168
169 return return_value;
170 }
171
172 PyDoc_STRVAR(_sha3_shake_128_digest__doc__,
173 "digest($self, /, length)\n"
174 "--\n"
175 "\n"
176 "Return the digest value as a bytes object.");
177
178 #define _SHA3_SHAKE_128_DIGEST_METHODDEF \
179 {"digest", _PyCFunction_CAST(_sha3_shake_128_digest), METH_FASTCALL|METH_KEYWORDS, _sha3_shake_128_digest__doc__},
180
181 static PyObject *
182 _sha3_shake_128_digest_impl(SHA3object *self, unsigned long length);
183
184 static PyObject *
185 _sha3_shake_128_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
186 {
187 PyObject *return_value = NULL;
188 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
189
190 #define NUM_KEYWORDS 1
191 static struct {
192 PyGC_Head _this_is_not_used;
193 PyObject_VAR_HEAD
194 Py_hash_t ob_hash;
195 PyObject *ob_item[NUM_KEYWORDS];
196 } _kwtuple = {
197 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
198 .ob_hash = -1,
199 .ob_item = { &_Py_ID(length), },
200 };
201 #undef NUM_KEYWORDS
202 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
203
204 #else // !Py_BUILD_CORE
205 # define KWTUPLE NULL
206 #endif // !Py_BUILD_CORE
207
208 static const char * const _keywords[] = {"length", NULL};
209 static _PyArg_Parser _parser = {
210 .keywords = _keywords,
211 .fname = "digest",
212 .kwtuple = KWTUPLE,
213 };
214 #undef KWTUPLE
215 PyObject *argsbuf[1];
216 unsigned long length;
217
218 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
219 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
220 if (!args) {
221 goto exit;
222 }
223 if (!_PyLong_UnsignedLong_Converter(args[0], &length)) {
224 goto exit;
225 }
226 return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length);
227
228 exit:
229 return return_value;
230 }
231
232 PyDoc_STRVAR(_sha3_shake_128_hexdigest__doc__,
233 "hexdigest($self, /, length)\n"
234 "--\n"
235 "\n"
236 "Return the digest value as a string of hexadecimal digits.");
237
238 #define _SHA3_SHAKE_128_HEXDIGEST_METHODDEF \
239 {"hexdigest", _PyCFunction_CAST(_sha3_shake_128_hexdigest), METH_FASTCALL|METH_KEYWORDS, _sha3_shake_128_hexdigest__doc__},
240
241 static PyObject *
242 _sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length);
243
244 static PyObject *
245 _sha3_shake_128_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
246 {
247 PyObject *return_value = NULL;
248 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
249
250 #define NUM_KEYWORDS 1
251 static struct {
252 PyGC_Head _this_is_not_used;
253 PyObject_VAR_HEAD
254 Py_hash_t ob_hash;
255 PyObject *ob_item[NUM_KEYWORDS];
256 } _kwtuple = {
257 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
258 .ob_hash = -1,
259 .ob_item = { &_Py_ID(length), },
260 };
261 #undef NUM_KEYWORDS
262 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
263
264 #else // !Py_BUILD_CORE
265 # define KWTUPLE NULL
266 #endif // !Py_BUILD_CORE
267
268 static const char * const _keywords[] = {"length", NULL};
269 static _PyArg_Parser _parser = {
270 .keywords = _keywords,
271 .fname = "hexdigest",
272 .kwtuple = KWTUPLE,
273 };
274 #undef KWTUPLE
275 PyObject *argsbuf[1];
276 unsigned long length;
277
278 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
279 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
280 if (!args) {
281 goto exit;
282 }
283 if (!_PyLong_UnsignedLong_Converter(args[0], &length)) {
284 goto exit;
285 }
286 return_value = _sha3_shake_128_hexdigest_impl((SHA3object *)self, length);
287
288 exit:
289 return return_value;
290 }
291 /*[clinic end generated code: output=65e437799472b89f input=a9049054013a1b77]*/