mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 08:53:08 +00:00
rename SecretKey to SecretKey32
This commit is contained in:
parent
7c580b5896
commit
b6e19cd9ea
@ -2,7 +2,7 @@ use chat_proto::logoschat::{
|
||||
convos::private_v1::{PrivateV1Frame, private_v1_frame::FrameType},
|
||||
encryption::{Doubleratchet, EncryptedPayload, encrypted_payload::Encryption},
|
||||
};
|
||||
use crypto::SecretKey;
|
||||
use crypto::SecretKey32;
|
||||
use prost::{Message, bytes::Bytes};
|
||||
|
||||
use crate::{
|
||||
@ -15,7 +15,7 @@ use crate::{
|
||||
pub struct PrivateV1Convo {}
|
||||
|
||||
impl PrivateV1Convo {
|
||||
pub fn new(_seed_key: SecretKey) -> Self {
|
||||
pub fn new(_seed_key: SecretKey32) -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use blake2::{
|
||||
Blake2bMac,
|
||||
digest::{FixedOutput, consts::U32},
|
||||
};
|
||||
use crypto::{DomainSeparator, PrekeyBundle, SecretKey, X3Handshake};
|
||||
use crypto::{DomainSeparator, PrekeyBundle, SecretKey32, X3Handshake};
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
|
||||
use crate::crypto::{PublicKey, StaticSecret};
|
||||
@ -24,7 +24,7 @@ impl InboxHandshake {
|
||||
identity_keypair: &StaticSecret,
|
||||
recipient_bundle: &PrekeyBundle,
|
||||
rng: &mut R,
|
||||
) -> (SecretKey, PublicKey) {
|
||||
) -> (SecretKey32, PublicKey) {
|
||||
// Perform X3DH handshake to get shared secret
|
||||
let (shared_secret, ephemeral_public) =
|
||||
InboxKeyExchange::initator(identity_keypair, recipient_bundle, rng);
|
||||
@ -47,7 +47,7 @@ impl InboxHandshake {
|
||||
onetime_prekey: Option<&StaticSecret>,
|
||||
initiator_identity: &PublicKey,
|
||||
initiator_ephemeral: &PublicKey,
|
||||
) -> SecretKey {
|
||||
) -> SecretKey32 {
|
||||
// Perform X3DH to get shared secret
|
||||
let shared_secret = InboxKeyExchange::responder(
|
||||
identity_keypair,
|
||||
@ -61,7 +61,7 @@ impl InboxHandshake {
|
||||
}
|
||||
|
||||
/// Derive keys from X3DH shared secret
|
||||
fn derive_keys_from_shared_secret(shared_secret: SecretKey) -> SecretKey {
|
||||
fn derive_keys_from_shared_secret(shared_secret: SecretKey32) -> SecretKey32 {
|
||||
let seed_key: [u8; 32] = Blake2bMac256::new_with_salt_and_personal(
|
||||
shared_secret.as_bytes(),
|
||||
&[], // No salt - input already has high entropy
|
||||
|
||||
@ -5,7 +5,7 @@ use rand_core::OsRng;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crypto::{PrekeyBundle, SecretKey};
|
||||
use crypto::{PrekeyBundle, SecretKey32};
|
||||
|
||||
use crate::context::Introduction;
|
||||
use crate::conversation::{ChatError, ConversationId, Convo, ConvoFactory, Id, PrivateV1Convo};
|
||||
@ -140,7 +140,7 @@ impl Inbox {
|
||||
fn perform_handshake(
|
||||
&self,
|
||||
payload: proto::EncryptedPayload,
|
||||
) -> Result<(SecretKey, proto::InboxV1Frame), ChatError> {
|
||||
) -> Result<(SecretKey32, proto::InboxV1Frame), ChatError> {
|
||||
let handshake = Self::extract_payload(payload)?;
|
||||
let header = handshake
|
||||
.header
|
||||
|
||||
@ -4,27 +4,27 @@ pub use generic_array::{GenericArray, typenum::U32};
|
||||
use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||
|
||||
#[derive(Clone, Zeroize, ZeroizeOnDrop, PartialEq)]
|
||||
pub struct SecretKey([u8; 32]);
|
||||
pub struct SecretKey32([u8; 32]);
|
||||
|
||||
impl SecretKey {
|
||||
impl SecretKey32 {
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
self.0.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for SecretKey {
|
||||
impl From<[u8; 32]> for SecretKey32 {
|
||||
fn from(value: [u8; 32]) -> Self {
|
||||
SecretKey(value)
|
||||
SecretKey32(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GenericArray<u8, U32>> for SecretKey {
|
||||
impl From<GenericArray<u8, U32>> for SecretKey32 {
|
||||
fn from(value: GenericArray<u8, U32>) -> Self {
|
||||
SecretKey(value.into())
|
||||
SecretKey32(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for SecretKey {
|
||||
impl Debug for SecretKey32 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("SecretKey").field(&"<32 bytes>").finish()
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ use rand_core::{CryptoRng, RngCore};
|
||||
use sha2::Sha256;
|
||||
use x25519_dalek::{PublicKey, SharedSecret, StaticSecret};
|
||||
|
||||
use crate::keys::SecretKey;
|
||||
use crate::keys::SecretKey32;
|
||||
|
||||
/// A prekey bundle containing the public keys needed to initiate an X3DH key exchange.
|
||||
#[derive(Clone, Debug)]
|
||||
@ -35,7 +35,7 @@ impl<D: DomainSeparator> X3Handshake<D> {
|
||||
dh2: &SharedSecret,
|
||||
dh3: &SharedSecret,
|
||||
dh4: Option<&SharedSecret>,
|
||||
) -> SecretKey {
|
||||
) -> SecretKey32 {
|
||||
// Concatenate all DH outputs
|
||||
let mut km = Vec::new();
|
||||
km.extend_from_slice(dh1.as_bytes());
|
||||
@ -52,7 +52,7 @@ impl<D: DomainSeparator> X3Handshake<D> {
|
||||
hk.expand(Self::domain_separator(), &mut output)
|
||||
.expect("32 bytes is valid HKDF output length");
|
||||
|
||||
// Move into SecretKey so it gets zeroized on drop.
|
||||
// Move into SecretKey32 so it gets zeroized on drop.
|
||||
output.into()
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ impl<D: DomainSeparator> X3Handshake<D> {
|
||||
identity_keypair: &StaticSecret,
|
||||
recipient_bundle: &PrekeyBundle,
|
||||
rng: &mut R,
|
||||
) -> (SecretKey, PublicKey) {
|
||||
) -> (SecretKey32, PublicKey) {
|
||||
// Generate ephemeral key for this handshake (using StaticSecret for multiple DH operations)
|
||||
let ephemeral_secret = StaticSecret::random_from_rng(rng);
|
||||
let ephemeral_public = PublicKey::from(&ephemeral_secret);
|
||||
@ -106,7 +106,7 @@ impl<D: DomainSeparator> X3Handshake<D> {
|
||||
onetime_prekey: Option<&StaticSecret>,
|
||||
initiator_identity: &PublicKey,
|
||||
initiator_ephemeral: &PublicKey,
|
||||
) -> SecretKey {
|
||||
) -> SecretKey32 {
|
||||
let dh1 = signed_prekey.diffie_hellman(initiator_identity);
|
||||
let dh2 = identity_keypair.diffie_hellman(initiator_ephemeral);
|
||||
let dh3 = signed_prekey.diffie_hellman(initiator_ephemeral);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user