Move enc::sym::Secret to enc::Secret
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
5b338c8758
commit
9634fbba31
|
@ -15,8 +15,8 @@ use crate::{
|
|||
enc::{
|
||||
asym::{ExchangePubKey, KeyExchangeKind, KeyID},
|
||||
hkdf::HkdfKind,
|
||||
sym::{CipherKind, HeadLen, Secret, TagLen},
|
||||
Random,
|
||||
sym::{CipherKind, HeadLen, TagLen},
|
||||
Random, Secret,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use ::num_traits::FromPrimitive;
|
|||
use super::Error;
|
||||
use crate::{
|
||||
config::Config,
|
||||
enc::{sym::Secret, Random},
|
||||
enc::{Random, Secret},
|
||||
};
|
||||
|
||||
/// Public key ID
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use ::sha3::Sha3_256;
|
||||
use ::zeroize::Zeroize;
|
||||
|
||||
use crate::{config::Config, enc::sym::Secret};
|
||||
use crate::{config::Config, enc::Secret};
|
||||
|
||||
/// Kind of HKDF
|
||||
#[derive(Debug, Copy, Clone, PartialEq, ::num_derive::FromPrimitive)]
|
||||
|
|
|
@ -8,6 +8,7 @@ pub mod sym;
|
|||
pub use errors::Error;
|
||||
|
||||
use ::ring::rand::SecureRandom;
|
||||
use ::zeroize::Zeroize;
|
||||
|
||||
/// wrapper where we implement whatever random traint stuff each library needs
|
||||
pub struct Random {
|
||||
|
@ -72,3 +73,42 @@ impl ::rand_core::RngCore for &Random {
|
|||
}
|
||||
}
|
||||
impl ::rand_core::CryptoRng for &Random {}
|
||||
|
||||
/// Secret, used for keys.
|
||||
/// Grants that on drop() we will zero out memory
|
||||
#[derive(Zeroize, Clone)]
|
||||
#[zeroize(drop)]
|
||||
pub struct Secret([u8; 32]);
|
||||
// Fake debug implementation to avoid leaking secrets
|
||||
impl ::core::fmt::Debug for Secret {
|
||||
fn fmt(
|
||||
&self,
|
||||
f: &mut core::fmt::Formatter<'_>,
|
||||
) -> Result<(), ::std::fmt::Error> {
|
||||
::core::fmt::Debug::fmt("[hidden secret]", f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Secret {
|
||||
/// New randomly generated secret
|
||||
pub fn new_rand(rand: &Random) -> Self {
|
||||
let mut ret = Self([0; 32]);
|
||||
rand.fill(&mut ret.0);
|
||||
ret
|
||||
}
|
||||
/// return a reference to the secret
|
||||
pub fn as_ref(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<[u8; 32]> for Secret {
|
||||
fn from(shared_secret: [u8; 32]) -> Self {
|
||||
Self(shared_secret)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::x25519_dalek::SharedSecret> for Secret {
|
||||
fn from(shared_secret: ::x25519_dalek::SharedSecret) -> Self {
|
||||
Self(shared_secret.to_bytes())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,12 @@
|
|||
//! Symmetric cypher stuff
|
||||
|
||||
use super::Error;
|
||||
use crate::{config::Config, enc::Random};
|
||||
use crate::{
|
||||
config::Config,
|
||||
enc::{Random, Secret},
|
||||
};
|
||||
use ::zeroize::Zeroize;
|
||||
|
||||
/// Secret, used for keys.
|
||||
/// Grants that on drop() we will zero out memory
|
||||
#[derive(Zeroize, Clone)]
|
||||
#[zeroize(drop)]
|
||||
pub struct Secret([u8; 32]);
|
||||
// Fake debug implementation to avoid leaking secrets
|
||||
impl ::core::fmt::Debug for Secret {
|
||||
fn fmt(
|
||||
&self,
|
||||
f: &mut core::fmt::Formatter<'_>,
|
||||
) -> Result<(), ::std::fmt::Error> {
|
||||
::core::fmt::Debug::fmt("[hidden secret]", f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Secret {
|
||||
/// New randomly generated secret
|
||||
pub fn new_rand(rand: &Random) -> Self {
|
||||
let mut ret = Self([0; 32]);
|
||||
rand.fill(&mut ret.0);
|
||||
ret
|
||||
}
|
||||
/// return a reference to the secret
|
||||
pub fn as_ref(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for Secret {
|
||||
fn from(shared_secret: [u8; 32]) -> Self {
|
||||
Self(shared_secret)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::x25519_dalek::SharedSecret> for Secret {
|
||||
fn from(shared_secret: ::x25519_dalek::SharedSecret) -> Self {
|
||||
Self(shared_secret.to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// List of possible Ciphers
|
||||
#[derive(Debug, Copy, Clone, PartialEq, ::num_derive::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
|
|
|
@ -16,8 +16,8 @@ use crate::{
|
|||
enc::{
|
||||
asym::{self, PrivKey, PubKey},
|
||||
hkdf::{self, Hkdf, HkdfKind},
|
||||
sym::{self, Secret},
|
||||
Random,
|
||||
sym::{self},
|
||||
Random, Secret,
|
||||
},
|
||||
inner::{HandshakeAction, HandshakeTracker, ThreadTracker},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue