chiark / gitweb /
Merge remote-tracking branch 'origin/HEAD'
[catacomb-python] / pubkey.c
index 73744299be232a845a2804ce30397c8c59d71cae..5167a973791f1930f18b4b7831a6ce6d4aa240ea 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -65,8 +65,12 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u,
   if (!u) {
     g->d.u = 0;
     u = Py_None;
-  } else if ((g->d.u = getmp(u)) == 0)
-    goto end;
+  } else {
+    if ((g->d.u = getmp(u)) == 0)
+      goto end;
+    if (MP_PYCHECK(u)) Py_INCREF(u);
+    else u = mp_pywrap(g->d.u);
+  }
   if (!p) {
     assert(g->d.u); assert(calcpub);
     pp = G_CREATE(GROUP_G(G));
@@ -78,7 +82,7 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u,
   g->d.p = GE_X(p);
   g->d.r = GRAND_R(rng);
   g->d.h = GCHASH_CH(hash);
-  g->G = G; Py_INCREF(G); g->u = u; Py_INCREF(u); g->p = p;
+  g->G = G; Py_INCREF(G); g->u = u; g->p = p;
   g->rng = rng; Py_INCREF(rng); g->hash = hash; Py_INCREF(hash);
   return ((PyObject *)g);
 end:
@@ -344,7 +348,7 @@ static PyObject *kcdsapriv_pynew(PyTypeObject *ty,
 {
   PyObject *G, *u, *p = 0, *rng = rand_pyobj, *hash = has160_pyobj;
   PyObject *rc = 0;
-  char *kwlist[] = { "G", "p", "u", "hash", "rng", 0 };
+  char *kwlist[] = { "G", "u", "p", "hash", "rng", 0 };
 
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", kwlist,
                                   group_pytype, &G,
@@ -728,19 +732,24 @@ static PyObject *meth__RSAPriv_generate(PyObject *me,
   unsigned nbits;
   unsigned n = 0;
   rsa_priv rp;
+  mp *e = 0;
   pgev evt = { 0 };
-  char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", 0 };
+  char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", "e", 0 };
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|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))
+                                  convgrand, &r, convuint, &n,
+                                  convmp, &e))
     goto end;
-  if (rsa_gen(&rp, nbits, r, n, evt.proc, evt.ctx))
+  if (e) MP_COPY(e);
+  else e = mp_fromulong(MP_NEW, 65537);
+  if (rsa_gen_e(&rp, nbits, e, r, n, evt.proc, evt.ctx))
     PGENERR;
   rc = rsapriv_pywrap(&rp);
 end:
   droppgev(&evt);
+  mp_drop(e);
   return (rc);
 }
 
@@ -1164,7 +1173,8 @@ XDHS(DEFXDH)
 /*----- Ed25519 and related algorithms ------------------------------------*/
 
 #define EDDSAS(_)                                                      \
-  _(ED25519, ed25519, -1, ctx)
+  _(ED25519, ed25519, -1, ctx)                                         \
+  _(ED448, ed448, 0, )
 
 #define DEFEDDSA(ED, ed, phdflt, sigver)                               \
                                                                        \