summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDwayne C. Litzenberger <dlitz@dlitz.net>2012-07-03 11:49:41 -0400
committerDwayne C. Litzenberger <dlitz@dlitz.net>2012-07-03 11:50:55 -0400
commitb215cc9e18012d9b291ea8c0adc6eefa507dd3b1 (patch)
treeebaa1aba53a5f287b53d2082780bc10de6d5ffba /src
parentde048b4f50bf548993ef876de54ca72e9b45a8ae (diff)
downloadpycrypto-b215cc9e18012d9b291ea8c0adc6eefa507dd3b1.tar.gz
_fastmath: Propagate errors raised in rabinMillerTest
Diffstat (limited to 'src')
-rw-r--r--src/_fastmath.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/_fastmath.c b/src/_fastmath.c
index bb8e9d4..f05e70f 100644
--- a/src/_fastmath.c
+++ b/src/_fastmath.c
@@ -1097,8 +1097,9 @@ cleanup:
mpz_clear (n);
Py_END_ALLOW_THREADS;
- if (result == 0)
- {
+ if (result < 0) {
+ return NULL;
+ } else if (result == 0) {
Py_INCREF(Py_False);
return Py_False;
} else {
@@ -1323,6 +1324,7 @@ sieve_field (char *field, unsigned long int field_size, mpz_t start)
/* Tests if n is prime.
* Returns 0 when n is definitly composite.
* Returns 1 when n is probably prime.
+ * Returns -1 when there is an error.
* every round reduces the chance of a false positive be at least 1/4.
*
* If randfunc is omitted, then the python version Random.new().read is used.
@@ -1335,7 +1337,8 @@ static int
rabinMillerTest (mpz_t n, int rounds, PyObject *randfunc)
{
int base_was_tested;
- unsigned long int i, j, b, composite, return_val=1;
+ unsigned long int i, j, b, composite;
+ int return_val = 1;
mpz_t a, m, z, n_1, tmp;
mpz_t tested[MAX_RABIN_MILLER_ROUNDS];