diff options
| author | Chris Cole <[email protected]> | 2017-03-25 12:29:18 -0400 |
|---|---|---|
| committer | Chris Cole <[email protected]> | 2017-03-25 12:29:18 -0400 |
| commit | d239e04c706df09b32c0f90e67adbe55b2a7d3d7 (patch) | |
| tree | 9098661d74441268ab1ad7627b3ecf7618e4df95 | |
| parent | Merge pull request #601 from pgerber/double_unlock (diff) | |
| download | rust-openssl-d239e04c706df09b32c0f90e67adbe55b2a7d3d7.tar.xz rust-openssl-d239e04c706df09b32c0f90e67adbe55b2a7d3d7.zip | |
Fix order of arguments to BN_rand_range and BN_pseudo_rand_range
| -rw-r--r-- | openssl/src/bn.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/openssl/src/bn.rs b/openssl/src/bn.rs index 5cc27862..a0066da8 100644 --- a/openssl/src/bn.rs +++ b/openssl/src/bn.rs @@ -106,12 +106,12 @@ impl BigNumRef { /// Places a cryptographically-secure pseudo-random number nonnegative /// number less than `self` in `rnd`. pub fn rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack> { - unsafe { cvt(ffi::BN_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ()) } + unsafe { cvt(ffi::BN_rand_range(rnd.as_ptr(), self.as_ptr())).map(|_| ()) } } /// The cryptographically weak counterpart to `rand_in_range`. pub fn pseudo_rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack> { - unsafe { cvt(ffi::BN_pseudo_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ()) } + unsafe { cvt(ffi::BN_pseudo_rand_range(rnd.as_ptr(), self.as_ptr())).map(|_| ()) } } /// Sets bit `n`. Equivalent to `self |= (1 << n)`. @@ -934,6 +934,24 @@ mod tests { } #[test] + fn test_rand_range() { + let range = BigNum::from_u32(909829283).unwrap(); + let mut result = BigNum::from_dec_str( + &range.to_dec_str().unwrap()).unwrap(); + range.rand_range(&mut result).unwrap(); + assert!(result >= BigNum::from_u32(0).unwrap() && result < range); + } + + #[test] + fn test_pseudo_rand_range() { + let range = BigNum::from_u32(909829283).unwrap(); + let mut result = BigNum::from_dec_str( + &range.to_dec_str().unwrap()).unwrap(); + range.pseudo_rand_range(&mut result).unwrap(); + assert!(result >= BigNum::from_u32(0).unwrap() && result < range); + } + + #[test] fn test_prime_numbers() { let a = BigNum::from_u32(19029017).unwrap(); let mut p = BigNum::new().unwrap(); |