Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikbhargavan committed Jun 23, 2024
1 parent f92efd4 commit 69e71fc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
7 changes: 4 additions & 3 deletions libcrux-ml-kem/src/ind_cca/instantiations.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! instantiate {
($modp:ident, $vector:path, $hash:path) => {

pub mod $modp {
use crate::{
MlKemCiphertext, MlKemKeyPair, MlKemPrivateKey, MlKemPublicKey, MlKemSharedSecret,
KEY_GENERATION_SEED_SIZE, SHARED_SECRET_SIZE,
};

pub(crate) type MlKemKeyPairUnpacked<const K:usize> = crate::types::unpacked::MlKemKeyPairUnpacked<K,$vector>;
pub(crate) type MlKemPublicKeyUnpacked<const K:usize> = crate::types::unpacked::MlKemPublicKeyUnpacked<K,$vector>;
pub(crate) type MlKemKeyPairUnpacked<const K: usize> =
crate::types::unpacked::MlKemKeyPairUnpacked<K, $vector>;
pub(crate) type MlKemPublicKeyUnpacked<const K: usize> =
crate::types::unpacked::MlKemPublicKeyUnpacked<K, $vector>;

/// Portable generate key pair.
pub(crate) fn generate_keypair<
Expand Down
9 changes: 7 additions & 2 deletions libcrux-ml-kem/src/mlkem1024.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! ML-KEM 1024
use super::{constants::*, ind_cca::*, types::{unpacked::*, *}, *};
use super::{
constants::*,
ind_cca::*,
types::{unpacked::*, *},
*,
};

// Kyber 1024 parameters
const RANK_1024: usize = 4;
Expand Down Expand Up @@ -143,7 +148,7 @@ macro_rules! instantiate {
IMPLICIT_REJECTION_HASH_INPUT_SIZE,
>(private_key, ciphertext)
}

// Unpacked API
pub fn generate_key_pair_unpacked(
randomness: [u8; KEY_GENERATION_SEED_SIZE],
Expand Down
9 changes: 6 additions & 3 deletions libcrux-ml-kem/src/mlkem512.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! ML-KEM 512
use super::{constants::*, ind_cca::*, types::{unpacked::*, *}, *};
use super::{
constants::*,
ind_cca::*,
types::{unpacked::*, *},
*,
};

// Kyber 512 parameters
const RANK_512: usize = 2;
Expand Down Expand Up @@ -47,7 +52,6 @@ pub type MlKem512PublicKeyUnpacked<Vector> = MlKemPublicKeyUnpacked<RANK_512, Ve
/// Am Unpacked ML-KEM 512 Key pair
pub type MlKem512KeyPairUnpacked<Vector> = MlKemKeyPairUnpacked<RANK_512, Vector>;


// Instantiate the different functions.
macro_rules! instantiate {
($modp:ident, $p:path, $vec:path) => {
Expand Down Expand Up @@ -200,7 +204,6 @@ macro_rules! instantiate {
IMPLICIT_REJECTION_HASH_INPUT_SIZE,
>(private_key, ciphertext)
}

}
};
}
Expand Down
4 changes: 2 additions & 2 deletions libcrux-ml-kem/src/mlkem768.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub type MlKem768PublicKey = MlKemPublicKey<CPA_PKE_PUBLIC_KEY_SIZE_768>;
pub type MlKem768KeyPair = MlKemKeyPair<SECRET_KEY_SIZE_768, CPA_PKE_PUBLIC_KEY_SIZE_768>;

/// An Unpacked ML-KEM 768 Public key
pub type MlKem768PublicKeyUnpacked<Vector:VectorType> = MlKemPublicKeyUnpacked<RANK_768, Vector>;
pub type MlKem768PublicKeyUnpacked<Vector: VectorType> = MlKemPublicKeyUnpacked<RANK_768, Vector>;
/// Am Unpacked ML-KEM 768 Key pair
pub type MlKem768KeyPairUnpacked<Vector:VectorType> = MlKemKeyPairUnpacked<RANK_768, Vector>;
pub type MlKem768KeyPairUnpacked<Vector: VectorType> = MlKemKeyPairUnpacked<RANK_768, Vector>;

// Instantiate the different functions.
macro_rules! instantiate {
Expand Down
11 changes: 7 additions & 4 deletions libcrux-ml-kem/tests/self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ macro_rules! impl_consistency_unpacked {
let key_pair = $key_gen(randomness);
let randomness = random_array();
let (ciphertext, shared_secret) = $encaps(key_pair.public_key(), randomness);
let (ciphertext_unpacked, shared_secret_unpacked) = $encaps_unpacked(&key_pair_unpacked.public_key, &key_pair_unpacked.public_key_hash, randomness);
let (ciphertext_unpacked, shared_secret_unpacked) = $encaps_unpacked(
&key_pair_unpacked.public_key,
&key_pair_unpacked.public_key_hash,
randomness,
);
assert_eq!(
shared_secret, shared_secret_unpacked,
"lhs: shared_secret, rhs: shared_secret_unpacked"
);
assert_eq!(
ciphertext.as_slice(), ciphertext_unpacked.as_slice(),
ciphertext.as_slice(),
ciphertext_unpacked.as_slice(),
"lhs: ciphertext, rhs: ciphertext_unpacked"
);
let shared_secret_decapsulated = $decaps_unpacked(&key_pair_unpacked, &ciphertext);
Expand Down Expand Up @@ -299,8 +304,6 @@ impl_consistency_unpacked!(
mlkem768::avx2::decapsulate_unpacked
);



impl_modified_ciphertext!(
modified_ciphertext_512,
mlkem1024::generate_key_pair,
Expand Down

0 comments on commit 69e71fc

Please sign in to comment.