1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(py_blake2s_new__doc__,
6 "blake2s(data=b\'\', /, *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
7 " key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
8 " node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
9 " usedforsecurity=True)\n"
10 "--\n"
11 "\n"
12 "Return a new BLAKE2s hash object.");
13
14 static PyObject *
15 py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
16 Py_buffer *key, Py_buffer *salt, Py_buffer *person,
17 int fanout, int depth, unsigned long leaf_size,
18 unsigned long long node_offset, int node_depth,
19 int inner_size, int last_node, int usedforsecurity);
20
21 static PyObject *
py_blake2s_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)22 py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24 PyObject *return_value = NULL;
25 static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", NULL};
26 static _PyArg_Parser _parser = {NULL, _keywords, "blake2s", 0};
27 PyObject *argsbuf[13];
28 PyObject * const *fastargs;
29 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
30 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
31 PyObject *data = NULL;
32 int digest_size = BLAKE2S_OUTBYTES;
33 Py_buffer key = {NULL, NULL};
34 Py_buffer salt = {NULL, NULL};
35 Py_buffer person = {NULL, NULL};
36 int fanout = 1;
37 int depth = 1;
38 unsigned long leaf_size = 0;
39 unsigned long long node_offset = 0;
40 int node_depth = 0;
41 int inner_size = 0;
42 int last_node = 0;
43 int usedforsecurity = 1;
44
45 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
46 if (!fastargs) {
47 goto exit;
48 }
49 if (nargs < 1) {
50 goto skip_optional_posonly;
51 }
52 noptargs--;
53 data = fastargs[0];
54 skip_optional_posonly:
55 if (!noptargs) {
56 goto skip_optional_kwonly;
57 }
58 if (fastargs[1]) {
59 digest_size = _PyLong_AsInt(fastargs[1]);
60 if (digest_size == -1 && PyErr_Occurred()) {
61 goto exit;
62 }
63 if (!--noptargs) {
64 goto skip_optional_kwonly;
65 }
66 }
67 if (fastargs[2]) {
68 if (PyObject_GetBuffer(fastargs[2], &key, PyBUF_SIMPLE) != 0) {
69 goto exit;
70 }
71 if (!PyBuffer_IsContiguous(&key, 'C')) {
72 _PyArg_BadArgument("blake2s", "argument 'key'", "contiguous buffer", fastargs[2]);
73 goto exit;
74 }
75 if (!--noptargs) {
76 goto skip_optional_kwonly;
77 }
78 }
79 if (fastargs[3]) {
80 if (PyObject_GetBuffer(fastargs[3], &salt, PyBUF_SIMPLE) != 0) {
81 goto exit;
82 }
83 if (!PyBuffer_IsContiguous(&salt, 'C')) {
84 _PyArg_BadArgument("blake2s", "argument 'salt'", "contiguous buffer", fastargs[3]);
85 goto exit;
86 }
87 if (!--noptargs) {
88 goto skip_optional_kwonly;
89 }
90 }
91 if (fastargs[4]) {
92 if (PyObject_GetBuffer(fastargs[4], &person, PyBUF_SIMPLE) != 0) {
93 goto exit;
94 }
95 if (!PyBuffer_IsContiguous(&person, 'C')) {
96 _PyArg_BadArgument("blake2s", "argument 'person'", "contiguous buffer", fastargs[4]);
97 goto exit;
98 }
99 if (!--noptargs) {
100 goto skip_optional_kwonly;
101 }
102 }
103 if (fastargs[5]) {
104 fanout = _PyLong_AsInt(fastargs[5]);
105 if (fanout == -1 && PyErr_Occurred()) {
106 goto exit;
107 }
108 if (!--noptargs) {
109 goto skip_optional_kwonly;
110 }
111 }
112 if (fastargs[6]) {
113 depth = _PyLong_AsInt(fastargs[6]);
114 if (depth == -1 && PyErr_Occurred()) {
115 goto exit;
116 }
117 if (!--noptargs) {
118 goto skip_optional_kwonly;
119 }
120 }
121 if (fastargs[7]) {
122 if (!_PyLong_UnsignedLong_Converter(fastargs[7], &leaf_size)) {
123 goto exit;
124 }
125 if (!--noptargs) {
126 goto skip_optional_kwonly;
127 }
128 }
129 if (fastargs[8]) {
130 if (!_PyLong_UnsignedLongLong_Converter(fastargs[8], &node_offset)) {
131 goto exit;
132 }
133 if (!--noptargs) {
134 goto skip_optional_kwonly;
135 }
136 }
137 if (fastargs[9]) {
138 node_depth = _PyLong_AsInt(fastargs[9]);
139 if (node_depth == -1 && PyErr_Occurred()) {
140 goto exit;
141 }
142 if (!--noptargs) {
143 goto skip_optional_kwonly;
144 }
145 }
146 if (fastargs[10]) {
147 inner_size = _PyLong_AsInt(fastargs[10]);
148 if (inner_size == -1 && PyErr_Occurred()) {
149 goto exit;
150 }
151 if (!--noptargs) {
152 goto skip_optional_kwonly;
153 }
154 }
155 if (fastargs[11]) {
156 last_node = PyObject_IsTrue(fastargs[11]);
157 if (last_node < 0) {
158 goto exit;
159 }
160 if (!--noptargs) {
161 goto skip_optional_kwonly;
162 }
163 }
164 usedforsecurity = PyObject_IsTrue(fastargs[12]);
165 if (usedforsecurity < 0) {
166 goto exit;
167 }
168 skip_optional_kwonly:
169 return_value = py_blake2s_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
170
171 exit:
172 /* Cleanup for key */
173 if (key.obj) {
174 PyBuffer_Release(&key);
175 }
176 /* Cleanup for salt */
177 if (salt.obj) {
178 PyBuffer_Release(&salt);
179 }
180 /* Cleanup for person */
181 if (person.obj) {
182 PyBuffer_Release(&person);
183 }
184
185 return return_value;
186 }
187
188 PyDoc_STRVAR(_blake2_blake2s_copy__doc__,
189 "copy($self, /)\n"
190 "--\n"
191 "\n"
192 "Return a copy of the hash object.");
193
194 #define _BLAKE2_BLAKE2S_COPY_METHODDEF \
195 {"copy", (PyCFunction)_blake2_blake2s_copy, METH_NOARGS, _blake2_blake2s_copy__doc__},
196
197 static PyObject *
198 _blake2_blake2s_copy_impl(BLAKE2sObject *self);
199
200 static PyObject *
_blake2_blake2s_copy(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))201 _blake2_blake2s_copy(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
202 {
203 return _blake2_blake2s_copy_impl(self);
204 }
205
206 PyDoc_STRVAR(_blake2_blake2s_update__doc__,
207 "update($self, data, /)\n"
208 "--\n"
209 "\n"
210 "Update this hash object\'s state with the provided bytes-like object.");
211
212 #define _BLAKE2_BLAKE2S_UPDATE_METHODDEF \
213 {"update", (PyCFunction)_blake2_blake2s_update, METH_O, _blake2_blake2s_update__doc__},
214
215 PyDoc_STRVAR(_blake2_blake2s_digest__doc__,
216 "digest($self, /)\n"
217 "--\n"
218 "\n"
219 "Return the digest value as a bytes object.");
220
221 #define _BLAKE2_BLAKE2S_DIGEST_METHODDEF \
222 {"digest", (PyCFunction)_blake2_blake2s_digest, METH_NOARGS, _blake2_blake2s_digest__doc__},
223
224 static PyObject *
225 _blake2_blake2s_digest_impl(BLAKE2sObject *self);
226
227 static PyObject *
_blake2_blake2s_digest(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))228 _blake2_blake2s_digest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
229 {
230 return _blake2_blake2s_digest_impl(self);
231 }
232
233 PyDoc_STRVAR(_blake2_blake2s_hexdigest__doc__,
234 "hexdigest($self, /)\n"
235 "--\n"
236 "\n"
237 "Return the digest value as a string of hexadecimal digits.");
238
239 #define _BLAKE2_BLAKE2S_HEXDIGEST_METHODDEF \
240 {"hexdigest", (PyCFunction)_blake2_blake2s_hexdigest, METH_NOARGS, _blake2_blake2s_hexdigest__doc__},
241
242 static PyObject *
243 _blake2_blake2s_hexdigest_impl(BLAKE2sObject *self);
244
245 static PyObject *
_blake2_blake2s_hexdigest(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))246 _blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
247 {
248 return _blake2_blake2s_hexdigest_impl(self);
249 }
250 /*[clinic end generated code: output=f7ee8092ed67e9c7 input=a9049054013a1b77]*/
251