Loading openssl-sys/src/handwritten/evp.rs +8 −0 Original line number Diff line number Diff line Loading @@ -402,6 +402,7 @@ cfg_if! { extern "C" { pub fn EVP_PKEY_get_id(pkey: *const EVP_PKEY) -> c_int; pub fn EVP_PKEY_get_bits(key: *const EVP_PKEY) -> c_int; pub fn EVP_PKEY_get_security_bits(key: *const EVP_PKEY) -> c_int; } #[inline] Loading @@ -413,6 +414,12 @@ cfg_if! { pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_bits(pkey) } #[inline] pub unsafe fn EVP_PKEY_security_bits(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_security_bits(pkey) } } else { extern "C" { pub fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int; Loading @@ -420,6 +427,7 @@ cfg_if! { const_ptr_api! { extern "C" { pub fn EVP_PKEY_bits(key: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; pub fn EVP_PKEY_security_bits(pkey: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; } } } Loading openssl/src/pkey.rs +17 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,14 @@ where unsafe { ffi::EVP_PKEY_bits(self.as_ptr()) as u32 } } ///Returns the number of security bits. /// ///Bits of security is defined in NIST SP800-57. #[corresponds(EVP_PKEY_security_bits)] pub fn security_bits(&self) -> u32 { unsafe { ffi::EVP_PKEY_security_bits(self.as_ptr()) as u32 } } /// Compares the public component of this key with another. #[corresponds(EVP_PKEY_cmp)] pub fn public_eq<U>(&self, other: &PKeyRef<U>) -> bool Loading Loading @@ -1018,6 +1026,15 @@ mod tests { assert_eq!(ec_key.private_key(), ec_key_.private_key()); } #[test] fn test_security_bits() { let group = crate::ec::EcGroup::from_curve_name(crate::nid::Nid::SECP521R1).unwrap(); let ec_key = EcKey::generate(&group).unwrap(); let pkey: PKey<Private> = ec_key.clone().try_into().unwrap(); assert_eq!(pkey.security_bits(), 256); } #[test] #[cfg(not(boringssl))] fn test_dh_conversion() { Loading Loading
openssl-sys/src/handwritten/evp.rs +8 −0 Original line number Diff line number Diff line Loading @@ -402,6 +402,7 @@ cfg_if! { extern "C" { pub fn EVP_PKEY_get_id(pkey: *const EVP_PKEY) -> c_int; pub fn EVP_PKEY_get_bits(key: *const EVP_PKEY) -> c_int; pub fn EVP_PKEY_get_security_bits(key: *const EVP_PKEY) -> c_int; } #[inline] Loading @@ -413,6 +414,12 @@ cfg_if! { pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_bits(pkey) } #[inline] pub unsafe fn EVP_PKEY_security_bits(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_security_bits(pkey) } } else { extern "C" { pub fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int; Loading @@ -420,6 +427,7 @@ cfg_if! { const_ptr_api! { extern "C" { pub fn EVP_PKEY_bits(key: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; pub fn EVP_PKEY_security_bits(pkey: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; } } } Loading
openssl/src/pkey.rs +17 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,14 @@ where unsafe { ffi::EVP_PKEY_bits(self.as_ptr()) as u32 } } ///Returns the number of security bits. /// ///Bits of security is defined in NIST SP800-57. #[corresponds(EVP_PKEY_security_bits)] pub fn security_bits(&self) -> u32 { unsafe { ffi::EVP_PKEY_security_bits(self.as_ptr()) as u32 } } /// Compares the public component of this key with another. #[corresponds(EVP_PKEY_cmp)] pub fn public_eq<U>(&self, other: &PKeyRef<U>) -> bool Loading Loading @@ -1018,6 +1026,15 @@ mod tests { assert_eq!(ec_key.private_key(), ec_key_.private_key()); } #[test] fn test_security_bits() { let group = crate::ec::EcGroup::from_curve_name(crate::nid::Nid::SECP521R1).unwrap(); let ec_key = EcKey::generate(&group).unwrap(); let pkey: PKey<Private> = ec_key.clone().try_into().unwrap(); assert_eq!(pkey.security_bits(), 256); } #[test] #[cfg(not(boringssl))] fn test_dh_conversion() { Loading