diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-05-12 14:08:41 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-05-22 12:00:09 +0200 |
commit | 2245b12bb056a390a5bb3541ce72ef66835297e6 (patch) | |
tree | 065d7e1ff0b434f65216a594bdbe49ad787f8fa2 /openpgp/src/crypto/backend/openssl | |
parent | 72db601361ab570d3f3c741ee941a562a0b3f885 (diff) |
openpgp: Add Ed25519 to trait Asymmetric.
Diffstat (limited to 'openpgp/src/crypto/backend/openssl')
-rw-r--r-- | openpgp/src/crypto/backend/openssl/asymmetric.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/openssl/asymmetric.rs b/openpgp/src/crypto/backend/openssl/asymmetric.rs index baffde97..cee5ebba 100644 --- a/openpgp/src/crypto/backend/openssl/asymmetric.rs +++ b/openpgp/src/crypto/backend/openssl/asymmetric.rs @@ -47,6 +47,35 @@ impl Asymmetric for super::Backend { deriver.set_peer(&public)?; Ok(deriver.derive_to_vec()?.into()) } + + fn ed25519_generate_key() -> Result<(Protected, [u8; 32])> { + let pair = openssl::pkey::PKey::generate_ed25519()?; + Ok((pair.raw_private_key()?.into(), + pair.raw_public_key()?.as_slice().try_into()?)) + } + + fn ed25519_derive_public(secret: &Protected) -> Result<[u8; 32]> { + let key = PKey::private_key_from_raw_bytes( + secret, openssl::pkey::Id::ED25519)?; + Ok(key.raw_public_key()?.as_slice().try_into()?) + } + + fn ed25519_sign(secret: &Protected, _public: &[u8; 32], digest: &[u8]) + -> Result<[u8; 64]> { + let key = PKey::private_key_from_raw_bytes( + secret, openssl::pkey::Id::ED25519)?; + + let mut signer = OpenSslSigner::new_without_digest(&key)?; + Ok(signer.sign_oneshot_to_vec(digest)?.as_slice().try_into()?) + } + + fn ed25519_verify(public: &[u8; 32], digest: &[u8], signature: &[u8; 64]) + -> Result<bool> { + let key = PKey::public_key_from_raw_bytes( + public, openssl::pkey::Id::ED25519)?; + let mut verifier = Verifier::new_without_digest(&key)?; + Ok(verifier.verify_oneshot(signature, digest)?) + } } impl TryFrom<&ProtectedMPI> for BigNum { |