bearssl/ec: add basic key wrappings

main
Aydin Mercan 2022-09-17 15:34:40 +03:00
parent f83ea3b50f
commit 279f8ac3e4
Signed by: jaiden
SSH Key Fingerprint: SHA256:vy6hjzotbn/MWZAbjzURNk3NL62EPkjoHsJ5xr/s7nk
4 changed files with 54 additions and 0 deletions

5
bearssl/src/ec.rs Normal file
View File

@ -0,0 +1,5 @@
mod private;
mod public;
pub use private::PrivateKey;
pub use public::PublicKey;

31
bearssl/src/ec/private.rs Normal file
View File

@ -0,0 +1,31 @@
use core::ops::Drop;
use core::slice;
use bearssl_sys::br_ec_private_key;
#[repr(transparent)]
pub struct PrivateKey(pub(crate) br_ec_private_key);
#[cfg(feature = "zeroize")]
impl Drop for PrivateKey {
fn drop(&mut self) {
use zeroize::Zeroize;
self.zeroize();
}
}
#[cfg(feature = "zeroize")]
impl zeroize::ZeroizeOnDrop for PrivateKey {}
#[cfg(feature = "zeroize")]
impl zeroize::Zeroize for PrivateKey {
fn zeroize(&mut self) {
// Safety: Slice constructions should be safe as long as lengths have not been modified
// outside what BearSSL set.
unsafe {
let x = slice::from_raw_parts_mut(self.0.x, self.0.xlen);
x.zeroize();
}
}
}

17
bearssl/src/ec/public.rs Normal file
View File

@ -0,0 +1,17 @@
use core::ops::Drop;
use core::slice;
use bearssl_sys::br_ec_public_key;
#[repr(transparent)]
pub struct PublicKey(pub(crate) br_ec_public_key);
#[cfg(feature = "zeroize")]
impl zeroize::Zeroize for PublicKey {
fn zeroize(&mut self) {
unsafe {
let q = slice::from_raw_parts_mut(self.0.q, self.0.qlen);
q.zeroize();
}
}
}

View File

@ -3,6 +3,7 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
extern crate std; extern crate std;
pub mod ec;
pub mod engine; pub mod engine;
pub mod profile; pub mod profile;
pub mod rsa; pub mod rsa;