anemoi/pallas/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 = 14;
#[derive(Debug, Clone)]
pub struct AnemoiPallas_4_3;
impl<'a> Anemoi<'a, Felt> for AnemoiPallas_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!(
"18712880128871405660082341349730785565255823061628968703358865218751151417752"
),
MontFp!(
"28852735674895552575971176920132291269394325921159912401133547399551253823836"
),
MontFp!(
"26914183606871107651657798736743760395879931340732129890542130715219568635233"
),
MontFp!(
"27817720939029377917254451534893082130205436526319390756748725483821043682962"
),
],
[
MontFp!(
"7488280825670435445228503460715501154849843394606817722757467631878489491576"
),
MontFp!(
"2100987632991283471444150478455496231109403827315568273860288078718165741464"
),
MontFp!(
"6222520451026549836150679335151684263209710554091853508002985812478940178025"
),
MontFp!(
"2331294531406910958527822246275943944406710088456573436153274102010924017354"
),
],
[
MontFp!(
"28236554368047742021122674913664702925498051699009480797855123423396409127424"
),
MontFp!(
"28571956557648956032290472207534755544155543961067813238521143563020835260190"
),
MontFp!(
"11890864596492355263204927068825137107155013350717250075271605503208215692102"
),
MontFp!(
"2146385911254725323188938434966974025494729246886919375868288131679851507942"
),
],
[
MontFp!(
"5662602441506544082794930546694382613083638283645264190718286175614291950641"
),
MontFp!(
"26426230950527356812142221026275565116303738754790084240578429795339466034164"
),
MontFp!(
"7606431703282712728472704009353367791943393945493591493569682126997947706297"
),
MontFp!(
"12646889247097562650417490351564075056024075418253246000525029119338492484289"
),
],
[
MontFp!(
"10825787260607616751169609178840463930489641212864382637613146607964956037921"
),
MontFp!(
"12945133801140879334333735332705086675570931561015785398145176519124729231398"
),
MontFp!(
"25796573378662241386672798266462663816631914566359170227059964498775517557593"
),
MontFp!(
"22905675056529224862135491481164551982575868649347349452708091844005700084745"
),
],
[
MontFp!(
"2706293383103552142713750355410095922374008816626706310439385030279551962855"
),
MontFp!(
"25095174773049296127150329242829615480392172531687294760034581117446118221012"
),
MontFp!(
"26266110874738862263602215168345217096550795904430199626942629792028606958240"
),
MontFp!(
"28603368972835430820221743278802074927949345284922929996556953635303950088156"
),
],
];
let output = [
[
MontFp!(
"11579208923731619542357098500868790785345222592776624286381870705739987052135"
),
MontFp!(
"11579208923731619542357098500868790785345222592776624286381870705739987052135"
),
Felt::zero(),
Felt::zero(),
],
[
MontFp!(
"21735578927475698800610569875486878598709331368954848907691439386750294515554"
),
MontFp!(
"21735578927475698800610569875486878598709331368954848907691439386750294515554"
),
MontFp!(
"14915059756306458668798776150463074115887270782104658469523764643553127876149"
),
MontFp!(
"14915059756306458668798776150463074115887270782104658469523764643553127876149"
),
],
[
MontFp!(
"8778638346924233418081111828888910239654127576710317834940372077697612057229"
),
MontFp!(
"8778638346924233418081111828888910239654127576710317834940372077697612057229"
),
MontFp!(
"22051619713425230766531768624512758113922728761788164591626179149121958488460"
),
MontFp!(
"22051619713425230766531768624512758113922728761788164591626179149121958488460"
),
],
[
MontFp!(
"11579208923731619542357098500868790785345222592776624286381870705739987052141"
),
MontFp!(
"11579208923731619542357098500868790785345222592776624286381870705739987052141"
),
MontFp!(
"28948022309329048855892746252171976963363056481941560715954676764349967630336"
),
MontFp!(
"28948022309329048855892746252171976963363056481941560715954676764349967630336"
),
],
[
MontFp!(
"17283201414116924245089329907535698111224648658784221600439748639335637674941"
),
MontFp!(
"26479782800068398970458204182012705758401605304420106167204650590713256532182"
),
MontFp!(
"10338391597216277656942980413829008466777109536073581900877591835021695568819"
),
MontFp!(
"17123282312932080046038193128576470212124183002819788764877324951792820434754"
),
],
[
MontFp!(
"6206380954349620232623210204008393720703543989720135339896580206585522492619"
),
MontFp!(
"16358178024424626585878286405746802069580448534221731165679599104937972035362"
),
MontFp!(
"1725186594966228291626100224452100382425697018376797116674060244334399737935"
),
MontFp!(
"22511022351156139808252235478233147735737684785393794001239173856649217523884"
),
],
[
MontFp!(
"1501345805127759538149278409744046764755030147159523194334056836741639537914"
),
MontFp!(
"2072956593715702166804090764699142512499267021860921056724909591595402265164"
),
MontFp!(
"6794616548982850581352118323703858558247511785700686750944534384011588938265"
),
MontFp!(
"28891023274198955119276558361602207121843074497319805569597386468487474083941"
),
],
[
MontFp!(
"12768072330711405752402872149949159672547968162080820602959168114898639808665"
),
MontFp!(
"3189142344855296694473746181389271523945849654798698928000280836774441230698"
),
MontFp!(
"20167495834362902685692827595809744708982207525482514019908874904371289631934"
),
MontFp!(
"476365962398447037164228410788223316602498531574527301541232344419852537249"
),
],
[
MontFp!(
"15863354971048065449627781299461239741107190960137886773206747362106533641213"
),
MontFp!(
"10443118821636765910392437596462640759768063449734247551061174994355315788226"
),
MontFp!(
"25787971215416328828361145584498935717599739690296329140906648755455106361026"
),
MontFp!(
"25233982640752157338965249744316550200028374932491477612911337158015794810420"
),
],
[
MontFp!(
"26879508395061745657933050746142536283130246035495192961566834648341564386249"
),
MontFp!(
"19414158739869868624990935872412201125324268703029552775035867917335734225509"
),
MontFp!(
"16584764994245004770894514188341380367909435067872517650346782058589958303457"
),
MontFp!(
"19769027774488544067737788505065028224861787632221296613317373544887464195211"
),
],
];
for i in input.iter_mut() {
AnemoiPallas_4_3::sbox_layer(i);
}
for (&i, o) in input.iter().zip(output) {
assert_eq!(i, o);
}
}
}