Skip to content

Commit ad2f4fd

Browse files
teythoonsimo5
authored andcommitted
ossl: Make BigNum::from_bigendian_slice use secure memory.
1 parent b1166ae commit ad2f4fd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ossl/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,21 @@ impl BigNum {
264264
///
265265
/// Returns a wrapped `BigNum` or an error if the import fails.
266266
pub fn from_bigendian_slice(v: &[u8]) -> Result<BigNum, Error> {
267-
let bn = unsafe {
267+
let mut bn = BigNum::new()?;
268+
269+
let ret = unsafe {
268270
BN_bin2bn(
269271
v.as_ptr() as *mut u8,
270272
c_int::try_from(v.len())?,
271-
std::ptr::null_mut(),
273+
bn.as_mut_ptr(),
272274
)
273275
};
274-
if bn.is_null() {
276+
if ret.is_null() {
275277
trace_ossl!("BN_bin2bn()");
276278
return Err(Error::new(ErrorKind::NullPtr));
277279
}
278-
Ok(BigNum { bn })
280+
281+
Ok(bn)
279282
}
280283

281284
/// Calculates the minimum number of bytes needed to represent the `BIGNUM`.

0 commit comments

Comments
 (0)