Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ Messages sealed as one type must be unsealed using the corresponding method, oth
- `RpoRandomCoin`: a struct implementing `FeltRng` as well as the [`RandomCoin`](https://github.com/facebook/winterfell/blob/main/crypto/src/random/mod.rs) trait using RPO hash function.
- `RpxRandomCoin`: a struct implementing `FeltRng` as well as the [`RandomCoin`](https://github.com/facebook/winterfell/blob/main/crypto/src/random/mod.rs) trait using RPX hash function.

## STARK proving system

The STARK module exports foundational components for the STARK proving system. It primarily consists of re-exports from the [Plonky3](https://github.com/Plonky3/Plonky3) project with some Miden-specific [adaptations](https://github.com/0xMiden/p3-miden).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand this quite a bit in the future. Let's add it to the list of follow-ups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few possible additional re-exports were mentioned here:
#720 (comment)

But the re-exports we have as of 7ba721b are rather extensive.


## Make commands

We use `make` to automate building, testing, and other processes. In most cases, `make` commands are wrappers around `cargo` commands with specific arguments. You can view the list of available commands in the [Makefile](Makefile), or run the following command:
Expand Down
6 changes: 3 additions & 3 deletions miden-crypto/benches/common/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::iter;

use miden_crypto::{
Felt, ONE, Word,
test_utils::{prng_array, rand_value},
rand::test_utils::{prng_array, rand_value},
};

// === Byte Array Generation ===
Expand Down Expand Up @@ -81,11 +81,11 @@ pub fn generate_word(seed: &mut [u8; 32]) -> Word {
}

/// Generate a generic value from seed using PRNG
pub fn generate_value<T: miden_crypto::utils::Randomizable + std::fmt::Debug + Clone>(
pub fn generate_value<T: miden_crypto::rand::Randomizable + std::fmt::Debug + Clone>(
seed: &mut [u8; 32],
) -> T {
*seed = prng_array(*seed);
let value: [T; 1] = miden_crypto::test_utils::prng_array(*seed);
let value: [T; 1] = miden_crypto::rand::test_utils::prng_array(*seed);
value[0].clone()
}

Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/benches/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miden_crypto::{
smt::{LeafIndex, SMT_MAX_DEPTH, SimpleSmt},
store::MerkleStore,
},
test_utils::{rand_array, rand_value},
rand::test_utils::{rand_array, rand_value},
};

/// Since MerkleTree can only be created when a power-of-two number of elements is used, the sample
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/aead/aead_rpo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
bytes_to_elements_exact, bytes_to_elements_with_padding, elements_to_bytes,
padded_elements_to_bytes,
zeroize::{Zeroize, ZeroizeOnDrop},
},
zeroize::{Zeroize, ZeroizeOnDrop},
};

#[cfg(all(test, feature = "std"))]
Expand Down
6 changes: 4 additions & 2 deletions miden-crypto/src/aead/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use thiserror::Error;

use crate::{
Felt,
utils::Deserializable,
zeroize::{Zeroize, ZeroizeOnDrop},
utils::{
Deserializable,
zeroize::{Zeroize, ZeroizeOnDrop},
},
};

pub mod aead_rpo;
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/aead/xchacha/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
bytes_to_elements_exact, elements_to_bytes,
zeroize::{Zeroize, ZeroizeOnDrop},
},
zeroize::{Zeroize, ZeroizeOnDrop},
};

#[cfg(all(test, feature = "std"))]
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/dsa/ecdsa_k256_keccak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
bytes_to_packed_u32_elements,
zeroize::{Zeroize, ZeroizeOnDrop},
},
zeroize::{Zeroize, ZeroizeOnDrop},
};

#[cfg(all(test, feature = "std"))]
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/dsa/eddsa_25519_sha512/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
bytes_to_packed_u32_elements,
zeroize::{Zeroize, ZeroizeOnDrop},
},
zeroize::{Zeroize, ZeroizeOnDrop},
};

#[cfg(all(test, feature = "std"))]
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/dsa/falcon512_rpo/keys/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
Word,
dsa::falcon512_rpo::{LOG_N, SK_LEN, hash_to_point::hash_to_point_rpo256, math::ntru_gen},
hash::blake::Blake3_256,
zeroize::{Zeroize, ZeroizeOnDrop},
utils::zeroize::{Zeroize, ZeroizeOnDrop},
};

// CONSTANTS
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/dsa/falcon512_rpo/math/ffsampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use num_complex::{Complex, Complex64};
use rand::Rng;

use super::{fft::FastFft, polynomial::Polynomial, samplerz::sampler_z};
use crate::zeroize::{Zeroize, ZeroizeOnDrop};
use crate::utils::zeroize::{Zeroize, ZeroizeOnDrop};

const SIGMIN: f64 = 1.2778336969128337;

Expand Down
7 changes: 4 additions & 3 deletions miden-crypto/src/dsa/falcon512_rpo/math/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{Inverse, field::FalconFelt};
use crate::{
Felt,
dsa::falcon512_rpo::{MODULUS, N},
zeroize::{Zeroize, ZeroizeOnDrop},
utils::zeroize::{Zeroize, ZeroizeOnDrop},
};

/// Represents a polynomial with coefficients of type F.
Expand Down Expand Up @@ -651,11 +651,12 @@ impl<F: Zeroize> ZeroizeOnDrop for Polynomial<F> {}
#[cfg(all(test, feature = "std"))]
mod tests {
use super::{FalconFelt, N, Polynomial};
use crate::rand::test_utils::rand_array;

#[test]
fn test_negacyclic_reduction() {
let coef1: [u8; N] = crate::test_utils::rand_array();
let coef2: [u8; N] = crate::test_utils::rand_array();
let coef1: [u8; N] = rand_array();
let coef2: [u8; N] = rand_array();

let poly1 = Polynomial::new(coef1.iter().map(|&a| FalconFelt::new(a as i16)).collect());
let poly2 = Polynomial::new(coef2.iter().map(|&a| FalconFelt::new(a as i16)).collect());
Expand Down
6 changes: 4 additions & 2 deletions miden-crypto/src/ecdh/k256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ use rand::{CryptoRng, RngCore};
use crate::{
dsa::ecdsa_k256_keccak::{PUBLIC_KEY_BYTES, PublicKey, SecretKey},
ecdh::KeyAgreementScheme,
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
zeroize::{Zeroize, ZeroizeOnDrop},
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
zeroize::{Zeroize, ZeroizeOnDrop},
},
};

// SHARED SECRET
Expand Down
4 changes: 2 additions & 2 deletions miden-crypto/src/ecdh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use alloc::vec::Vec;
use rand::{CryptoRng, RngCore};
use thiserror::Error;

use crate::{
utils::{Deserializable, Serializable},
use crate::utils::{
Deserializable, Serializable,
zeroize::{Zeroize, ZeroizeOnDrop},
};

Expand Down
6 changes: 4 additions & 2 deletions miden-crypto/src/ecdh/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ use rand::{CryptoRng, RngCore};
use crate::{
dsa::eddsa_25519_sha512::{PublicKey, SecretKey},
ecdh::KeyAgreementScheme,
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
zeroize::{Zeroize, ZeroizeOnDrop},
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
zeroize::{Zeroize, ZeroizeOnDrop},
},
};

// SHARED SECRETE
Expand Down
14 changes: 1 addition & 13 deletions miden-crypto/src/hash/algebraic_sponge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,11 @@ use core::ops::Range;
use p3_field::PrimeCharacteristicRing;

use super::{Felt, Word, ZERO};
use crate::{BasedVectorSpace, PrimeField64};
use crate::field::{BasedVectorSpace, PrimeField64};

pub(crate) mod poseidon2;
pub(crate) mod rescue;

// Re-export the main hash function types
pub use poseidon2::Poseidon2;
// Re-export P3 integration types for public API
pub use poseidon2::{
Poseidon2Challenger, Poseidon2Compression, Poseidon2Hasher, Poseidon2Permutation256,
};
pub use rescue::{
Rpo256, Rpx256,
rpo::{RpoChallenger, RpoCompression, RpoHasher, RpoPermutation256},
rpx::{RpxChallenger, RpxCompression, RpxHasher, RpxPermutation256},
};

// CONSTANTS
// ================================================================================================

Expand Down
4 changes: 2 additions & 2 deletions miden-crypto/src/hash/algebraic_sponge/poseidon2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
AlgebraicSponge, CAPACITY_RANGE, DIGEST_RANGE, Felt, RATE_RANGE, Range, STATE_WIDTH, Word, ZERO,
};
use crate::PrimeCharacteristicRing;
use crate::field::PrimeCharacteristicRing;

mod constants;
use constants::{
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Poseidon2 {

/// Returns a hash of the provided field elements.
#[inline(always)]
pub fn hash_elements<E: crate::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
pub fn hash_elements<E: crate::field::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
<Self as AlgebraicSponge>::hash_elements(elements)
}

Expand Down
3 changes: 0 additions & 3 deletions miden-crypto/src/hash/algebraic_sponge/rescue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ mod mds;
use mds::{MDS, apply_mds};

pub(crate) mod rpo;
pub use rpo::Rpo256;

pub(crate) mod rpx;
pub use rpx::Rpx256;

#[cfg(test)]
mod tests;
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/algebraic_sponge/rescue/rpo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Rpo256 {

/// Returns a hash of the provided field elements.
#[inline(always)]
pub fn hash_elements<E: crate::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
pub fn hash_elements<E: crate::field::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
<Self as AlgebraicSponge>::hash_elements(elements)
}

Expand Down
5 changes: 3 additions & 2 deletions miden-crypto/src/hash/algebraic_sponge/rescue/rpo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use super::{
Felt, Rpo256, STATE_WIDTH,
};
use crate::{
ONE, PrimeCharacteristicRing, PrimeField64, Word, ZERO,
ONE, Word, ZERO,
field::{PrimeCharacteristicRing, PrimeField64},
hash::algebraic_sponge::{AlgebraicSponge, BINARY_CHUNK_SIZE, CAPACITY_RANGE, RATE_WIDTH},
test_utils::rand_value,
rand::test_utils::rand_value,
};

#[test]
Expand Down
4 changes: 2 additions & 2 deletions miden-crypto/src/hash/algebraic_sponge/rescue/rpx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Rpx256 {

/// Returns a hash of the provided field elements.
#[inline(always)]
pub fn hash_elements<E: crate::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
pub fn hash_elements<E: crate::field::BasedVectorSpace<Felt>>(elements: &[E]) -> Word {
<Self as AlgebraicSponge>::hash_elements(elements)
}

Expand Down Expand Up @@ -250,7 +250,7 @@ impl Rpx256 {
/// over the field arithmetic.
mod cubic_ext {
use super::Felt;
use crate::PrimeCharacteristicRing;
use crate::field::PrimeCharacteristicRing;

/// Multiplies two cubic extension field elements.
///
Expand Down
4 changes: 3 additions & 1 deletion miden-crypto/src/hash/algebraic_sponge/rescue/rpx/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use p3_field::PrimeField64;
use proptest::prelude::*;

use super::{Felt, Rpx256};
use crate::{ONE, Word, ZERO, hash::algebraic_sponge::AlgebraicSponge, test_utils::rand_value};
use crate::{
ONE, Word, ZERO, hash::algebraic_sponge::AlgebraicSponge, rand::test_utils::rand_value,
};

// The number of iterations to run the `ext_round_matches_reference_many` test.
#[cfg(all(
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/algebraic_sponge/rescue/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use p3_field::PrimeCharacteristicRing;

use super::{ALPHA, Felt, INV_ALPHA};
use crate::test_utils::rand_value;
use crate::rand::test_utils::rand_value;

#[test]
fn test_alphas() {
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/blake/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use p3_miden_goldilocks::Goldilocks as Felt;
use proptest::prelude::*;

use super::*;
use crate::test_utils::rand_vector;
use crate::rand::test_utils::rand_vector;

#[test]
fn blake3_hash_elements() {
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/keccak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sha3::Digest as Sha3Digest;

use super::{Felt, HasherExt};
use crate::{
PrimeField64,
field::PrimeField64,
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, HexParseError, Serializable,
bytes_to_hex_string, hex_to_bytes,
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/keccak/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::vec::Vec;
use proptest::prelude::*;

use super::*;
use crate::test_utils::rand_vector;
use crate::rand::test_utils::rand_vector;

#[test]
fn keccak256_hash_elements() {
Expand Down
17 changes: 13 additions & 4 deletions miden-crypto/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@ pub mod sha2;

/// Poseidon2 hash function.
pub mod poseidon2 {
pub use super::algebraic_sponge::poseidon2::Poseidon2;
pub use p3_miden_goldilocks::Poseidon2Goldilocks;

pub use super::algebraic_sponge::poseidon2::{
Poseidon2, Poseidon2Challenger, Poseidon2Compression, Poseidon2Hasher,
Poseidon2Permutation256,
};
}

/// Rescue Prime Optimized (RPO) hash function.
pub mod rpo {
pub use super::algebraic_sponge::rescue::Rpo256;
pub use super::algebraic_sponge::rescue::rpo::{
Rpo256, RpoChallenger, RpoCompression, RpoHasher,
};
}

/// Rescue Prime Extended (RPX) hash function.
pub mod rpx {
pub use super::algebraic_sponge::rescue::Rpx256;
pub use super::algebraic_sponge::rescue::rpx::{
Rpx256, RpxChallenger, RpxCompression, RpxHasher,
};
}

pub mod algebraic_sponge;
mod algebraic_sponge;

// TRAITS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/hash/sha2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::vec::Vec;
use proptest::prelude::*;

use super::*;
use crate::test_utils::rand_vector;
use crate::rand::test_utils::rand_vector;

// SHA-256 TESTS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/src/ies/crypto_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloc::vec::Vec;
use rand::{CryptoRng, RngCore};

use super::IesError;
use crate::{Felt, aead::AeadScheme, ecdh::KeyAgreementScheme, zeroize::Zeroizing};
use crate::{Felt, aead::AeadScheme, ecdh::KeyAgreementScheme, utils::zeroize::Zeroizing};

// CRYPTO BOX
// ================================================================================================
Expand Down
Loading