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