From 9619f09d3dcdf8c25994b77c6f462eba68729c11 Mon Sep 17 00:00:00 2001 From: willyzha Date: Wed, 19 Jul 2023 22:00:44 -0700 Subject: [PATCH] Use generated alias private key to calculate alias serial number --- crypto/src/openssl.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crypto/src/openssl.rs b/crypto/src/openssl.rs index 70586180..2c4aaeb2 100644 --- a/crypto/src/openssl.rs +++ b/crypto/src/openssl.rs @@ -52,12 +52,6 @@ impl OpensslCrypto { } } - fn get_priv_bytes(&mut self, algs: AlgLen) -> Result, CryptoError> { - let priv_bytes = vec![0u8; algs.size()]; - let priv_digest = self.hash(algs, &priv_bytes)?; - Ok(priv_digest.bytes().to_vec()) - } - fn ec_key_from_priv_key( algs: AlgLen, priv_key: &OpensslPrivKey, @@ -224,15 +218,16 @@ impl Crypto for OpensslCrypto { serial: &mut [u8], ) -> Result<(), CryptoError> { let nid = Self::get_curve(algs); - let priv_bytes = self.get_priv_bytes(algs)?; + let pem = include_bytes!(concat!(env!("OUT_DIR"), "/alias_priv.pem")); + let ec_priv: EcKey = EcKey::private_key_from_pem(pem).unwrap(); let group = EcGroup::from_curve_name(nid).map_err(|_| CryptoError::CryptoLibError)?; - let priv_bn = - BigNum::from_slice(priv_bytes.as_slice()).map_err(|_| CryptoError::CryptoLibError)?; let mut pub_point = EcPoint::new(&group).map_err(|_| CryptoError::CryptoLibError)?; let mut bn_ctx = BigNumContext::new().map_err(|_| CryptoError::CryptoLibError)?; - pub_point.mul_generator(&group, &priv_bn, &bn_ctx).unwrap(); + pub_point + .mul_generator(&group, ec_priv.private_key(), &bn_ctx) + .unwrap(); let mut x = BigNum::new().map_err(|_| CryptoError::CryptoLibError)?; let mut y = BigNum::new().map_err(|_| CryptoError::CryptoLibError)?;