[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Add test-vector support



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

Modified Files:
	_minionlib.h crypt.c main.c 
Log Message:
Add test-vector support

Index: _minionlib.h
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/_minionlib.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- _minionlib.h	14 Jul 2003 15:38:50 -0000	1.18
+++ _minionlib.h	2 Oct 2003 21:46:23 -0000	1.19
@@ -65,6 +65,7 @@
 FUNC_DOC(mm_sha1);
 FUNC_DOC(mm_aes_key);
 FUNC_DOC(mm_aes_ctr128_crypt);
+FUNC_DOC(mm_aes128_block_crypt);
 FUNC_DOC(mm_strxor);
 FUNC_DOC(mm_openssl_seed);
 #ifdef MS_WINDOWS

Index: crypt.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/crypt.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- crypt.c	4 Sep 2003 16:07:05 -0000	1.30
+++ crypt.c	2 Oct 2003 21:46:23 -0000	1.31
@@ -225,6 +225,45 @@
         return output;
 }
 
+const char mm_aes128_block_crypt__doc__[] = 
+"aes128_block_crypt(key, block, encrypt=0) -> result\n\n"
+"For testing only.  Encrypt or decrypt a single RSA block.\n";
+
+PyObject*
+mm_aes128_block_crypt(PyObject *self, PyObject *args, PyObject *kwdict)
+{
+        static char *kwlist[] = { "key", "block", "encrypt", NULL };
+        char *input;
+        long inputlen;
+        int encrypt=0;
+        PyObject *result;
+        AES_KEY *aes_key = NULL;        
+
+        if (!PyArg_ParseTupleAndKeywords(args, kwdict,
+                                         "O&s#|i:aes128_block_crypt", kwlist, 
+                                         aes_arg_convert, &aes_key,
+                                         &input, &inputlen,
+                                         &encrypt))
+                return NULL;
+        
+        if (inputlen != 16) {
+                TYPE_ERR("aes128_block_crypt expected a single block.");
+                return NULL;
+        }
+
+        if (!(result = PyString_FromStringAndSize(NULL, 16))) {
+                PyErr_NoMemory();
+                return NULL;
+        }
+        if (encrypt) {
+                AES_encrypt(input, PyString_AS_STRING(result), aes_key);
+        } else {
+                AES_decrypt(input, PyString_AS_STRING(result), aes_key);
+        }
+
+        return result;
+}
+
 const char mm_strxor__doc__[]=
   "strxor(str1, str2) -> str\n\n"
   "Computes the bitwise xor of two equally-long strings.  Throws TypeError\n"
@@ -849,6 +888,58 @@
         return output;
 }
 
+const char mm_RSA_get_private_key__doc__[]=
+"rsa.get_private_key() -> (n,e,d,p,q)\n";
+
+PyObject *
+mm_RSA_get_private_key(PyObject *self, PyObject *args, PyObject *kwdict)
+{
+        /* ???? should be threadified? */
+        static char *kwlist[] = {  NULL };
+
+        RSA *rsa;
+        PyObject *n, *e, *d, *p, *q;
+        PyObject *output;
+
+        n = e = d = p = q = NULL;
+
+        assert(mm_RSA_Check(self));
+        if (!PyArg_ParseTupleAndKeywords(args, kwdict,
+                                         ":get_private_key", kwlist))
+                return NULL;
+
+        rsa = ((mm_RSA*)self)->rsa;
+        if (!rsa->n) { TYPE_ERR("Key has no modulus"); return NULL;}
+        if (!rsa->e) { TYPE_ERR("Key has no e"); return NULL; }
+        if (!rsa->d) { TYPE_ERR("Key has no d"); return NULL; }
+        if (!rsa->p) { TYPE_ERR("Key has no p"); return NULL; }
+        if (!rsa->q) { TYPE_ERR("Key has no q"); return NULL; }
+        output = NULL;
+        if (!(n = bn2pylong(rsa->n))) {
+                PyErr_NoMemory(); goto done;
+        }
+        if (!(e = bn2pylong(rsa->e))) {
+                PyErr_NoMemory(); goto done;
+        }
+        if (!(d = bn2pylong(rsa->d))) {
+                PyErr_NoMemory(); goto done;
+        }
+        if (!(p = bn2pylong(rsa->p))) {
+                PyErr_NoMemory(); goto done;
+        }
+        if (!(q = bn2pylong(rsa->q))) {
+                PyErr_NoMemory(); goto done;
+        }
+        output = Py_BuildValue("OOOOO", n, e, d, p, q);
+ done:
+        if (n) { Py_DECREF(n); }
+        if (e) { Py_DECREF(e); }
+        if (d) { Py_DECREF(d); }
+        if (p) { Py_DECREF(p); }
+        if (q) { Py_DECREF(q); }
+        return output;
+}
+
 const char mm_RSA_get_exponent__doc__[]=
    "rsa.get_exponent() -> e\n";
 
@@ -931,6 +1022,7 @@
         METHOD(mm_RSA, get_public_key),
         METHOD(mm_RSA, get_exponent),
         METHOD(mm_RSA, PEM_write_key),
+        METHOD(mm_RSA, get_private_key),
         { NULL, NULL }
 };
 

Index: main.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/main.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- main.c	14 Jul 2003 15:38:50 -0000	1.19
+++ main.c	2 Oct 2003 21:46:23 -0000	1.20
@@ -29,6 +29,7 @@
         ENTRY(sha1),
         ENTRY(aes_key),
         ENTRY(aes_ctr128_crypt),
+        ENTRY(aes128_block_crypt),
         ENTRY(strxor),
         ENTRY(openssl_seed),
         ENTRY(openssl_rand),