• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)\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, int usedforsecurity);
20 
21 static PyObject *
py_sha3_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)22 py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24     PyObject *return_value = NULL;
25     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
26 
27     #define NUM_KEYWORDS 1
28     static struct {
29         PyGC_Head _this_is_not_used;
30         PyObject_VAR_HEAD
31         PyObject *ob_item[NUM_KEYWORDS];
32     } _kwtuple = {
33         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
34         .ob_item = { &_Py_ID(usedforsecurity), },
35     };
36     #undef NUM_KEYWORDS
37     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
38 
39     #else  // !Py_BUILD_CORE
40     #  define KWTUPLE NULL
41     #endif  // !Py_BUILD_CORE
42 
43     static const char * const _keywords[] = {"", "usedforsecurity", NULL};
44     static _PyArg_Parser _parser = {
45         .keywords = _keywords,
46         .fname = "sha3_224",
47         .kwtuple = KWTUPLE,
48     };
49     #undef KWTUPLE
50     PyObject *argsbuf[2];
51     PyObject * const *fastargs;
52     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
53     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
54     PyObject *data = NULL;
55     int usedforsecurity = 1;
56 
57     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
58     if (!fastargs) {
59         goto exit;
60     }
61     if (nargs < 1) {
62         goto skip_optional_posonly;
63     }
64     noptargs--;
65     data = fastargs[0];
66 skip_optional_posonly:
67     if (!noptargs) {
68         goto skip_optional_kwonly;
69     }
70     usedforsecurity = PyObject_IsTrue(fastargs[1]);
71     if (usedforsecurity < 0) {
72         goto exit;
73     }
74 skip_optional_kwonly:
75     return_value = py_sha3_new_impl(type, data, usedforsecurity);
76 
77 exit:
78     return return_value;
79 }
80 
81 PyDoc_STRVAR(_sha3_sha3_224_copy__doc__,
82 "copy($self, /)\n"
83 "--\n"
84 "\n"
85 "Return a copy of the hash object.");
86 
87 #define _SHA3_SHA3_224_COPY_METHODDEF    \
88     {"copy", (PyCFunction)_sha3_sha3_224_copy, METH_NOARGS, _sha3_sha3_224_copy__doc__},
89 
90 static PyObject *
91 _sha3_sha3_224_copy_impl(SHA3object *self);
92 
93 static PyObject *
_sha3_sha3_224_copy(SHA3object * self,PyObject * Py_UNUSED (ignored))94 _sha3_sha3_224_copy(SHA3object *self, PyObject *Py_UNUSED(ignored))
95 {
96     return _sha3_sha3_224_copy_impl(self);
97 }
98 
99 PyDoc_STRVAR(_sha3_sha3_224_digest__doc__,
100 "digest($self, /)\n"
101 "--\n"
102 "\n"
103 "Return the digest value as a bytes object.");
104 
105 #define _SHA3_SHA3_224_DIGEST_METHODDEF    \
106     {"digest", (PyCFunction)_sha3_sha3_224_digest, METH_NOARGS, _sha3_sha3_224_digest__doc__},
107 
108 static PyObject *
109 _sha3_sha3_224_digest_impl(SHA3object *self);
110 
111 static PyObject *
_sha3_sha3_224_digest(SHA3object * self,PyObject * Py_UNUSED (ignored))112 _sha3_sha3_224_digest(SHA3object *self, PyObject *Py_UNUSED(ignored))
113 {
114     return _sha3_sha3_224_digest_impl(self);
115 }
116 
117 PyDoc_STRVAR(_sha3_sha3_224_hexdigest__doc__,
118 "hexdigest($self, /)\n"
119 "--\n"
120 "\n"
121 "Return the digest value as a string of hexadecimal digits.");
122 
123 #define _SHA3_SHA3_224_HEXDIGEST_METHODDEF    \
124     {"hexdigest", (PyCFunction)_sha3_sha3_224_hexdigest, METH_NOARGS, _sha3_sha3_224_hexdigest__doc__},
125 
126 static PyObject *
127 _sha3_sha3_224_hexdigest_impl(SHA3object *self);
128 
129 static PyObject *
_sha3_sha3_224_hexdigest(SHA3object * self,PyObject * Py_UNUSED (ignored))130 _sha3_sha3_224_hexdigest(SHA3object *self, PyObject *Py_UNUSED(ignored))
131 {
132     return _sha3_sha3_224_hexdigest_impl(self);
133 }
134 
135 PyDoc_STRVAR(_sha3_sha3_224_update__doc__,
136 "update($self, data, /)\n"
137 "--\n"
138 "\n"
139 "Update this hash object\'s state with the provided bytes-like object.");
140 
141 #define _SHA3_SHA3_224_UPDATE_METHODDEF    \
142     {"update", (PyCFunction)_sha3_sha3_224_update, METH_O, _sha3_sha3_224_update__doc__},
143 
144 PyDoc_STRVAR(_sha3_shake_128_digest__doc__,
145 "digest($self, length, /)\n"
146 "--\n"
147 "\n"
148 "Return the digest value as a bytes object.");
149 
150 #define _SHA3_SHAKE_128_DIGEST_METHODDEF    \
151     {"digest", (PyCFunction)_sha3_shake_128_digest, METH_O, _sha3_shake_128_digest__doc__},
152 
153 static PyObject *
154 _sha3_shake_128_digest_impl(SHA3object *self, unsigned long length);
155 
156 static PyObject *
_sha3_shake_128_digest(SHA3object * self,PyObject * arg)157 _sha3_shake_128_digest(SHA3object *self, PyObject *arg)
158 {
159     PyObject *return_value = NULL;
160     unsigned long length;
161 
162     if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
163         goto exit;
164     }
165     return_value = _sha3_shake_128_digest_impl(self, length);
166 
167 exit:
168     return return_value;
169 }
170 
171 PyDoc_STRVAR(_sha3_shake_128_hexdigest__doc__,
172 "hexdigest($self, length, /)\n"
173 "--\n"
174 "\n"
175 "Return the digest value as a string of hexadecimal digits.");
176 
177 #define _SHA3_SHAKE_128_HEXDIGEST_METHODDEF    \
178     {"hexdigest", (PyCFunction)_sha3_shake_128_hexdigest, METH_O, _sha3_shake_128_hexdigest__doc__},
179 
180 static PyObject *
181 _sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length);
182 
183 static PyObject *
_sha3_shake_128_hexdigest(SHA3object * self,PyObject * arg)184 _sha3_shake_128_hexdigest(SHA3object *self, PyObject *arg)
185 {
186     PyObject *return_value = NULL;
187     unsigned long length;
188 
189     if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
190         goto exit;
191     }
192     return_value = _sha3_shake_128_hexdigest_impl(self, length);
193 
194 exit:
195     return return_value;
196 }
197 /*[clinic end generated code: output=a8e76a880d1421ec input=a9049054013a1b77]*/
198