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