Expose EC_GROUP_get0_generator as EcGroup::generator
This commit is contained in:
parent
89bd6d6168
commit
390d71f1e5
|
|
@ -30,6 +30,8 @@ extern "C" {
|
||||||
ctx: *mut BN_CTX,
|
ctx: *mut BN_CTX,
|
||||||
) -> c_int;
|
) -> c_int;
|
||||||
|
|
||||||
|
pub fn EC_GROUP_get0_generator(group: *const EC_GROUP) -> *const EC_POINT;
|
||||||
|
|
||||||
pub fn EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int;
|
pub fn EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int;
|
||||||
|
|
||||||
pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int);
|
pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int);
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,18 @@ impl EcGroupRef {
|
||||||
unsafe { ffi::EC_GROUP_get_degree(self.as_ptr()) as u32 }
|
unsafe { ffi::EC_GROUP_get_degree(self.as_ptr()) as u32 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the generator for the given curve as a [`EcPoint`].
|
||||||
|
///
|
||||||
|
/// OpenSSL documentation at [`EC_GROUP_get0_generator`]
|
||||||
|
///
|
||||||
|
/// [`EC_GROUP_get0_generator`]: https://www.openssl.org/docs/man1.1.0/man3/EC_GROUP_get0_generator.html
|
||||||
|
pub fn generator(&self) -> &EcPointRef {
|
||||||
|
unsafe {
|
||||||
|
let ptr = ffi::EC_GROUP_get0_generator(self.as_ptr());
|
||||||
|
EcPointRef::from_ptr(ptr as *mut _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Places the order of the curve in the provided `BigNum`.
|
/// Places the order of the curve in the provided `BigNum`.
|
||||||
///
|
///
|
||||||
/// OpenSSL documentation at [`EC_GROUP_get_order`]
|
/// OpenSSL documentation at [`EC_GROUP_get_order`]
|
||||||
|
|
@ -889,6 +901,17 @@ mod test {
|
||||||
assert!(public_key.eq(&group, key.public_key(), &mut ctx).unwrap());
|
assert!(public_key.eq(&group, key.public_key(), &mut ctx).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generator() {
|
||||||
|
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
|
||||||
|
let gen = group.generator();
|
||||||
|
let one = BigNum::from_u32(1).unwrap();
|
||||||
|
let mut ctx = BigNumContext::new().unwrap();
|
||||||
|
let mut ecp = EcPoint::new(&group).unwrap();
|
||||||
|
ecp.mul_generator(&group, &one, &mut ctx).unwrap();
|
||||||
|
assert!(ecp.eq(&group, gen, &mut ctx).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn key_from_public_key() {
|
fn key_from_public_key() {
|
||||||
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
|
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue