chiark / gitweb /
catacomb-python.h: Don't inhibit 64-bit type detection any more.
[catacomb-python] / pubkey.c
index e7bfb988865d933ab277632a32003ef1d8db18dd..4c4eb1dfbc40743ea7c342eea9dafde4a22c0a52 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Public-key cryptography
  *
  * (c) 2004 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the Python interface to Catacomb.
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * Catacomb/Python is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with Catacomb/Python; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -198,7 +196,7 @@ static PyMemberDef dsapub_pymembers[] = {
   MEMBER(G,    T_OBJECT, READONLY, "D.G -> group to work in")
   MEMBER(p,    T_OBJECT, READONLY, "D.p -> public key (group element")
   MEMBER(rng,  T_OBJECT, READONLY, "D.rng -> random number generator")
-  MEMBER(hash,         T_OBJECT, READONLY, "D.hash -> hash class")
+  MEMBER(hash, T_OBJECT, READONLY, "D.hash -> hash class")
 #undef MEMBERSTRUCT
   { 0 }
 };
@@ -212,7 +210,7 @@ static PyMemberDef dsapriv_pymembers[] = {
 
 static PyTypeObject dsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.DSAPub",                   /* @tp_name@ */
+  "DSAPub",                            /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -260,7 +258,7 @@ static PyTypeObject dsapub_pytype_skel = {
 
 static PyTypeObject dsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.DSAPriv",                  /* @tp_name@ */
+  "DSAPriv",                           /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -425,7 +423,7 @@ static PyMethodDef kcdsapriv_pymethods[] = {
 
 static PyTypeObject kcdsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.KCDSAPub",                 /* @tp_name@ */
+  "KCDSAPub",                          /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -473,7 +471,7 @@ static PyTypeObject kcdsapub_pytype_skel = {
 
 static PyTypeObject kcdsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.KCDSAPriv",                        /* @tp_name@ */
+  "KCDSAPriv",                         /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -555,6 +553,7 @@ static PyObject *rsapub_pynew(PyTypeObject *ty,
   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");
   o = (rsapub_pyobj *)ty->tp_alloc(ty, 0);
   o->pub = rp;
   rsa_pubcreate(&o->pubctx, &o->pub);
@@ -627,6 +626,10 @@ static PyObject *rsapriv_pynew(PyTypeObject *ty,
                                   convmp, &rp.q_inv,
                                   &rng))
     goto end;
+  if ((rp.n && !MP_ODDP(rp.n)) ||
+      (rp.p && !MP_ODDP(rp.p)) ||
+      (rp.p && !MP_ODDP(rp.q)))
+    VALERR("RSA modulus and factors must be odd");
   if (rsa_recover(&rp)) VALERR("couldn't construct private key");
   if (rng != Py_None && !GRAND_PYCHECK(rng))
     TYERR("not a random number source");
@@ -761,7 +764,7 @@ static PyMethodDef rsapriv_pymethods[] = {
 
 static PyTypeObject rsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.RSAPub",                   /* @tp_name@ */
+  "RSAPub",                            /* @tp_name@ */
   sizeof(rsapub_pyobj),                        /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -809,7 +812,7 @@ static PyTypeObject rsapub_pytype_skel = {
 
 static PyTypeObject rsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.RSAPriv",                  /* @tp_name@ */
+  "RSAPriv",                           /* @tp_name@ */
   sizeof(rsapriv_pyobj),               /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */