Skip to content

Commit

Permalink
Added sk_to_pk() for Kem trait and implemented for dhkem (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycscaly authored Mar 19, 2023
1 parent 1232a8f commit bef12c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub trait Kem: Sized {
#[cfg(not(feature = "serde_impls"))]
type PrivateKey: Clone + PartialEq + Eq + Serializable + Deserializable;

/// Computes the public key of a given private key
fn sk_to_pk(sk: &Self::PrivateKey) -> Self::PublicKey;

/// The encapsulated key for this KEM. This is used by the recipient to derive the shared
/// secret.
#[cfg(feature = "serde_impls")]
Expand Down
7 changes: 6 additions & 1 deletion src/kem/dhkem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ macro_rules! impl_dhkem {

// The encapped key is the ephemeral pubkey
let encapped_key = {
let pk_eph = <$dhkex as DhKeyExchange>::sk_to_pk(&sk_eph);
let pk_eph = <$kem_name as KemTrait>::sk_to_pk(&sk_eph);
EncappedKey(pk_eph)
};

Expand Down Expand Up @@ -212,6 +212,11 @@ macro_rules! impl_dhkem {
<$dhkex as DhKeyExchange>::derive_keypair::<$kdf>(&suite_id, ikm)
}

/// Computes the public key of a given private key
fn sk_to_pk(sk: &PrivateKey) -> PublicKey {
<$dhkex as DhKeyExchange>::sk_to_pk(sk)
}

// Runs encap_with_eph using a random ephemeral key
fn encap<R: CryptoRng + RngCore>(
pk_recip: &Self::PublicKey,
Expand Down

0 comments on commit bef12c5

Please sign in to comment.