diff options
Diffstat (limited to 'openpgp/src/packet/key.rs')
-rw-r--r-- | openpgp/src/packet/key.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 2750e7a3..4f9b496a 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1089,6 +1089,32 @@ impl<R> Key4<SecretParts, R> scalar: private_key.into(), }.into()) } + + /// Creates a new OpenPGP secret key packet for an existing Ed25519 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_ed25519<T>(private_key: &[u8], ctime: T) + -> Result<Self> where T: Into<Option<time::SystemTime>> + { + use crate::crypto::backend::{Backend, interface::Asymmetric}; + + let private_key = Protected::from(private_key); + let public_key = Backend::ed25519_derive_public(&private_key)?; + + Self::with_secret( + ctime.into().unwrap_or_else(crate::now), + PublicKeyAlgorithm::EdDSA, + mpi::PublicKey::EdDSA { + curve: Curve::Ed25519, + q: mpi::MPI::new_compressed_point(&public_key), + }, + mpi::SecretKeyMaterial::EdDSA { + scalar: private_key.into(), + }.into()) + } } impl<P, R> Key4<P, R> |