Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
core.option.Option_c4 (found in file libcrux_core) mentions libcrux_ml_dsa.polynomial.PolynomialRingElement_24 (found in file libcrux_mldsa65_avx2)
  • Loading branch information
franziskuskiefer committed Dec 5, 2024
1 parent 7bf825a commit 38bf469
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
41 changes: 20 additions & 21 deletions libcrux-ml-dsa/cg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ files:
monomorphizations_using:
- [libcrux_sha3, "*"]

# MLKEM: MISC NON-ARCHITECTURE SPECIFIC HEADERS
- name: libcrux_core
inline_static: true
private:
monomorphizations_of:
- [core, "*"]
- [libcrux_ml_dsa, types, "*"]
- [libcrux_ml_dsa, utils, "*" ]
monomorphizations_using:
- [Eurydice, "*" ]
- [libcrux_ml_dsa, types, "*"]
patterns:
- [core, "*"]
- [libcrux_ml_dsa, types ]
- [libcrux_ml_dsa, constants ]
- [libcrux_ml_dsa, utils, "*" ]
# - [libcrux_ml_dsa, simd, traits ]
api:
- [Eurydice, "*"]

# MLDSA-65

- name: libcrux_mldsa65_avx2
Expand Down Expand Up @@ -93,27 +113,6 @@ files:
- [libcrux_ml_dsa, ml_dsa_generic, instantiations, portable, "*"]
- [core, option, Option_84]


# MLKEM: MISC NON-ARCHITECTURE SPECIFIC HEADERS
- name: libcrux_core
inline_static: true
private:
monomorphizations_of:
- [core, "*"]
- [libcrux_ml_dsa, types, "*"]
- [libcrux_ml_dsa, utils, "*" ]
monomorphizations_using:
- [Eurydice, "*" ]
- [libcrux_ml_dsa, types, "*"]
patterns:
- [core, "*"]
- [libcrux_ml_dsa, types, "*" ]
- [libcrux_ml_dsa, constants ]
- [libcrux_ml_dsa, utils, "*" ]
- [libcrux_ml_dsa, simd, traits ]
api:
- [Eurydice, "*"]

naming:
skip_prefix:
- [ core, core_arch, arm_shared, neon ]
Expand Down
10 changes: 5 additions & 5 deletions libcrux-ml-dsa/cg/code_gen.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This code was generated with the following revisions:
Charon: 45f5a34f336e35c6cc2253bc90cbdb8d812cefa9
Eurydice: e2db6e88adc9995ca9d3dedf7fa9bc4095e9ca20
Karamel: 8c3612018c25889288da6857771be3ad03b75bcd
F*: 5643e656b989aca7629723653a2570c7df6252b9-dirty
Libcrux: ebd9959e4b3ba3155e1f0225ac0764b1a8657d7f
Charon: a68994d00017b76a805d0115ca06c1f2c1805e79
Eurydice: b665364a6d86749566ce2d650d13fa12c8fab2c5
Karamel: 96572bc631fde691a2aea7bce5a5a3838b3a5968
F*: b0961063393215ca65927f017720cb365a193833-dirty
Libcrux: 7bf825af76a34466b18ead540bb08b9631dbfd13
10 changes: 5 additions & 5 deletions libcrux-ml-dsa/cg/header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: MIT or Apache-2.0
*
* This code was generated with the following revisions:
* Charon: 45f5a34f336e35c6cc2253bc90cbdb8d812cefa9
* Eurydice: e2db6e88adc9995ca9d3dedf7fa9bc4095e9ca20
* Karamel: 8c3612018c25889288da6857771be3ad03b75bcd
* F*: 5643e656b989aca7629723653a2570c7df6252b9-dirty
* Libcrux: ebd9959e4b3ba3155e1f0225ac0764b1a8657d7f
* Charon: a68994d00017b76a805d0115ca06c1f2c1805e79
* Eurydice: b665364a6d86749566ce2d650d13fa12c8fab2c5
* Karamel: 96572bc631fde691a2aea7bce5a5a3838b3a5968
* F*: b0961063393215ca65927f017720cb365a193833-dirty
* Libcrux: 7bf825af76a34466b18ead540bb08b9631dbfd13
*/
6 changes: 4 additions & 2 deletions libcrux-ml-dsa/src/ml_dsa_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub(crate) fn generate_key_pair<
#[inline(always)]
pub(crate) fn sign_pre_hashed<
SIMDUnit: Operations,
Shake128: shake128::Xof,
Shake128X4: shake128::XofX4,
Shake256: shake256::DsaXof,
Shake256Xof: shake256::Xof,
Expand Down Expand Up @@ -124,7 +125,7 @@ pub(crate) fn sign_pre_hashed<
if context.len() > CONTEXT_MAX_LEN {
return Err(SigningError::ContextTooLongError);
}
let pre_hashed_message = PH::hash(message);
let pre_hashed_message = PH::hash::<Shake128>(message);
sign_internal::<
SIMDUnit,
Shake128X4,
Expand Down Expand Up @@ -606,6 +607,7 @@ pub(crate) fn verify<
#[inline(always)]
pub(crate) fn verify_pre_hashed<
SIMDUnit: Operations,
Shake128: shake128::Xof,
Shake128X4: shake128::XofX4,
Shake256: shake256::DsaXof,
Shake256Xof: shake256::Xof,
Expand All @@ -630,7 +632,7 @@ pub(crate) fn verify_pre_hashed<
context: &[u8],
signature_serialized: &[u8; SIGNATURE_SIZE],
) -> Result<(), VerificationError> {
let pre_hashed_message = PH::hash(message);
let pre_hashed_message = PH::hash::<Shake128>(message);

verify_internal::<
SIMDUnit,
Expand Down
6 changes: 5 additions & 1 deletion libcrux-ml-dsa/src/ml_dsa_generic/instantiations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
macro_rules! instantiate {
($modp:ident, $simdunit:path, $shake128x4:path, $shake256:path, $shake256xof:path, $shake256x4:path) => {
($modp:ident, $simdunit:path, $shake128:path, $shake128x4:path, $shake256:path, $shake256xof:path, $shake256x4:path) => {
pub mod $modp {
use crate::{
constants::*,
Expand Down Expand Up @@ -148,6 +148,7 @@ macro_rules! instantiate {
) -> Result<MLDSASignature<SIGNATURE_SIZE>, SigningError> {
crate::ml_dsa_generic::sign_pre_hashed::<
$simdunit,
$shake128,
$shake128x4,
$shake256,
$shake256xof,
Expand Down Expand Up @@ -278,6 +279,7 @@ macro_rules! instantiate {
) -> Result<(), VerificationError> {
crate::ml_dsa_generic::verify_pre_hashed::<
$simdunit,
$shake128,
$shake128x4,
$shake256,
$shake256xof,
Expand Down Expand Up @@ -305,6 +307,7 @@ macro_rules! instantiate {
// Portable generic implementations.
instantiate! {portable,
crate::simd::portable::PortableSIMDUnit,
crate::hash_functions::portable::Shake128,
crate::hash_functions::portable::Shake128X4,
crate::hash_functions::portable::Shake256,
crate::hash_functions::portable::Shake256Xof,
Expand All @@ -319,6 +322,7 @@ pub mod avx2;
#[cfg(feature = "simd128")]
instantiate! {neon,
crate::simd::portable::PortableSIMDUnit,
crate::hash_functions::portable::Shake128,
crate::hash_functions::neon::Shake128x4,
crate::hash_functions::portable::Shake256,
crate::hash_functions::portable::Shake256Xof,
Expand Down
2 changes: 2 additions & 0 deletions libcrux-ml-dsa/src/ml_dsa_generic/instantiations/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ mod avx2_feature {
) -> Result<MLDSASignature<SIGNATURE_SIZE>, SigningError> {
crate::ml_dsa_generic::sign_pre_hashed::<
crate::simd::avx2::AVX2SIMDUnit,
crate::hash_functions::portable::Shake128, // XXX: Use simd256
crate::hash_functions::simd256::Shake128x4,
crate::hash_functions::simd256::Shake256,
crate::hash_functions::portable::Shake256Xof, // XXX: Use simd256
Expand Down Expand Up @@ -292,6 +293,7 @@ mod avx2_feature {
) -> Result<(), VerificationError> {
crate::ml_dsa_generic::verify_pre_hashed::<
crate::simd::avx2::AVX2SIMDUnit,
crate::hash_functions::portable::Shake128, // XXX: Use simd256
crate::hash_functions::simd256::Shake128x4,
crate::hash_functions::simd256::Shake256,
crate::hash_functions::portable::Shake256Xof, // XXX: Use simd256
Expand Down
2 changes: 0 additions & 2 deletions libcrux-ml-dsa/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub(crate) struct PolynomialRingElement<SIMDUnit: Operations> {
pub(crate) simd_units: [SIMDUnit; SIMD_UNITS_IN_RING_ELEMENT],
}

pub type OptionalRingElement<SIMDUnit> = Option<PolynomialRingElement<SIMDUnit>>;

impl<SIMDUnit: Operations> PolynomialRingElement<SIMDUnit> {
#[allow(non_snake_case)]
pub(crate) fn ZERO() -> Self {
Expand Down
12 changes: 7 additions & 5 deletions libcrux-ml-dsa/src/pre_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! pre-hash trait for SHAKE-128, with a digest length of 256 bytes.
use crate::{
constants::CONTEXT_MAX_LEN,
hash_functions::shake128::Xof,
hash_functions,
types::{SigningError, VerificationError},
};

Expand All @@ -19,7 +19,7 @@ pub(crate) trait PreHash<const DIGEST_LEN: usize> {
fn oid() -> PreHashOID;

/// Used to derive the pre-hash PH of the message before signing.
fn hash(message: &[u8]) -> [u8; DIGEST_LEN];
fn hash<Shake128: hash_functions::shake128::Xof>(message: &[u8]) -> [u8; DIGEST_LEN];
}

#[allow(non_camel_case_types)]
Expand All @@ -34,9 +34,9 @@ impl PreHash<256> for SHAKE128_PH {
]
}

fn hash(message: &[u8]) -> [u8; 256] {
fn hash<Shake128: hash_functions::shake128::Xof>(message: &[u8]) -> [u8; 256] {
let mut output = [0u8; 256];
crate::hash_functions::portable::Shake128::shake128(message, &mut output);
Shake128::shake128(message, &mut output);

output
}
Expand All @@ -53,12 +53,14 @@ pub(crate) enum DomainSeparationError {
ContextTooLongError,
}

pub(crate) type PreHashResult<'a> = Result<DomainSeparationContext<'a>, DomainSeparationError>;

impl<'a> DomainSeparationContext<'a> {
/// `context` must be at most 255 bytes long.
pub(crate) fn new(
context: &'a [u8],
pre_hash_oid: Option<&'a PreHashOID>,
) -> Result<Self, DomainSeparationError> {
) -> PreHashResult<'a> {
if context.len() > CONTEXT_MAX_LEN {
Err(DomainSeparationError::ContextTooLongError)
} else {
Expand Down

0 comments on commit 38bf469

Please sign in to comment.