-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
mod arithmetic; | ||
mod constants; | ||
mod hash_functions; | ||
mod ml_dsa_generic; | ||
mod matrix; | ||
mod sample; | ||
mod utils; | ||
|
||
mod ml_dsa_generic; | ||
|
||
pub mod ml_dsa_65; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::{arithmetic::PolynomialRingElement, sample::sample_ring_element_for_A}; | ||
|
||
#[allow(non_snake_case)] | ||
#[inline(always)] | ||
pub(crate) fn expand_to_A<const ROWS_IN_A: usize, const COLUMNS_IN_A: usize>( | ||
mut seed: [u8; 34], | ||
transposed: bool, | ||
) -> [[PolynomialRingElement; COLUMNS_IN_A]; ROWS_IN_A] { | ||
let mut A = [[PolynomialRingElement::ZERO; COLUMNS_IN_A]; ROWS_IN_A]; | ||
|
||
for i in 0..ROWS_IN_A { | ||
for j in 0..COLUMNS_IN_A { | ||
seed[32] = i as u8; | ||
seed[33] = j as u8; | ||
|
||
let sampled = sample_ring_element_for_A(seed); | ||
|
||
if transposed { | ||
A[j][i] = sampled; | ||
} else { | ||
A[i][j] = sampled; | ||
} | ||
} | ||
} | ||
|
||
A | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
use crate::hash_functions::H; | ||
use crate::{hash_functions::H, matrix::expand_to_A, utils::into_padded_array}; | ||
|
||
#[allow(non_snake_case)] | ||
pub(crate) fn generate_key_pair< | ||
const ROWS_IN_A: usize, | ||
const COLUMNS_IN_A: usize, | ||
const SECRET_KEY_SIZE: usize, | ||
const PUBLIC_KEY_SIZE: usize, | ||
>( | ||
randomness: [u8; 32], | ||
) -> ([u8; SECRET_KEY_SIZE], [u8; PUBLIC_KEY_SIZE]) { | ||
let seed_expanded = H::<1024>(&randomness); | ||
let (_seed_for_matrix_a, seed_expanded) = seed_expanded.split_at(32); | ||
let (seed_for_A, seed_expanded) = seed_expanded.split_at(32); | ||
let (_seed_for_short_vectors, _random_seed_for_signing) = seed_expanded.split_at(64); | ||
|
||
let _A_hat = expand_to_A::<ROWS_IN_A, COLUMNS_IN_A>(into_padded_array(seed_for_A), false); | ||
|
||
todo!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Pad the `slice` with `0`s at the end. | ||
#[inline(always)] | ||
pub(crate) fn into_padded_array<const LEN: usize>(slice: &[u8]) -> [u8; LEN] { | ||
debug_assert!(slice.len() <= LEN); | ||
let mut out = [0u8; LEN]; | ||
out[0..slice.len()].copy_from_slice(slice); | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters