//! 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::{Decryptor, KeyPair, Signer};
use crate::crypto::mem::Protected;
use crate::crypto::mpi;
use crate::crypto::SessionKey;
use crate::packet::key::{Key4, SecretParts};
use crate::packet::{self, key, Key};
use crate::types::{PublicKeyAlgorithm, SymmetricAlgorithm};
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 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> {
use cng::asymmetric::{AsymmetricAlgorithm, AsymmetricAlgorithmId};
use cng::asymmetric::{AsymmetricKey, Private, Rsa};
use cng::asymmetric::signature::{Signer, SignaturePadding};
use cng::key_blob::RsaKeyPrivatePayload;
use cng::key_blob::EccKeyPrivatePayload;
use cng::asymmetric::ecc::NamedCurve;
#[allow(deprecated)]
self.secret().map(|secret| {
Ok(match (self.public().pk_algo(), self.public().mpis(), secret) {
(PublicKeyAlgorithm::RSAEncryptSign,
&mpi::PublicKey::RSA { ref e, ref n },
&mpi::SecretKeyMaterial::RSA { ref p, ref q, ref d, .. }) |
(PublicKeyAlgorithm::RSASign,
&mpi::PublicKey::RSA { ref e, ref n },
&mpi::SecretKeyMaterial::RSA { ref p, ref q, ref d, .. })