Updated dependencies. Removed useless zeroize.
This commit is contained in:
parent
ae6673cb48
commit
6aaae1bea4
8 changed files with 19 additions and 51 deletions
21
src/dh.rs
21
src/dh.rs
|
|
@ -8,27 +8,12 @@ use alloc::vec::Vec;
|
|||
use alloc::string::ToString;
|
||||
use p256::elliptic_curve::ecdh::diffie_hellman;
|
||||
|
||||
use zeroize::Zeroize;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DhKeyPair {
|
||||
pub private_key: SecretKey,
|
||||
pub public_key: PublicKey,
|
||||
}
|
||||
|
||||
impl Drop for DhKeyPair {
|
||||
fn drop(&mut self) {
|
||||
self.private_key = SecretKey::random(&mut OsRng);
|
||||
self.public_key = self.private_key.public_key();
|
||||
}
|
||||
}
|
||||
|
||||
impl Zeroize for DhKeyPair {
|
||||
fn zeroize(&mut self) {
|
||||
self.private_key = SecretKey::random(&mut OsRng);
|
||||
self.public_key = self.private_key.public_key();
|
||||
}
|
||||
}
|
||||
|
||||
impl DhKeyPair {
|
||||
fn ex_public_key_bytes(&self) -> Vec<u8> {
|
||||
|
|
@ -38,7 +23,7 @@ impl DhKeyPair {
|
|||
|
||||
impl PartialEq for DhKeyPair {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if self.private_key.to_bytes() != other.private_key.to_bytes() {
|
||||
if self.private_key.to_be_bytes() != other.private_key.to_be_bytes() {
|
||||
return false
|
||||
}
|
||||
if self.ex_public_key_bytes() != other.ex_public_key_bytes() {
|
||||
|
|
@ -51,7 +36,7 @@ impl PartialEq for DhKeyPair {
|
|||
impl Debug for DhKeyPair {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("DhKeyPair")
|
||||
.field("private_key", &self.private_key.to_bytes())
|
||||
.field("private_key", &self.private_key.to_be_bytes())
|
||||
.field("public_key", &self.ex_public_key_bytes())
|
||||
.finish()
|
||||
}
|
||||
|
|
@ -74,7 +59,7 @@ impl DhKeyPair {
|
|||
}
|
||||
|
||||
pub fn key_agreement(&self, public_key: &PublicKey) -> SharedSecret {
|
||||
diffie_hellman(self.private_key.to_secret_scalar(), public_key.as_affine())
|
||||
diffie_hellman(self.private_key.to_nonzero_scalar(), public_key.as_affine())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
use hmac::{Hmac, Mac, NewMac};
|
||||
use hmac::{Hmac, Mac};
|
||||
|
||||
#[cfg(feature = "ring")]
|
||||
use ring_compat::digest::Sha512;
|
||||
|
||||
#[cfg(not(feature = "ring"))]
|
||||
use sha2::Sha512;
|
||||
|
||||
use core::convert::TryInto;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
|
||||
use hkdf::Hkdf;
|
||||
|
||||
#[cfg(feature = "ring")]
|
||||
use ring_compat::digest::Sha512;
|
||||
|
||||
#[cfg(not(feature = "ring"))]
|
||||
use sha2::Sha512;
|
||||
|
||||
use core::convert::TryInto;
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
//! # let shared_nhkb = [2; 32];
|
||||
//! let (bob_ratchet, public_key) = RatchetEncHeader::init_bob(sk, shared_hka, shared_nhkb);
|
||||
//! let ex_ratchet = bob_ratchet.export();
|
||||
//! let im_ratchet = RatchetEncHeader::import(&ex_ratchet);
|
||||
//! let im_ratchet = RatchetEncHeader::import(&ex_ratchet).unwrap();
|
||||
//! assert_eq!(im_ratchet, bob_ratchet)
|
||||
//! ```
|
||||
//!
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ pub struct Ratchet {
|
|||
|
||||
impl Drop for Ratchet {
|
||||
fn drop(&mut self) {
|
||||
self.dhs.zeroize();
|
||||
if let Some(mut _d) = self.dhr {
|
||||
let sk = SecretKey::random(&mut OsRng);
|
||||
_d = sk.public_key()
|
||||
|
|
@ -182,7 +181,6 @@ pub struct RatchetEncHeader {
|
|||
|
||||
impl Zeroize for RatchetEncHeader {
|
||||
fn zeroize(&mut self) {
|
||||
self.dhs.zeroize();
|
||||
self.rk.zeroize();
|
||||
self.cks.zeroize();
|
||||
self.ckr.zeroize();
|
||||
|
|
@ -225,7 +223,7 @@ impl From<&RatchetEncHeader> for ExRatchetEncHeader {
|
|||
fn from(reh: &RatchetEncHeader) -> Self {
|
||||
let private_dhs = reh.dhs.private_key.to_jwk_string();
|
||||
let public_dhs = reh.dhs.public_key.to_jwk_string();
|
||||
let dhs = (private_dhs, public_dhs);
|
||||
let dhs = (private_dhs.to_string(), public_dhs);
|
||||
let dhr = reh.dhr.map(|e| e.to_jwk_string());
|
||||
let rk = reh.rk;
|
||||
let cks = reh.cks;
|
||||
|
|
@ -441,8 +439,8 @@ impl RatchetEncHeader {
|
|||
}
|
||||
|
||||
/// Import the ratchet from Binary data. Panics when binary data is invalid.
|
||||
pub fn import(inp: &[u8]) -> Self {
|
||||
let ex: ExRatchetEncHeader = bincode::deserialize(inp).unwrap();
|
||||
RatchetEncHeader::from(&ex)
|
||||
pub fn import(inp: &[u8]) -> Option<Self> {
|
||||
let ex: ExRatchetEncHeader = bincode::deserialize(inp).ok()?;
|
||||
Some(RatchetEncHeader::from(&ex))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue