CVS: crypto/src _fastmath.c,1.1,1.2
"A.M. Kuchling" <[email protected]> Thu, 03 Apr 2003 10:36:50 -0800
| Newsgroups | gmane.comp.python.cryptography.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/pycrypto/crypto/src
In directory sc8-pr-cvs1:/tmp/cvs-serv13258
Modified Files:
_fastmath.c
Log Message:
Add isPrime() function; move method definition list to end of file
Index: _fastmath.c
===================================================================
RCS file: /cvsroot/pycrypto/crypto/src/_fastmath.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- _fastmath.c 3 Apr 2003 18:17:41 -0000 1.1
+++ _fastmath.c 3 Apr 2003 18:36:37 -0000 1.2
@@ -74,12 +74,6 @@
PyObject *rsaKey_new (PyObject *, PyObject *);
PyObject *dsaKey_new (PyObject *, PyObject *);
-static PyMethodDef _fastmath__methods__[] = {
- {"dsa_construct", dsaKey_new, METH_VARARGS},
- {"rsa_construct", rsaKey_new, METH_VARARGS},
- {NULL, NULL}
-};
-
typedef struct
{
PyObject_HEAD mpz_t n;
@@ -224,9 +218,9 @@
sizeof (rsaKey),
0,
(destructor) rsaKey_dealloc, /* dealloc */
- 0, /* print */
+ 0, /* print */
(getattrfunc) rsaKey_getattr, /* getattr */
- 0, /* setattr */
+ 0, /* setattr */
0, /* compare */
0, /* repr */
0, /* as_number */
@@ -578,6 +572,41 @@
return Py_BuildValue ("i", 1);
}
+
+PyObject *
+isPrime (PyObject * self, PyObject * args)
+{
+ PyObject *l;
+ mpz_t n;
+ int result;
+
+ if (!(PyArg_ParseTuple (args, "O!", &PyLong_Type, &l)))
+ {
+ return NULL;
+ }
+ mpz_init (n);
+ longObjToMPZ (n, (PyLongObject *) l);
+
+ result = mpz_probab_prime_p(n, 5);
+
+ mpz_clear (n);
+
+ if (result == 0) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ } else {
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
+}
+
+
+static PyMethodDef _fastmath__methods__[] = {
+ {"dsa_construct", dsaKey_new, METH_VARARGS},
+ {"rsa_construct", rsaKey_new, METH_VARARGS},
+ {"isPrime", isPrime, METH_VARARGS},
+ {NULL, NULL}
+};
void
init_fastmath (void)
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/