diff options
author | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2010-08-02 16:58:07 -0400 |
---|---|---|
committer | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2010-08-02 17:03:29 -0400 |
commit | 79f6c64c58cfb8795fa40b6999a89219ac9f102d (patch) | |
tree | 7d6b8cb8a98aa81735e6f6e457d38a1ef1047054 /src/_fastmath.c | |
parent | 902ea14fc2d3d4a6e01afbef6f45115ab37e7fcd (diff) | |
download | pycrypto-79f6c64c58cfb8795fa40b6999a89219ac9f102d.tar.gz |
getRandomNumber API compatibility:
Legrandin's getStrongPrime() patch changed the behaviour of
Crypto.Util.number.getRandomNumber() to something that is more like what
people would expect, but different from what we did before. This change
modifies Crypto.Util.number in the following ways:
- Rename getRandomNBitNumber -> getRandomNBitInteger
and getRandomNumber -> getRandomInteger
- Preserve old behaviour by making getRandomNumber work the same as
getRandomNBitInteger.
- Emit a DeprecationWarning when the old getRandomNumber is used.
Diffstat (limited to 'src/_fastmath.c')
-rwxr-xr-x | src/_fastmath.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/_fastmath.c b/src/_fastmath.c index a172d81..67c3cc5 100755 --- a/src/_fastmath.c +++ b/src/_fastmath.c @@ -891,7 +891,7 @@ getRNG (void) * support 2.1) */ static int -getRandomNumber (mpz_t n, unsigned long int bits, PyObject *randfunc_) +getRandomInteger (mpz_t n, unsigned long int bits, PyObject *randfunc_) { PyObject *arglist, *randfunc=NULL, *rng=NULL, *rand_bytes=NULL; int return_val = 1; @@ -959,9 +959,9 @@ cleanup: * support 2.1) */ static int -getRandomNBitNumber (mpz_t n, unsigned long int bits, PyObject *randfunc) +getRandomNBitInteger (mpz_t n, unsigned long int bits, PyObject *randfunc) { - if (!getRandomNumber (n, bits, randfunc)) + if (!getRandomInteger (n, bits, randfunc)) return 0; /* set the MSB to ensure n really has the correct number of bits. */ mpz_setbit (n, bits); @@ -991,7 +991,7 @@ getRandomRange (mpz_t n, mpz_t lower_bound, mpz_t upper_bound, do { - if (!getRandomNumber (n, bits, randfunc)) + if (!getRandomInteger (n, bits, randfunc)) { mpz_clear (range); return 0; @@ -1218,8 +1218,8 @@ getStrongPrime (PyObject *self, PyObject *args, PyObject *kwargs) Py_BLOCK_THREADS; int res = 1; res &= getRandomRange (X, lower_bound, upper_bound, randfunc); - res &= getRandomNBitNumber (y[0], 101, randfunc); - res &= getRandomNBitNumber (y[1], 101, randfunc); + res &= getRandomNBitInteger (y[0], 101, randfunc); + res &= getRandomNBitInteger (y[1], 101, randfunc); Py_UNBLOCK_THREADS; if (!res) { |