diff options
Diffstat (limited to 'openpgp/src/crypto/backend/interface.rs')
-rw-r--r-- | openpgp/src/crypto/backend/interface.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/openpgp/src/crypto/backend/interface.rs b/openpgp/src/crypto/backend/interface.rs index f96e9a6c..81343c6c 100644 --- a/openpgp/src/crypto/backend/interface.rs +++ b/openpgp/src/crypto/backend/interface.rs @@ -1,9 +1,12 @@ //! The crypto-backend abstraction. -use crate::Result; +use crate::{ + Result, + crypto::mem::Protected, +}; /// Abstracts over the cryptographic backends. -pub trait Backend { +pub trait Backend: Asymmetric { /// Returns a short, human-readable description of the backend. /// /// This starts with the name of the backend, possibly a version, @@ -19,3 +22,18 @@ pub trait Backend { /// long-term cryptographic keys from. fn random(buf: &mut [u8]) -> Result<()>; } + +/// Public-key cryptography interface. +pub trait Asymmetric { + /// Generates an X25519 key pair. + /// + /// Returns a tuple containing the secret and public key. + fn x25519_generate_key() -> Result<(Protected, [u8; 32])>; + + /// Computes the public key for a given secret key. + fn x25519_derive_public(secret: &Protected) -> Result<[u8; 32]>; + + /// Computes the shared point. + fn x25519_shared_point(secret: &Protected, public: &[u8; 32]) + -> Result<Protected>; +} |