chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pubkey.c: Change the arguments to {DSA,KCDSA}{Pub,Priv}.
[catacomb-python]
/
pubkey.c
diff --git
a/pubkey.c
b/pubkey.c
index 5292717f5b4c0804783682a05f4c2876751cbc39..4067ae0ff10219ed5dbff4f24df93be1c4d41af7 100644
(file)
--- a/
pubkey.c
+++ b/
pubkey.c
@@
-54,26
+54,35
@@
static void dsa_pydealloc(PyObject *me)
}
static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u,
}
static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u,
- PyObject *p, PyObject *rng, PyObject *hash)
+ PyObject *p, PyObject *rng, PyObject *hash,
+ void (*calcpub)(group *, ge *, mp *))
{
dsa_pyobj *g;
{
dsa_pyobj *g;
+ ge *pp;
g = PyObject_New(dsa_pyobj, ty);
g = PyObject_New(dsa_pyobj, ty);
- if (GROUP_G(G) != GE_G(p) && !group_samep(GROUP_G(G), GE_G(p)))
- TYERR("public key not from group");
+ if (p) Py_INCREF(p);
if (!u) {
g->d.u = 0;
u = Py_None;
} else if ((g->d.u = getmp(u)) == 0)
goto end;
if (!u) {
g->d.u = 0;
u = Py_None;
} else if ((g->d.u = getmp(u)) == 0)
goto end;
+ if (!p) {
+ assert(g->d.u); assert(calcpub);
+ pp = G_CREATE(GROUP_G(G));
+ calcpub(GROUP_G(G), pp, g->d.u);
+ p = ge_pywrap(G, pp);
+ } else if (GROUP_G(G) != GE_G(p) && !group_samep(GROUP_G(G), GE_G(p)))
+ TYERR("public key not from group");
g->d.g = GROUP_G(G);
g->d.p = GE_X(p);
g->d.r = GRAND_R(rng);
g->d.h = GCHASH_CH(hash);
g->d.g = GROUP_G(G);
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;
Py_INCREF(p);
+ g->G = G; Py_INCREF(G); g->u = u; Py_INCREF(u); g->p = p;
g->rng = rng; Py_INCREF(rng); g->hash = hash; Py_INCREF(hash);
return ((PyObject *)g);
end:
g->rng = rng; Py_INCREF(rng); g->hash = hash; Py_INCREF(hash);
return ((PyObject *)g);
end:
+ if (p) Py_DECREF(p);
FREEOBJ(g);
return (0);
}
FREEOBJ(g);
return (0);
}
@@
-81,17
+90,16
@@
end:
static PyObject *dsapub_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
static PyObject *dsapub_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
- PyObject *G, *p, *
u = 0, *
rng = rand_pyobj, *hash = sha_pyobj;
+ PyObject *G, *p, *rng = rand_pyobj, *hash = sha_pyobj;
PyObject *rc = 0;
PyObject *rc = 0;
- char *kwlist[] = { "G", "p", "
u", "
hash", "rng", 0 };
+ char *kwlist[] = { "G", "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!:new", kwlist,
group_pytype, &G,
ge_pytype, &p,
group_pytype, &G,
ge_pytype, &p,
- &u,
gchash_pytype, &hash,
grand_pytype, &rng) ||
gchash_pytype, &hash,
grand_pytype, &rng) ||
- (rc = dsa_setup(dsapub_pytype, G,
u, p, rng, hash
)) == 0)
+ (rc = dsa_setup(dsapub_pytype, G,
0, p, rng, hash, 0
)) == 0)
goto end;
end:
return (rc);
goto end;
end:
return (rc);
@@
-156,20
+164,22
@@
end:
return (rc);
}
return (rc);
}
+static void dsa_calcpub(group *g, ge *p, mp *u) { G_EXP(g, p, g->g, u); }
+
static PyObject *dsapriv_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
static PyObject *dsapriv_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
- PyObject *G, *p
, *u = Py_None
, *rng = rand_pyobj, *hash = sha_pyobj;
+ PyObject *G, *p
= 0, *u
, *rng = rand_pyobj, *hash = sha_pyobj;
PyObject *rc = 0;
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,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O
|O!
O!O!:new", kwlist,
group_pytype, &G,
group_pytype, &G,
- ge_pytype, &p,
&u,
&u,
+ ge_pytype, &p,
gchash_pytype, &hash,
grand_pytype, &rng) ||
gchash_pytype, &hash,
grand_pytype, &rng) ||
- (rc = dsa_setup(dsapriv_pytype, G, u, p, rng, hash)) == 0)
+ (rc = dsa_setup(dsapriv_pytype, G, u, p, rng, hash
, dsa_calcpub
)) == 0)
goto end;
end:
return (rc);
goto end;
end:
return (rc);
@@
-307,36
+317,43
@@
static PyTypeObject dsapriv_pytype_skel = {
static PyObject *kcdsapub_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
static PyObject *kcdsapub_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
- PyObject *G, *p, *
u = 0, *
rng = rand_pyobj, *hash = has160_pyobj;
+ PyObject *G, *p, *rng = rand_pyobj, *hash = has160_pyobj;
PyObject *rc = 0;
PyObject *rc = 0;
- char *kwlist[] = { "G", "p", "
u", "
hash", "rng", 0 };
+ char *kwlist[] = { "G", "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!:new", kwlist,
group_pytype, &G,
ge_pytype, &p,
group_pytype, &G,
ge_pytype, &p,
- &u,
gchash_pytype, &hash,
grand_pytype, &rng) ||
gchash_pytype, &hash,
grand_pytype, &rng) ||
- (rc = dsa_setup(kcdsapub_pytype, G,
u, p, rng, hash
)) == 0)
+ (rc = dsa_setup(kcdsapub_pytype, G,
0, p, rng, hash, 0
)) == 0)
goto end;
end:
return (rc);
}
goto end;
end:
return (rc);
}
+static void kcdsa_calcpub(group *g, ge *p, mp *u)
+{
+ mp *uinv = mp_modinv(MP_NEW, u, g->r);
+ G_EXP(g, p, g->g, uinv);
+ mp_drop(uinv);
+}
+
static PyObject *kcdsapriv_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
static PyObject *kcdsapriv_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
{
- PyObject *G, *
p, *u = Py_None
, *rng = rand_pyobj, *hash = has160_pyobj;
+ PyObject *G, *
u, *p = 0
, *rng = rand_pyobj, *hash = has160_pyobj;
PyObject *rc = 0;
char *kwlist[] = { "G", "p", "u", "hash", "rng", 0 };
PyObject *rc = 0;
char *kwlist[] = { "G", "p", "u", "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,
group_pytype, &G,
- ge_pytype, &p,
&u,
&u,
+ ge_pytype, &p,
gchash_pytype, &hash,
grand_pytype, &rng) ||
gchash_pytype, &hash,
grand_pytype, &rng) ||
- (rc = dsa_setup(kcdsapriv_pytype, G, u, p, rng, hash)) == 0)
+ (rc = dsa_setup(kcdsapriv_pytype, G, u, p,
+ rng, hash, kcdsa_calcpub)) == 0)
goto end;
end:
return (rc);
goto end;
end:
return (rc);