diff options
Diffstat (limited to 'openpgp/src/crypto/backend/nettle/asymmetric.rs')
-rw-r--r-- | openpgp/src/crypto/backend/nettle/asymmetric.rs | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/openpgp/src/crypto/backend/nettle/asymmetric.rs b/openpgp/src/crypto/backend/nettle/asymmetric.rs index 0d908c55..54fa31d2 100644 --- a/openpgp/src/crypto/backend/nettle/asymmetric.rs +++ b/openpgp/src/crypto/backend/nettle/asymmetric.rs @@ -319,45 +319,16 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> { use std::time::SystemTime; use crate::crypto::mem::Protected; use crate::packet::key::{Key4, SecretParts}; -use crate::types::{PublicKeyAlgorithm, SymmetricAlgorithm}; +use crate::types::PublicKeyAlgorithm; impl<R> Key4<SecretParts, R> where R: key::KeyRole, { - - /// Creates a new OpenPGP secret key packet for an existing X25519 key. - /// - /// The ECDH key will use hash algorithm `hash` and symmetric - /// algorithm `sym`. If one or both are `None` secure defaults - /// will be used. The key will have it's creation date set to - /// `ctime` or the current time if `None` is given. - pub fn import_secret_cv25519<H, S, T>(private_key: &[u8], - hash: H, sym: S, ctime: T) - -> Result<Self> where H: Into<Option<HashAlgorithm>>, - S: Into<Option<SymmetricAlgorithm>>, - T: Into<Option<SystemTime>> + pub(crate) fn derive_cv25519_public_key(private_key: &Protected) -> Result<[u8; 32]> { - let mut public_key = [0; curve25519::CURVE25519_SIZE]; - curve25519::mul_g(&mut public_key, private_key).unwrap(); - - let mut private_key = Vec::from(private_key); - private_key.reverse(); - - use crate::crypto::ecdh; - Self::with_secret( - ctime.into().unwrap_or_else(crate::now), - PublicKeyAlgorithm::ECDH, - mpi::PublicKey::ECDH { - curve: Curve::Cv25519, - hash: hash.into().unwrap_or_else( - || ecdh::default_ecdh_kdf_hash(&Curve::Cv25519)), - sym: sym.into().unwrap_or_else( - || ecdh::default_ecdh_kek_cipher(&Curve::Cv25519)), - q: MPI::new_compressed_point(&public_key), - }, - mpi::SecretKeyMaterial::ECDH { - scalar: private_key.into(), - }.into()) + let mut public_key = [0; ed25519::ED25519_KEY_SIZE]; + curve25519::mul_g(&mut public_key, private_key)?; + Ok(public_key) } /// Creates a new OpenPGP secret key packet for an existing Ed25519 key. |