use 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 AnemoiVesta_4_3;
impl<'a> Anemoi<'a, Felt> for AnemoiVesta_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!(
"17171575821044835452646983376891657746598420360665916302857913112615155188481"
),
MontFp!(
"4878259343889800676637792865429595913732079354642033188788788548816160388735"
),
MontFp!(
"14710586041044452280724909007581961178636649140337447602844509492879394113222"
),
MontFp!(
"14763126680150486047850907515297623604390978801529782376208845118079999547174"
),
],
[
MontFp!(
"17621725050880138854641482650591645168660210996317222444321058926774415541946"
),
MontFp!(
"13067325682471079882811673387226046556407138012917413608330391951960387495410"
),
MontFp!(
"20911986584380119522392938022935582955713091835803437809976548779028892215661"
),
MontFp!(
"17298480895319073476099634353198223959109770492655180223644829345139705168365"
),
],
[
MontFp!(
"13534062722920228579078071013506040783750843313080406768993540646788604385176"
),
MontFp!(
"26851346411244739169665985676194362370977424369866209266327946801651837149058"
),
MontFp!(
"12968329156644290669691681918059690306978208003866808993210570576582841655293"
),
MontFp!(
"21184218576550897586080893660460594353277491003122420065397739788693455441109"
),
],
[
MontFp!(
"17504721576578377929854363754818129014302454236479094309892572904535169942869"
),
MontFp!(
"17256871907841874512168520633397755541046680509612495348304533123172126069744"
),
MontFp!(
"16573708108955804589285207554694926372644581797962983706855707412377533942212"
),
MontFp!(
"1001195731002069601021768787609669443963929305292415139649356731428403204249"
),
],
[
MontFp!(
"21476588965425360576536796024756252860916517597530022982052267963267761980984"
),
MontFp!(
"17365209058103552181676089103846560200758866117938205841358160405187644279990"
),
MontFp!(
"16617787352584448859685152382705822107925311942425148627685165704166212993664"
),
MontFp!(
"2919794818120166755501845600665380143239158883070227393012670214344361883435"
),
],
[
MontFp!(
"3663837741866278150801204926023987330338046375536699520520320692280869686326"
),
MontFp!(
"5626342828308728729030948740359160208771225597340085483888793900808668920280"
),
MontFp!(
"25341432683205836473097754503018431181083054988433449428007954708327253738217"
),
MontFp!(
"15391436080588677843251606356820121755337819137001567922095591061616851369448"
),
],
];
let output = [
[
MontFp!(
"11579208923731619542357098500868790785345222592776658951871897099357345179239"
),
MontFp!(
"11579208923731619542357098500868790785345222592776658951871897099357345179239"
),
Felt::zero(),
Felt::zero(),
],
[
MontFp!(
"13565375592455225805458964934459476225912655788084948267498268443578124721632"
),
MontFp!(
"13565375592455225805458964934459476225912655788084948267498268443578124721632"
),
MontFp!(
"9688406656496048098325282220348971925838074278218514686842913989361614061362"
),
MontFp!(
"9688406656496048098325282220348971925838074278218514686842913989361614061362"
),
],
[
MontFp!(
"2367797382831619836622158180640631392193461256316785256748737102603438284997"
),
MontFp!(
"2367797382831619836622158180640631392193461256316785256748737102603438284997"
),
MontFp!(
"22890698294176523999447614696141668677027690702028879487883356180097137464994"
),
MontFp!(
"22890698294176523999447614696141668677027690702028879487883356180097137464994"
),
],
[
MontFp!(
"11579208923731619542357098500868790785345222592776658951871897099357345179245"
),
MontFp!(
"11579208923731619542357098500868790785345222592776658951871897099357345179245"
),
MontFp!(
"28948022309329048855892746252171976963363056481941647379679742748393362948096"
),
MontFp!(
"28948022309329048855892746252171976963363056481941647379679742748393362948096"
),
],
[
MontFp!(
"10834673606358093173944279745976759059282896484598866610299737717080841298894"
),
MontFp!(
"14751616569792947008809107589976394618335553401465142648266392823583311269481"
),
MontFp!(
"28915835230101313873104310991681564688490043581744718728292376228642036830592"
),
MontFp!(
"7282709690508471028387940016197311947640076145872685038693283675273937439736"
),
],
[
MontFp!(
"26000345689549895363283873872451186641162516373012354417251023714780009927003"
),
MontFp!(
"13849124917766027264899160017673016264585759399986798614785827738974797194155"
),
MontFp!(
"8955784606601724943377132411560566113265992763465987885117815782293937851495"
),
MontFp!(
"6565333146518532840849043401826609024181130017038960798608855468883102381414"
),
],
[
MontFp!(
"21109420587697170836832911867087823108857795784397864682870252300989133756020"
),
MontFp!(
"17188055203546690417044651390023546199594064434077150965740084623882793877514"
),
MontFp!(
"20085797212322074806135678993748941530758528924846634705082758590430235069635"
),
MontFp!(
"24268073510990283425579455729982488115856346090827060961647926830361310483848"
),
],
[
MontFp!(
"16824129626344096135954812067640680184165094020670516973289821648459956174106"
),
MontFp!(
"17316199417585477116623334871792239358691009061600084787253680017279645782888"
),
MontFp!(
"22375672866738589057574253392637204503002483931111484491573463969182722351809"
),
MontFp!(
"28726833968838884390617957057713314393911952670281654565341057363619249338673"
),
],
[
MontFp!(
"11968530618465310232016284667600684254801630353088096980840340222862442855863"
),
MontFp!(
"23009100846224121436963731270583729980599923002973867306072660027295168025394"
),
MontFp!(
"28860636272668071557193448786384677753479273346368618958622860976935157887016"
),
MontFp!(
"4463852872232541738265687183045472986403778996068792264575135291104249406722"
),
],
[
MontFp!(
"8979606502867217781351947858153826073681057874607380315557491044827045184621"
),
MontFp!(
"3839354517358775617962892520281827551367585295130112918826401592054336406926"
),
MontFp!(
"8343148043471367933586208942539738049172643392238458806455194294812216204895"
),
MontFp!(
"19521609587404332101664179315451299357540048026126867904509375413756617469695"
),
],
];
for i in input.iter_mut() {
AnemoiVesta_4_3::sbox_layer(i);
}
for (&i, o) in input.iter().zip(output) {
assert_eq!(i, o);
}
}
}