refactor: flattened repo structure
This commit is contained in:
parent
2f3dcd47e3
commit
7395697a68
11 changed files with 33 additions and 34 deletions
24
Cargo.toml
24
Cargo.toml
|
@ -1,4 +1,20 @@
|
||||||
[workspace]
|
[package]
|
||||||
members = [
|
name = "miden-crypto"
|
||||||
"crypto"
|
version = "0.1.0"
|
||||||
]
|
description="Miden Cryptographic primitives"
|
||||||
|
authors = ["miden contributors"]
|
||||||
|
readme="README.md"
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://github.com/0xPolygonMiden/crypto"
|
||||||
|
categories = ["cryptography", "no-std"]
|
||||||
|
keywords = ["miden", "crypto", "hash", "merkle"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
winter_crypto = { version = "0.4.1", package = "winter-crypto" }
|
||||||
|
winter_math = { version = "0.4.1", package = "winter-math" }
|
||||||
|
winter_utils = { version = "0.4.1", package = "winter-utils" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
proptest = "1.0.0"
|
||||||
|
rand_utils = { version = "0.4", package = "winter-rand-utils" }
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "crypto"
|
|
||||||
version = "0.1.0"
|
|
||||||
description="Miden Cryptographic primitives"
|
|
||||||
authors = ["miden contributors"]
|
|
||||||
readme="README.md"
|
|
||||||
license = "MIT"
|
|
||||||
repository = "https://github.com/0xPolygonMiden/crypto"
|
|
||||||
categories = ["cryptography", "no-std"]
|
|
||||||
keywords = ["miden", "crypto", "hash", "merkle"]
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
winter_utils = { version = "0.4.1", package = "winter-utils" }
|
|
||||||
winter_math = { version = "0.4.1", package = "winter-math" }
|
|
||||||
winter_crypto = { version = "0.4.1", package = "winter-crypto" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
proptest = "1.0.0"
|
|
||||||
rand_utils = { version = "0.4", package = "winter-rand-utils" }
|
|
|
@ -1,6 +1,8 @@
|
||||||
use super::DIGEST_SIZE;
|
use super::DIGEST_SIZE;
|
||||||
use crate::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
use crate::{
|
||||||
use crate::{Digest, Felt, StarkField, ZERO};
|
ByteReader, ByteWriter, Deserializable, DeserializationError, Digest, Felt, Serializable,
|
||||||
|
StarkField, ZERO,
|
||||||
|
};
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
|
||||||
// DIGEST TRAIT IMPLEMENTATIONS
|
// DIGEST TRAIT IMPLEMENTATIONS
|
|
@ -34,11 +34,11 @@ pub(crate) const fn mds_multiply_freq(state: [u64; 12]) -> [u64; 12] {
|
||||||
let (u8, u9, u10) = fft4_real([s2, s5, s8, s11]);
|
let (u8, u9, u10) = fft4_real([s2, s5, s8, s11]);
|
||||||
|
|
||||||
// This where the multiplication in frequency domain is done. More precisely, and with
|
// This where the multiplication in frequency domain is done. More precisely, and with
|
||||||
// the appropriate permuations in between, the sequence of
|
// the appropriate permutations in between, the sequence of
|
||||||
// 3-point FFTs --> multiplication by twiddle factors --> Hadamard multiplication -->
|
// 3-point FFTs --> multiplication by twiddle factors --> Hadamard multiplication -->
|
||||||
// 3 point iFFTs --> multiplication by (inverse) twiddle factors
|
// 3 point iFFTs --> multiplication by (inverse) twiddle factors
|
||||||
// is "squashed" into one step composed of the functions "block1", "block2" and "block3".
|
// is "squashed" into one step composed of the functions "block1", "block2" and "block3".
|
||||||
// The expressions in the aformentioned functions are the result of explicit computations
|
// The expressions in the aforementioned functions are the result of explicit computations
|
||||||
// combined with the Karatsuba trick for the multiplication of Complex numbers.
|
// combined with the Karatsuba trick for the multiplication of Complex numbers.
|
||||||
|
|
||||||
let [v0, v4, v8] = block1([u0, u4, u8], MDS_FREQ_BLOCK_ONE);
|
let [v0, v4, v8] = block1([u0, u4, u8], MDS_FREQ_BLOCK_ONE);
|
||||||
|
@ -184,7 +184,7 @@ mod tests {
|
||||||
for i in 0..STATE_WIDTH {
|
for i in 0..STATE_WIDTH {
|
||||||
v1[i] = Felt::new(a[i]);
|
v1[i] = Felt::new(a[i]);
|
||||||
}
|
}
|
||||||
v2 = v1.clone();
|
v2 = v1;
|
||||||
|
|
||||||
apply_mds_naive(&mut v1);
|
apply_mds_naive(&mut v1);
|
||||||
Rpo256::apply_mds(&mut v2);
|
Rpo256::apply_mds(&mut v2);
|
|
@ -5,12 +5,12 @@ use core::{convert::TryInto, ops::Range};
|
||||||
mod digest;
|
mod digest;
|
||||||
pub use digest::RpoDigest256;
|
pub use digest::RpoDigest256;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
mod mds_freq;
|
mod mds_freq;
|
||||||
use mds_freq::mds_multiply_freq;
|
use mds_freq::mds_multiply_freq;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
|
@ -6,6 +6,7 @@ use core::convert::TryInto;
|
||||||
use rand_utils::rand_value;
|
use rand_utils::rand_value;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::needless_range_loop)]
|
||||||
fn mds_inv_test() {
|
fn mds_inv_test() {
|
||||||
let mut mul_result = [[Felt::new(0); STATE_WIDTH]; STATE_WIDTH];
|
let mut mul_result = [[Felt::new(0); STATE_WIDTH]; STATE_WIDTH];
|
||||||
for i in 0..STATE_WIDTH {
|
for i in 0..STATE_WIDTH {
|
||||||
|
@ -29,7 +30,7 @@ fn mds_inv_test() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_alphas() {
|
fn test_alphas() {
|
||||||
let e: Felt = Felt::new(rand_value());
|
let e: Felt = Felt::new(rand_value());
|
||||||
let e_exp = e.exp(ALPHA.into());
|
let e_exp = e.exp(ALPHA);
|
||||||
assert_eq!(e, e_exp.exp(INV_ALPHA));
|
assert_eq!(e, e_exp.exp(INV_ALPHA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ fn hash_test_vectors() {
|
||||||
];
|
];
|
||||||
|
|
||||||
for i in 0..elements.len() {
|
for i in 0..elements.len() {
|
||||||
let expected = RpoDigest256::new(EXPECTED[i].try_into().unwrap());
|
let expected = RpoDigest256::new(EXPECTED[i]);
|
||||||
let result = Rpo256::hash_elements(&elements[..(i + 1)]);
|
let result = Rpo256::hash_elements(&elements[..(i + 1)]);
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue