//! Implementation of asymmetric cryptography using Windows CNG API.
#![allow(unused_variables)]
use std::time::SystemTime;
use std::convert::TryInto;
use crate::{Error, Result};
use crate::crypto::asymmetric::KeyPair;
use crate::crypto::backend::interface::Asymmetric;
use crate::crypto::mem::Protected;
use crate::crypto::mpi::{self, MPI, ProtectedMPI};
use crate::crypto::SessionKey;
use crate::crypto::{pad, pad_at_least, pad_truncating};
use crate::packet::key::{Key4, SecretParts};
use crate::packet::{key, Key};
use crate::types::PublicKeyAlgorithm;
use crate::types::{Curve, HashAlgorithm};
use num_bigint_dig::{traits::ModInverse, BigInt, BigUint};
use win_crypto_ng as cng;
const CURVE25519_SIZE: usize = 32;
impl TryFrom<&Protected> for Box<ed25519_dalek::SigningKey> {
type Error = anyhow::Error;
fn try_from(value: &Protected) -> Result<Self> {
if value.len() != ed25519_dalek::SECRET_KEY_LENGTH {
return Err(crate::Error::InvalidArgument(
"Bad Ed25519 secret length".into()).into());
}
Ok(Box::new(ed25519_dalek::SigningKey::from_bytes(
value.as_ref().try_into().map_err(
|e: std::array::TryFromSliceError| {
Error::InvalidKey(e.to_string())
})?)))
}
}
impl Asymmetric for super::Backend {
fn supports_algo(algo: PublicKeyAlgorithm) -> bool {
use PublicKeyAlgorithm::*;
#[allow(deprecated)]
match algo {
RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
=> true,
ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
=> false,
}
}
fn supports_curve(curve: &Curve) -> bool {
use Curve::*;
match curve {
NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
=> true,
BrainpoolP256 |