/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
usecrate::{
crypto::{Cryptographer, EcKeyComponents, LocalKeyPair, RemotePublicKey},
error::*,
}; use base64::Engine; use hkdf::Hkdf; use lazy_static::lazy_static; use openssl::{
bn::{BigNum, BigNumContext},
derive::Deriver,
ec::{EcGroup, EcKey, EcPoint, PointConversionForm},
nid::Nid,
pkey::{PKey, Private, Public},
rand::rand_bytes,
symm::{Cipher, Crypter, Mode},
}; use sha2::Sha256; use std::{any::Any, fmt};
fn from_raw_components(components: &EcKeyComponents) -> Result<Self> { let d = BigNum::from_slice(components.private_key())?; letmut bn_ctx = BigNumContext::new()?; let ec_point = EcPoint::from_bytes(&GROUP_P256, components.public_key(), &mut bn_ctx)?; letmut x = BigNum::new()?; letmut y = BigNum::new()?;
ec_point.affine_coordinates_gfp(&GROUP_P256, &mut x, &mut y, &mut bn_ctx)?; let public_key = EcKey::from_public_key_affine_coordinates(&GROUP_P256, &x, &y)?; let private_key = EcKey::from_private_components(&GROUP_P256, &d, public_key.public_key())?;
Ok(Self {
ec_key: private_key,
})
}
}
impl LocalKeyPair for OpenSSLLocalKeyPair { /// Export the public key component in the binary uncompressed point representation /// using OpenSSL `PointConversionForm::UNCOMPRESSED`. fn pub_as_raw(&self) -> Result<Vec<u8>> { let pub_key_point = self.ec_key.public_key(); letmut bn_ctx = BigNumContext::new()?; let uncompressed =
pub_key_point.to_bytes(&GROUP_P256, PointConversionForm::UNCOMPRESSED, &mut bn_ctx)?;
Ok(uncompressed)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.