anemoi/ed_on_bls12_377/anemoi_4_3/
mod.rsuse super::{sbox, Felt, MontFp};
use crate::{Anemoi, Jive, Sponge};
use ark_ff::{One, Zero};
mod digest;
mod hasher;
mod round_constants;
pub use digest::AnemoiDigest;
pub const STATE_WIDTH: usize = 4;
pub const RATE_WIDTH: usize = 3;
pub const NUM_COLUMNS: usize = 2;
pub const DIGEST_SIZE: usize = 1;
pub const NUM_HASH_ROUNDS: usize = 13;
#[derive(Debug, Clone)]
pub struct AnemoiEdOnBls12_377_4_3;
impl<'a> Anemoi<'a, Felt> for AnemoiEdOnBls12_377_4_3 {
const NUM_COLUMNS: usize = NUM_COLUMNS;
const NUM_ROUNDS: usize = NUM_HASH_ROUNDS;
const WIDTH: usize = STATE_WIDTH;
const RATE: usize = RATE_WIDTH;
const OUTPUT_SIZE: usize = DIGEST_SIZE;
const ARK_C: &'a [Felt] = &round_constants::C;
const ARK_D: &'a [Felt] = &round_constants::D;
const GROUP_GENERATOR: u32 = sbox::BETA;
const ALPHA: u32 = sbox::ALPHA;
const INV_ALPHA: Felt = sbox::INV_ALPHA;
const BETA: u32 = sbox::BETA;
const DELTA: Felt = sbox::DELTA;
fn exp_by_inv_alpha(x: Felt) -> Felt {
sbox::exp_by_inv_alpha(&x)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sbox() {
let mut input = [
[Felt::zero(); 4],
[Felt::one(); 4],
[Felt::zero(), Felt::zero(), Felt::one(), Felt::one()],
[Felt::one(), Felt::one(), Felt::zero(), Felt::zero()],
[
MontFp!(
"6940611250961405825545120029831205176738938552303008099611294173446214664691"
),
MontFp!(
"5480101850489696149840075166530318206489985128150744820471435535091528839652"
),
MontFp!(
"7201708049151036562000911944571756000547188117994933461815572531099111507008"
),
MontFp!(
"2827974473455700078166226024266488132656186871950920903129036949398605833629"
),
],
[
MontFp!(
"3797298936296365643814910403003368678726980427948810943421657673572178221272"
),
MontFp!(
"3828813336966645323320224908314624281093027915540569354320022538372988152473"
),
MontFp!(
"1736474654150736285873001750930727146127814411691408428537206120670446282294"
),
MontFp!(
"5128204574980809977822483630871447033147725725424331254019341452653455654924"
),
],
[
MontFp!(
"363367089441777931868044811987807633905545635069929092712399993719093576081"
),
MontFp!(
"4499104641455590180541887405234538384893195314093643162939427056350664747151"
),
MontFp!(
"322082831357193867657259588842970988302030045428218803173011288946367489601"
),
MontFp!(
"2550486608303639259333928490889681998380932297525433923771649375659301661356"
),
],
[
MontFp!(
"569885108850314383039787650749237519609027256648980365651438143735816362452"
),
MontFp!(
"2231761616448584541799204987982427589306080774164492939411651502918197836282"
),
MontFp!(
"975958182683693184298678181982021390187979817693304378783961528549635345076"
),
MontFp!(
"6800777224506517112003788618327461160471360483680685236270115242024102433772"
),
],
[
MontFp!(
"2178456317658974621524416648664796240015650299869313616773773046556512624500"
),
MontFp!(
"6108764474179910781895022974008558967594975622651332911031649475673777444941"
),
MontFp!(
"322789571245927139906087806656368609474704183617327852687875513826059978167"
),
MontFp!(
"2036015014603942867052188337935912876869958747975216855231584534899562463341"
),
],
[
MontFp!(
"6888589121497847879114382779391578918240281139874908089359455035911570474458"
),
MontFp!(
"4932041139906557449394989927615093637991458700273301564730524306069053433570"
),
MontFp!(
"6707233285329233695459704472887655906779798762621322395753642225481709082973"
),
MontFp!(
"4279400969981279096458604462286536561659734209815053084820881239939402418016"
),
],
];
let output = [
[
MontFp!(
"1151517511285686876033930673470210890642168091157372340172986380352373987142"
),
MontFp!(
"1151517511285686876033930673470210890642168091157372340172986380352373987142"
),
Felt::zero(),
Felt::zero(),
],
[
MontFp!(
"6365899358248349268142114350217140688230280935934585545650923395666961413055"
),
MontFp!(
"6365899358248349268142114350217140688230280935934585545650923395666961413055"
),
MontFp!(
"6687234439711495246728724424832755914754252582501095871411974444826560185425"
),
MontFp!(
"6687234439711495246728724424832755914754252582501095871411974444826560185425"
),
],
[
MontFp!(
"1259102676294307221997675460062050531223883403969519571426325121918383273022"
),
MontFp!(
"1259102676294307221997675460062050531223883403969519571426325121918383273022"
),
MontFp!(
"7394748313577717922329439561482524665112163885958294194408694881596009888759"
),
MontFp!(
"7394748313577717922329439561482524665112163885958294194408694881596009888759"
),
],
[
MontFp!(
"1151517511285686876033930673470210890642168091157372340172986380352373987165"
),
MontFp!(
"1151517511285686876033930673470210890642168091157372340172986380352373987165"
),
MontFp!(
"8444461749428370424248824938781546531375899335154063827935233455917409239040"
),
MontFp!(
"8444461749428370424248824938781546531375899335154063827935233455917409239040"
),
],
[
MontFp!(
"7962439147697478800520582761847111012106735318125829846366291618908473686116"
),
MontFp!(
"7058751001080730959547442434495302260582693544412828808219138906337451517161"
),
MontFp!(
"7610759523417427095136375189077605713450842926189142665114958923389951390483"
),
MontFp!(
"7370601767943888934127439971298429071576548952526549407838407200704701145515"
),
],
[
MontFp!(
"2927660095822284546401031412254364029035550069433219717273462954925109590672"
),
MontFp!(
"6929673295900641592120861566798023414690473061652437589990009194949549428303"
),
MontFp!(
"4959604256674896033311385996155529284422440264041445539258111854751191937263"
),
MontFp!(
"644775785228329987611955612280721302113108438087791143571578304392216755758"
),
],
[
MontFp!(
"950631625887038367895927182524611804160977170511614282563728402345375887472"
),
MontFp!(
"2761794990801377404145971147931082875758064182610942949242394014861101949123"
),
MontFp!(
"8292379064179071091961530677648164322527913498403800659027433703574803746886"
),
MontFp!(
"5349708320358365651991136572392417727487783610421709871664347540256647040707"
),
],
[
MontFp!(
"1969676591619887399313777813313029730106501074884812896398494003208794257303"
),
MontFp!(
"7623993127594691993810168322669423564777544844991491103471558310861331177665"
),
MontFp!(
"7865489468706356141413765929518262062562091873670617664420962727992171677397"
),
MontFp!(
"1047255922660906029293756125324473874091747869075898395946061648959722451391"
),
],
[
MontFp!(
"7028600421814477627558300765007849180036842437989558086681357484107076343216"
),
MontFp!(
"2100349465037004852214713977415406790590064557129937251556358608846711292012"
),
MontFp!(
"7794677823110842833881725728765381400261512740202187384149964282047633316580"
),
MontFp!(
"1277567984187090426540102474916764011511418249317300200728389135555258671114"
),
],
[
MontFp!(
"5114352268268160726646255196019903626981936965659310958570594586662576745581"
),
MontFp!(
"774860654520724039647175689904190465106549292473554403022581208001425309882"
),
MontFp!(
"4521297766675132714960096996876587301299300215269750173311992361871990712733"
),
MontFp!(
"880067337913507515189560951296717643033128059481477252400992450470381181296"
),
],
];
for i in input.iter_mut() {
AnemoiEdOnBls12_377_4_3::sbox_layer(i);
}
for (&i, o) in input.iter().zip(output) {
assert_eq!(i, o);
}
}
}