[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Converting an RSA key"s modulus to a Python long is too...



Update of /home/minion/cvsroot/src/minion/src
In directory moria.mit.edu:/tmp/cvs-serv3693/src

Modified Files:
	crypt.c 
Log Message:
Converting an RSA key's modulus to a Python long is too expensive when
we only want to check that its exponent == 65537; add a "get_exponent"
method to facilitate this.


Index: crypt.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/crypt.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- crypt.c	16 Dec 2002 15:18:33 -0000	1.16
+++ crypt.c	29 Dec 2002 20:30:41 -0000	1.17
@@ -634,7 +634,7 @@
 
         assert(mm_RSA_Check(self));
         if (!PyArg_ParseTupleAndKeywords(args, kwdict,
-                                         ":rsa_get_public_key", kwlist))
+                                         ":get_public_key", kwlist))
                 return NULL;
 
         rsa = ((mm_RSA*)self)->rsa;
@@ -652,6 +652,30 @@
         return output;
 }
 
+const char mm_RSA_get_exponent__doc__[]=
+   "rsa.get_exponent() -> e\n";
+
+PyObject *
+mm_RSA_get_exponent(PyObject *self, PyObject *args, PyObject *kwdict)
+{
+        static char *kwlist[] = {  NULL };
+
+        RSA *rsa;
+        PyObject *e;
+
+        assert(mm_RSA_Check(self));
+        if (!PyArg_ParseTupleAndKeywords(args, kwdict,
+                                         ":get_exponent", kwlist))
+                return NULL;
+
+        rsa = ((mm_RSA*)self)->rsa;
+        if (!rsa->e) { TYPE_ERR("Key has no e"); return NULL; }
+        if (!(e = bn2pylong(rsa->e))) {
+                PyErr_NoMemory(); return NULL;
+        }
+        return e;
+}
+
 const char mm_rsa_make_public_key__doc__[]=
    "rsa_make_public_key(n,e) -> rsa\n\n"
    "n and e must both be long integers.  Ints won't work.\n";
@@ -706,6 +730,7 @@
         METHOD(mm_RSA, encode_key),
         METHOD(mm_RSA, get_modulus_bytes),
         METHOD(mm_RSA, get_public_key),
+        METHOD(mm_RSA, get_exponent),
         METHOD(mm_RSA, PEM_write_key),
         { NULL, NULL }
 };