1use super::{sbox, Felt, MontFp};
4use crate::{Anemoi, Jive, Sponge};
5use ark_ff::{One, Zero};
6mod digest;
8mod hasher;
10mod round_constants;
12
13pub use digest::AnemoiDigest;
14
15pub const STATE_WIDTH: usize = 4;
21pub const RATE_WIDTH: usize = 3;
23
24pub const NUM_COLUMNS: usize = 2;
26
27pub const DIGEST_SIZE: usize = 1;
29
30pub const NUM_HASH_ROUNDS: usize = 14;
32
33#[derive(Debug, Clone)]
38pub struct AnemoiVesta_4_3;
39
40impl<'a> Anemoi<'a, Felt> for AnemoiVesta_4_3 {
41 const NUM_COLUMNS: usize = NUM_COLUMNS;
42 const NUM_ROUNDS: usize = NUM_HASH_ROUNDS;
43
44 const WIDTH: usize = STATE_WIDTH;
45 const RATE: usize = RATE_WIDTH;
46 const OUTPUT_SIZE: usize = DIGEST_SIZE;
47
48 const ARK_C: &'a [Felt] = &round_constants::C;
49 const ARK_D: &'a [Felt] = &round_constants::D;
50
51 const GROUP_GENERATOR: u32 = sbox::BETA;
52
53 const ALPHA: u32 = sbox::ALPHA;
54 const INV_ALPHA: Felt = sbox::INV_ALPHA;
55 const BETA: u32 = sbox::BETA;
56 const DELTA: Felt = sbox::DELTA;
57
58 fn exp_by_inv_alpha(x: Felt) -> Felt {
59 sbox::exp_by_inv_alpha(&x)
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_sbox() {
69 let mut input = [
71 [Felt::zero(); 4],
72 [Felt::one(); 4],
73 [Felt::zero(), Felt::zero(), Felt::one(), Felt::one()],
74 [Felt::one(), Felt::one(), Felt::zero(), Felt::zero()],
75 [
76 MontFp!(
77 "17171575821044835452646983376891657746598420360665916302857913112615155188481"
78 ),
79 MontFp!(
80 "4878259343889800676637792865429595913732079354642033188788788548816160388735"
81 ),
82 MontFp!(
83 "14710586041044452280724909007581961178636649140337447602844509492879394113222"
84 ),
85 MontFp!(
86 "14763126680150486047850907515297623604390978801529782376208845118079999547174"
87 ),
88 ],
89 [
90 MontFp!(
91 "17621725050880138854641482650591645168660210996317222444321058926774415541946"
92 ),
93 MontFp!(
94 "13067325682471079882811673387226046556407138012917413608330391951960387495410"
95 ),
96 MontFp!(
97 "20911986584380119522392938022935582955713091835803437809976548779028892215661"
98 ),
99 MontFp!(
100 "17298480895319073476099634353198223959109770492655180223644829345139705168365"
101 ),
102 ],
103 [
104 MontFp!(
105 "13534062722920228579078071013506040783750843313080406768993540646788604385176"
106 ),
107 MontFp!(
108 "26851346411244739169665985676194362370977424369866209266327946801651837149058"
109 ),
110 MontFp!(
111 "12968329156644290669691681918059690306978208003866808993210570576582841655293"
112 ),
113 MontFp!(
114 "21184218576550897586080893660460594353277491003122420065397739788693455441109"
115 ),
116 ],
117 [
118 MontFp!(
119 "17504721576578377929854363754818129014302454236479094309892572904535169942869"
120 ),
121 MontFp!(
122 "17256871907841874512168520633397755541046680509612495348304533123172126069744"
123 ),
124 MontFp!(
125 "16573708108955804589285207554694926372644581797962983706855707412377533942212"
126 ),
127 MontFp!(
128 "1001195731002069601021768787609669443963929305292415139649356731428403204249"
129 ),
130 ],
131 [
132 MontFp!(
133 "21476588965425360576536796024756252860916517597530022982052267963267761980984"
134 ),
135 MontFp!(
136 "17365209058103552181676089103846560200758866117938205841358160405187644279990"
137 ),
138 MontFp!(
139 "16617787352584448859685152382705822107925311942425148627685165704166212993664"
140 ),
141 MontFp!(
142 "2919794818120166755501845600665380143239158883070227393012670214344361883435"
143 ),
144 ],
145 [
146 MontFp!(
147 "3663837741866278150801204926023987330338046375536699520520320692280869686326"
148 ),
149 MontFp!(
150 "5626342828308728729030948740359160208771225597340085483888793900808668920280"
151 ),
152 MontFp!(
153 "25341432683205836473097754503018431181083054988433449428007954708327253738217"
154 ),
155 MontFp!(
156 "15391436080588677843251606356820121755337819137001567922095591061616851369448"
157 ),
158 ],
159 ];
160
161 let output = [
162 [
163 MontFp!(
164 "11579208923731619542357098500868790785345222592776658951871897099357345179239"
165 ),
166 MontFp!(
167 "11579208923731619542357098500868790785345222592776658951871897099357345179239"
168 ),
169 Felt::zero(),
170 Felt::zero(),
171 ],
172 [
173 MontFp!(
174 "13565375592455225805458964934459476225912655788084948267498268443578124721632"
175 ),
176 MontFp!(
177 "13565375592455225805458964934459476225912655788084948267498268443578124721632"
178 ),
179 MontFp!(
180 "9688406656496048098325282220348971925838074278218514686842913989361614061362"
181 ),
182 MontFp!(
183 "9688406656496048098325282220348971925838074278218514686842913989361614061362"
184 ),
185 ],
186 [
187 MontFp!(
188 "2367797382831619836622158180640631392193461256316785256748737102603438284997"
189 ),
190 MontFp!(
191 "2367797382831619836622158180640631392193461256316785256748737102603438284997"
192 ),
193 MontFp!(
194 "22890698294176523999447614696141668677027690702028879487883356180097137464994"
195 ),
196 MontFp!(
197 "22890698294176523999447614696141668677027690702028879487883356180097137464994"
198 ),
199 ],
200 [
201 MontFp!(
202 "11579208923731619542357098500868790785345222592776658951871897099357345179245"
203 ),
204 MontFp!(
205 "11579208923731619542357098500868790785345222592776658951871897099357345179245"
206 ),
207 MontFp!(
208 "28948022309329048855892746252171976963363056481941647379679742748393362948096"
209 ),
210 MontFp!(
211 "28948022309329048855892746252171976963363056481941647379679742748393362948096"
212 ),
213 ],
214 [
215 MontFp!(
216 "10834673606358093173944279745976759059282896484598866610299737717080841298894"
217 ),
218 MontFp!(
219 "14751616569792947008809107589976394618335553401465142648266392823583311269481"
220 ),
221 MontFp!(
222 "28915835230101313873104310991681564688490043581744718728292376228642036830592"
223 ),
224 MontFp!(
225 "7282709690508471028387940016197311947640076145872685038693283675273937439736"
226 ),
227 ],
228 [
229 MontFp!(
230 "26000345689549895363283873872451186641162516373012354417251023714780009927003"
231 ),
232 MontFp!(
233 "13849124917766027264899160017673016264585759399986798614785827738974797194155"
234 ),
235 MontFp!(
236 "8955784606601724943377132411560566113265992763465987885117815782293937851495"
237 ),
238 MontFp!(
239 "6565333146518532840849043401826609024181130017038960798608855468883102381414"
240 ),
241 ],
242 [
243 MontFp!(
244 "21109420587697170836832911867087823108857795784397864682870252300989133756020"
245 ),
246 MontFp!(
247 "17188055203546690417044651390023546199594064434077150965740084623882793877514"
248 ),
249 MontFp!(
250 "20085797212322074806135678993748941530758528924846634705082758590430235069635"
251 ),
252 MontFp!(
253 "24268073510990283425579455729982488115856346090827060961647926830361310483848"
254 ),
255 ],
256 [
257 MontFp!(
258 "16824129626344096135954812067640680184165094020670516973289821648459956174106"
259 ),
260 MontFp!(
261 "17316199417585477116623334871792239358691009061600084787253680017279645782888"
262 ),
263 MontFp!(
264 "22375672866738589057574253392637204503002483931111484491573463969182722351809"
265 ),
266 MontFp!(
267 "28726833968838884390617957057713314393911952670281654565341057363619249338673"
268 ),
269 ],
270 [
271 MontFp!(
272 "11968530618465310232016284667600684254801630353088096980840340222862442855863"
273 ),
274 MontFp!(
275 "23009100846224121436963731270583729980599923002973867306072660027295168025394"
276 ),
277 MontFp!(
278 "28860636272668071557193448786384677753479273346368618958622860976935157887016"
279 ),
280 MontFp!(
281 "4463852872232541738265687183045472986403778996068792264575135291104249406722"
282 ),
283 ],
284 [
285 MontFp!(
286 "8979606502867217781351947858153826073681057874607380315557491044827045184621"
287 ),
288 MontFp!(
289 "3839354517358775617962892520281827551367585295130112918826401592054336406926"
290 ),
291 MontFp!(
292 "8343148043471367933586208942539738049172643392238458806455194294812216204895"
293 ),
294 MontFp!(
295 "19521609587404332101664179315451299357540048026126867904509375413756617469695"
296 ),
297 ],
298 ];
299
300 for i in input.iter_mut() {
301 AnemoiVesta_4_3::sbox_layer(i);
302 }
303
304 for (&i, o) in input.iter().zip(output) {
305 assert_eq!(i, o);
306 }
307 }
308}