Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ impl<const LIMBS: usize, const N: usize, MOD: ConstMontyParams<LIMBS>> PrivateKe
Self { params, key }
}

pub(crate) const fn params(&self) -> CsidhParams<LIMBS, N, MOD> {
/// Obtains the parameters used by this `PrivateKey`
pub const fn params(&self) -> CsidhParams<LIMBS, N, MOD> {
self.params
}

pub(crate) const fn key(&self) -> [u32; N] {
///Obtains the key material in this `PrivateKey`
pub const fn key(&self) -> [u32; N] {
self.key
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ where
}
}

///Creates a foreign public key from this `PublicKey`
pub fn to_repr(&self) -> Uint<SAT_LIMBS> {
return self.key().to_montgomery();
}

pub(crate) const fn key(&self) -> ConstMontyForm<MOD, SAT_LIMBS> {
self.key
}
Expand Down
25 changes: 24 additions & 1 deletion src/shared_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crypto_bigint::{
rand_core::CryptoRngCore,
};

use crate::{csidh::csidh, private_key::PrivateKey, public_key::PublicKey};
use crate::{
CsidhParams, csidh::csidh, montgomery_curve::MontgomeryCurve, private_key::PrivateKey,
public_key::PublicKey,
};

/// A shared secret created with the CSIDH key exchange.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -36,4 +39,24 @@ where
),
}
}

/// Constructs a `SharedSecret` from the foreign shared secret, if the secret is valid.
#[must_use]
pub fn new<const N: usize>(
params: CsidhParams<SAT_LIMBS, N, MOD>,
shared_secret: Uint<SAT_LIMBS>,
rng: &mut impl CryptoRngCore,
) -> Option<Self> {
let shared_secret = ConstMontyForm::new(&shared_secret);
if MontgomeryCurve::new(params, shared_secret).is_supersingular(rng) {
Some(Self { shared_secret })
} else {
None
}
}

///Creates a foreign shared secret from this `SharedSecret`
pub fn to_repr(&self) -> Uint<SAT_LIMBS> {
return self.shared_secret.to_montgomery();
}
}