diff options
author | Igor Matuszewski <igor@sequoia-pgp.org> | 2020-04-10 23:44:51 +0200 |
---|---|---|
committer | Igor Matuszewski <igor@sequoia-pgp.org> | 2020-08-13 13:15:04 +0200 |
commit | 976424a29509e194e10d277f15425fb67bb17493 (patch) | |
tree | 016f55a487961c2527593035174e1153619b1714 /openpgp/src/crypto/backend | |
parent | 9a367f4d5049709b35de12f4879a72c0ada674b0 (diff) |
openpgp: Add stubs for other crypto impls using Windows CNG API
Diffstat (limited to 'openpgp/src/crypto/backend')
-rw-r--r-- | openpgp/src/crypto/backend/cng.rs | 3 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/cng/aead.rs | 18 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/cng/asymmetric.rs | 117 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/cng/ecdh.rs | 32 |
4 files changed, 170 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs index 017ca117..9947f3a2 100644 --- a/openpgp/src/crypto/backend/cng.rs +++ b/openpgp/src/crypto/backend/cng.rs @@ -2,6 +2,9 @@ use win_crypto_ng::random::RandomNumberGenerator; +pub mod aead; +pub mod asymmetric; +pub mod ecdh; pub mod hash; pub mod symmetric; diff --git a/openpgp/src/crypto/backend/cng/aead.rs b/openpgp/src/crypto/backend/cng/aead.rs new file mode 100644 index 00000000..4251fb5b --- /dev/null +++ b/openpgp/src/crypto/backend/cng/aead.rs @@ -0,0 +1,18 @@ +//! Implementation of AEAD using Windows CNG API. +#![allow(unused_variables)] + +use crate::Result; + +use crate::crypto::aead::Aead; +use crate::types::{AEADAlgorithm, SymmetricAlgorithm}; + +impl AEADAlgorithm { + pub(crate) fn context( + &self, + sym_algo: SymmetricAlgorithm, + key: &[u8], + nonce: &[u8], + ) -> Result<Box<dyn Aead>> { + unimplemented!() + } +} diff --git a/openpgp/src/crypto/backend/cng/asymmetric.rs b/openpgp/src/crypto/backend/cng/asymmetric.rs new file mode 100644 index 00000000..f09d89be --- /dev/null +++ b/openpgp/src/crypto/backend/cng/asymmetric.rs @@ -0,0 +1,117 @@ +//! Implementation of asymmetric cryptography using Windows CNG API. +#![allow(unused_variables)] + +use std::time::SystemTime; + +use crate::Result; + +use crate::crypto::asymmetric::{Decryptor, KeyPair, Signer}; +use crate::crypto::mpi; +use crate::crypto::SessionKey; +use crate::packet::key::{Key4, SecretParts}; +use crate::packet::{self, key, Key}; +use crate::types::SymmetricAlgorithm; +use crate::types::{Curve, HashAlgorithm}; + +impl Signer for KeyPair { + fn public(&self) -> &Key<key::PublicParts, key::UnspecifiedRole> { + KeyPair::public(self) + } + + fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<mpi::Signature> { + unimplemented!() + } +} + +impl Decryptor for KeyPair { + fn public(&self) -> &Key<key::PublicParts, key::UnspecifiedRole> { + KeyPair::public(self) + } + + /// Creates a signature over the `digest` produced by `hash_algo`. + fn decrypt( + &mut self, + ciphertext: &mpi::Ciphertext, + plaintext_len: Option<usize>, + ) -> Result<SessionKey> { + unimplemented!() + } +} + +impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> { + /// Encrypts the given data with this key. + pub fn encrypt(&self, data: &SessionKey) -> Result<mpi::Ciphertext> { + unimplemented!() + } + + /// Verifies the given signature. + pub fn verify(&self, sig: &packet::Signature, digest: &[u8]) -> Result<()> { + unimplemented!() + } +} + +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>>, + { + unimplemented!() + } + + /// 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<SystemTime>>, + { + unimplemented!() + } + + /// Creates a new OpenPGP public key packet for an existing RSA key. + /// + /// The RSA key will use public exponent `e` and modulo `n`. The key will + /// have it's creation date set to `ctime` or the current time if `None` + /// is given. + pub fn import_secret_rsa<T>(d: &[u8], p: &[u8], q: &[u8], ctime: T) -> Result<Self> + where + T: Into<Option<SystemTime>>, + { + unimplemented!() + } + + /// Generates a new RSA key with a public modulos of size `bits`. + pub fn generate_rsa(bits: usize) -> Result<Self> { + unimplemented!() + } + + /// Generates a new ECC key over `curve`. + /// + /// If `for_signing` is false a ECDH key, if it's true either a + /// EdDSA or ECDSA key is generated. Giving `for_signing == true` + /// and `curve == Cv25519` will produce an error. Similar for + /// `for_signing == false` and `curve == Ed25519`. + /// signing/encryption + pub fn generate_ecc(for_signing: bool, curve: Curve) -> Result<Self> { + unimplemented!() + } +} diff --git a/openpgp/src/crypto/backend/cng/ecdh.rs b/openpgp/src/crypto/backend/cng/ecdh.rs new file mode 100644 index 00000000..c2014a75 --- /dev/null +++ b/openpgp/src/crypto/backend/cng/ecdh.rs @@ -0,0 +1,32 @@ +//! Elliptic Curve Diffie-Hellman. +#![allow(unused_variables)] + +use crate::crypto::mpi::{Ciphertext, SecretKeyMaterial}; +use crate::crypto::SessionKey; +use crate::packet::{key, Key}; +use crate::Result; + +/// Wraps a session key using Elliptic Curve Diffie-Hellman. +#[allow(non_snake_case)] +pub fn encrypt<R>( + recipient: &Key<key::PublicParts, R>, + session_key: &SessionKey, +) -> Result<Ciphertext> +where + R: key::KeyRole, +{ + unimplemented!() +} + +/// Unwraps a session key using Elliptic Curve Diffie-Hellman. +#[allow(non_snake_case)] +pub fn decrypt<R>( + recipient: &Key<key::PublicParts, R>, + recipient_sec: &SecretKeyMaterial, + ciphertext: &Ciphertext, +) -> Result<SessionKey> +where + R: key::KeyRole, +{ + unimplemented!() +} |