Added zeroize (not complete yet) and moved to new repo.
This commit is contained in:
parent
638e469fc2
commit
9083a269b6
6 changed files with 78 additions and 14 deletions
19
src/dh.rs
19
src/dh.rs
|
|
@ -8,11 +8,26 @@ use alloc::vec::Vec;
|
|||
use alloc::string::ToString;
|
||||
use p256::elliptic_curve::ecdh::diffie_hellman;
|
||||
|
||||
use zeroize::Zeroize;
|
||||
|
||||
pub struct DhKeyPair {
|
||||
pub private_key: SecretKey,
|
||||
pub public_key: PublicKey,
|
||||
}
|
||||
|
||||
impl Drop for DhKeyPair {
|
||||
fn drop(&mut self) {
|
||||
core::mem::drop(&mut self.private_key);
|
||||
core::mem::drop(&mut self.public_key);
|
||||
}
|
||||
}
|
||||
|
||||
impl Zeroize for DhKeyPair {
|
||||
fn zeroize(&mut self) {
|
||||
core::mem::drop(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl DhKeyPair {
|
||||
fn ex_public_key_bytes(&self) -> Vec<u8> {
|
||||
self.public_key.to_string().as_bytes().to_vec()
|
||||
|
|
@ -49,7 +64,7 @@ impl Default for DhKeyPair {
|
|||
impl DhKeyPair {
|
||||
pub fn new() -> Self {
|
||||
let secret = SecretKey::random(&mut OsRng);
|
||||
let public = PublicKey::from_secret_scalar(&secret.secret_scalar());
|
||||
let public = PublicKey::from_secret_scalar(&secret.to_secret_scalar());
|
||||
DhKeyPair {
|
||||
private_key: secret,
|
||||
public_key: public,
|
||||
|
|
@ -57,7 +72,7 @@ impl DhKeyPair {
|
|||
}
|
||||
|
||||
pub fn key_agreement(&self, public_key: &PublicKey) -> SharedSecret {
|
||||
diffie_hellman(self.private_key.secret_scalar(), public_key.as_affine())
|
||||
diffie_hellman(self.private_key.to_secret_scalar(), public_key.as_affine())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue