algorithms.c (AEADAAD.copy): Propagate the hashed length to the copy.
[catacomb-python] / pubkey.c
index 0abb011..5680429 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -96,9 +96,9 @@ static PyObject *dsapub_pynew(PyTypeObject *ty,
 {
   PyObject *G, *p, *rng = rand_pyobj, *hash = sha_pyobj;
   PyObject *rc = 0;
-  char *kwlist[] = { "G", "p", "hash", "rng", 0 };
+  static const char *const kwlist[] = { "G", "p", "hash", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O!|O!O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O!|O!O!:new", KWLIST,
                                   group_pytype, &G,
                                   ge_pytype, &p,
                                   gchash_pytype, &hash,
@@ -112,7 +112,7 @@ end:
 static PyObject *dsameth_beginhash(PyObject *me, PyObject *arg)
 {
   if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me)), f_freeme));
+  return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me))));
 }
 
 static PyObject *dsameth_endhash(PyObject *me, PyObject *arg)
@@ -135,9 +135,9 @@ static PyObject *dsameth_sign(PyObject *me, PyObject *arg, PyObject *kw)
   Py_ssize_t n;
   mp *k = 0;
   PyObject *rc = 0;
-  char *kwlist[] = { "msg", "k", 0 };
+  static const char *const kwlist[] = { "msg", "k", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|O&:sign", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|O&:sign", KWLIST,
                                   &p, &n, convmp, &k))
     goto end;
   if (n != DSA_D(me)->h->hashsz)
@@ -175,9 +175,9 @@ static PyObject *dsapriv_pynew(PyTypeObject *ty,
 {
   PyObject *G, *p = 0, *u, *rng = rand_pyobj, *hash = sha_pyobj;
   PyObject *rc = 0;
-  char *kwlist[] = { "G", "u", "p", "hash", "rng", 0 };
+  static const char *const kwlist[] = { "G", "u", "p", "hash", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", KWLIST,
                                   group_pytype, &G,
                                   &u,
                                   ge_pytype, &p,
@@ -247,7 +247,7 @@ static PyTypeObject dsapub_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"DSA public key information.",
+"DSAPub(GROUP, P, [hash = sha], [rng = rand]): DSA public key.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -295,7 +295,7 @@ static PyTypeObject dsapriv_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"DSA private key information.",
+"DSAPriv(GROUP, U, [p = u G], [hash = sha], [rng = rand]): DSA private key.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -323,9 +323,9 @@ static PyObject *kcdsapub_pynew(PyTypeObject *ty,
 {
   PyObject *G, *p, *rng = rand_pyobj, *hash = has160_pyobj;
   PyObject *rc = 0;
-  char *kwlist[] = { "G", "p", "hash", "rng", 0 };
+  static const char *const kwlist[] = { "G", "p", "hash", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O!|O!O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O!|O!O!:new", KWLIST,
                                   group_pytype, &G,
                                   ge_pytype, &p,
                                   gchash_pytype, &hash,
@@ -348,9 +348,9 @@ static PyObject *kcdsapriv_pynew(PyTypeObject *ty,
 {
   PyObject *G, *u, *p = 0, *rng = rand_pyobj, *hash = has160_pyobj;
   PyObject *rc = 0;
-  char *kwlist[] = { "G", "u", "p", "hash", "rng", 0 };
+  static const char *const kwlist[] = { "G", "u", "p", "hash", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", KWLIST,
                                   group_pytype, &G,
                                   &u,
                                   ge_pytype, &p,
@@ -366,7 +366,7 @@ end:
 static PyObject *kcdsameth_beginhash(PyObject *me, PyObject *arg)
 {
   if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me)), f_freeme));
+  return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me))));
 }
 
 static PyObject *kcdsameth_endhash(PyObject *me, PyObject *arg)
@@ -389,9 +389,9 @@ static PyObject *kcdsameth_sign(PyObject *me, PyObject *arg, PyObject *kw)
   Py_ssize_t n;
   mp *k = 0;
   PyObject *r = 0, *rc = 0;
-  char *kwlist[] = { "msg", "k", 0 };
+  static const char *const kwlist[] = { "msg", "k", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|O&:sign", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|O&:sign", KWLIST,
                                   &p, &n, convmp, &k))
     goto end;
   if (n != DSA_D(me)->h->hashsz)
@@ -467,7 +467,7 @@ static PyTypeObject kcdsapub_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"KCDSA public key information.",
+"KCDSAPub(GROUP, P, [hash = sha], [rng = rand]): KCDSA public key.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -515,7 +515,7 @@ static PyTypeObject kcdsapriv_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"KCDSA private key information.",
+"KCDSAPriv(GROUP, U, [p = u G], [hash = sha], [rng = rand]): KCDSA private key.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -569,9 +569,9 @@ static PyObject *rsapub_pynew(PyTypeObject *ty,
 {
   rsa_pub rp = { 0 };
   rsapub_pyobj *o;
-  char *kwlist[] = { "n", "e", 0 };
+  static const char *const kwlist[] = { "n", "e", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", KWLIST,
                                   convmp, &rp.n, convmp, &rp.e))
     goto end;
   if (!MP_ODDP(rp.n)) VALERR("RSA modulus must be even");
@@ -636,10 +636,10 @@ static PyObject *rsapriv_pynew(PyTypeObject *ty,
 {
   rsa_priv rp = { 0 };
   PyObject *rng = Py_None;
-  char *kwlist[] =
+  static const char *const kwlist[] =
     { "n", "e", "d", "p", "q", "dp", "dq", "q_inv", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&O&O&O&O&O&O&O:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&O&O&O&O&O&O&O:new", KWLIST,
                                   convmp, &rp.n, convmp, &rp.e,
                                   convmp, &rp.d,
                                   convmp, &rp.p, convmp, &rp.q,
@@ -711,9 +711,9 @@ static PyObject *rsameth_privop(PyObject *me, PyObject *arg, PyObject *kw)
   PyObject *rng = RSA_RNG(me);
   mp *x = 0;
   PyObject *rc = 0;
-  char *kwlist[] = { "x", "rng", 0 };
+  static const char *const kwlist[] = { "x", "rng", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O:privop", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O:privop", KWLIST,
                                   convmp, &x, &rng))
     goto end;
   if (rng != Py_None && !GRAND_PYCHECK(rng))
@@ -735,11 +735,12 @@ static PyObject *meth__RSAPriv_generate(PyObject *me,
   mp *e = 0;
   struct excinfo exc = EXCINFO_INIT;
   pypgev evt = { { 0 } };
-  char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", "e", 0 };
+  static const char *const kwlist[] =
+    { "class", "nbits", "event", "rng", "nsteps", "e", 0 };
   PyObject *rc = 0;
 
   evt.exc = &exc;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST,
                                   &me, convuint, &nbits, convpgev, &evt,
                                   convgrand, &r, convuint, &n,
                                   convmp, &e))
@@ -815,7 +816,7 @@ static PyTypeObject rsapub_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"RSA public key information.",
+"RSAPub(N, E): RSA public key.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -863,7 +864,8 @@ static PyTypeObject rsapriv_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"RSA private key information.",
+"RSAPriv(..., [rng = rand]): RSA private key.\n\
+  Keywords: n, e, d, p, q, dp, dq, q_inv; must provide enough",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -899,10 +901,10 @@ static PyObject *meth__p1crypt_encode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x;
-  char *kwlist[] = { "msg", "nbits", "ep", "rng", 0 };
+  static const char *const kwlist[] = { "msg", "nbits", "ep", "rng", 0 };
 
   p1.r = &rand_global; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|s#O&:encode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|s#O&:encode", KWLIST,
                                   &m, &msz, convulong, &nbits,
                                   &ep, &epsz, convgrand, &p1.r))
     goto end;
@@ -929,10 +931,10 @@ static PyObject *meth__p1crypt_decode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x = 0;
-  char *kwlist[] = { "ct", "nbits", "ep", "rng", 0 };
+  static const char *const kwlist[] = { "ct", "nbits", "ep", "rng", 0 };
 
   p1.r = &rand_global; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|s#O&:decode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|s#O&:decode", KWLIST,
                                   convmp, &x, convulong, &nbits,
                                   &ep, &epsz, convgrand, &p1.r))
     goto end;
@@ -960,10 +962,10 @@ static PyObject *meth__p1sig_encode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x;
-  char *kwlist[] = { "msg", "nbits", "ep", "rng", 0 };
+  static const char *const kwlist[] = { "msg", "nbits", "ep", "rng", 0 };
 
   p1.r = &rand_global; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|s#O&:encode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|s#O&:encode", KWLIST,
                                   &m, &msz, convulong, &nbits,
                                   &ep, &epsz, convgrand, &p1.r))
     goto end;
@@ -991,10 +993,11 @@ static PyObject *meth__p1sig_decode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x = 0;
-  char *kwlist[] = { "msg", "sig", "nbits", "ep", "rng", 0 };
+  static const char *const kwlist[] =
+    { "msg", "sig", "nbits", "ep", "rng", 0 };
 
   p1.r = &rand_global; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|s#O&:decode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|s#O&:decode", KWLIST,
                                   &hukairz, convmp, &x, convulong, &nbits,
                                   &ep, &epsz, convgrand, &p1.r))
     goto end;
@@ -1022,10 +1025,11 @@ static PyObject *meth__oaep_encode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x;
-  char *kwlist[] = { "msg", "nbits", "mgf", "hash", "ep", "rng", 0 };
+  static const char *const kwlist[] =
+    { "msg", "nbits", "mgf", "hash", "ep", "rng", 0 };
 
   o.r = &rand_global; o.cc = &sha_mgf; o.ch = &sha; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|O&O&s#O&:encode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|O&O&s#O&:encode", KWLIST,
                                   &m, &msz, convulong, &nbits,
                                   convgccipher, &o.cc,
                                   convgchash, &o.ch,
@@ -1055,10 +1059,11 @@ static PyObject *meth__oaep_decode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x = 0;
-  char *kwlist[] = { "ct", "nbits", "mgf", "hash", "ep", "rng", 0 };
+  static const char *const kwlist[] =
+    { "ct", "nbits", "mgf", "hash", "ep", "rng", 0 };
 
   o.r = &rand_global; o.cc = &sha_mgf; o.ch = &sha; ep = 0; epsz = 0;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|O&O&s#O&:decode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|O&O&s#O&:decode", KWLIST,
                                   convmp, &x, convulong, &nbits,
                                   convgccipher, &o.cc,
                                   convgchash, &o.ch,
@@ -1089,10 +1094,11 @@ static PyObject *meth__pss_encode(PyObject *me,
   octet *b = 0;
   size_t sz;
   mp *x = 0;
-  char *kwlist[] = { "msg", "nbits", "mgf", "hash", "saltsz", "rng", 0 };
+  static const char *const kwlist[] =
+    { "msg", "nbits", "mgf", "hash", "saltsz", "rng", 0 };
 
   p.cc = &sha_mgf; p.ch = &sha; p.r = &rand_global; p.ssz = (size_t)-1;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|O&O&O&O&:encode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&|O&O&O&O&:encode", KWLIST,
                                   &m, &msz, convulong, &nbits,
                                   convgccipher, &p.cc,
                                   convgchash, &p.ch,
@@ -1122,11 +1128,11 @@ static PyObject *meth__pss_decode(PyObject *me,
   size_t sz;
   int n;
   mp *x = 0;
-  char *kwlist[] =
+  static const char *const kwlist[] =
     { "msg", "sig", "nbits", "mgf", "hash", "saltsz", "rng", 0 };
 
   p.cc = &sha_mgf; p.ch = &sha; p.r = &rand_global; p.ssz = (size_t)-1;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&O&|O&O&O&O&:decode", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&O&|O&O&O&O&:decode", KWLIST,
                                   &m, &msz, convmp, &x, convulong, &nbits,
                                   convgccipher, &p.cc,
                                   convgchash, &p.ch,
@@ -1202,10 +1208,11 @@ XDHS(DEFXDH)
     int ph = phdflt;                                                   \
     PyObject *rc = 0;                                                  \
     octet pp[ED##_PUBSZ];                                              \
-    char *kwlist[] = { "key", "msg", "pub", "perso", "phflag", 0 };    \
+    static const char *const kwlist[] =                                        \
+      { "key", "msg", "pub", "perso", "phflag", 0 };                   \
     if (!PyArg_ParseTupleAndKeywords(arg, kw,                          \
                                     "s#s#|s#s#O&:" #ed "_sign",        \
-                                    kwlist,                            \
+                                    KWLIST,                            \
                                     &k, &ksz, &m, &msz, &p, &psz,      \
                                     &c, &csz, convbool, &ph))          \
       goto end;                                                                \
@@ -1229,10 +1236,11 @@ XDHS(DEFXDH)
     Py_ssize_t psz, csz = 0, msz, ssz;                                 \
     int ph = phdflt;                                                   \
     PyObject *rc = 0;                                                  \
-    char *kwlist[] = { "pub", "msg", "sig", "perso", "phflag", 0 };    \
+    static const char *const kwlist[] =                                        \
+      { "pub", "msg", "sig", "perso", "phflag", 0 };                   \
     if (!PyArg_ParseTupleAndKeywords(arg, kw,                          \
                                     "s#s#s#|s#O&:" #ed "_verify",      \
-                                    kwlist,                            \
+                                    KWLIST,                            \
                                     &p, &psz, &m, &msz, &s, &ssz,      \
                                     &c, &csz, convbool, &ph))          \
       goto end;                                                                \