anemoi/ed_on_bls12_377/anemoi_4_3/
mod.rs1use 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 = 13;
32
33#[derive(Debug, Clone)]
38pub struct AnemoiEdOnBls12_377_4_3;
39
40impl<'a> Anemoi<'a, Felt> for AnemoiEdOnBls12_377_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 "6940611250961405825545120029831205176738938552303008099611294173446214664691"
78 ),
79 MontFp!(
80 "5480101850489696149840075166530318206489985128150744820471435535091528839652"
81 ),
82 MontFp!(
83 "7201708049151036562000911944571756000547188117994933461815572531099111507008"
84 ),
85 MontFp!(
86 "2827974473455700078166226024266488132656186871950920903129036949398605833629"
87 ),
88 ],
89 [
90 MontFp!(
91 "3797298936296365643814910403003368678726980427948810943421657673572178221272"
92 ),
93 MontFp!(
94 "3828813336966645323320224908314624281093027915540569354320022538372988152473"
95 ),
96 MontFp!(
97 "1736474654150736285873001750930727146127814411691408428537206120670446282294"
98 ),
99 MontFp!(
100 "5128204574980809977822483630871447033147725725424331254019341452653455654924"
101 ),
102 ],
103 [
104 MontFp!(
105 "363367089441777931868044811987807633905545635069929092712399993719093576081"
106 ),
107 MontFp!(
108 "4499104641455590180541887405234538384893195314093643162939427056350664747151"
109 ),
110 MontFp!(
111 "322082831357193867657259588842970988302030045428218803173011288946367489601"
112 ),
113 MontFp!(
114 "2550486608303639259333928490889681998380932297525433923771649375659301661356"
115 ),
116 ],
117 [
118 MontFp!(
119 "569885108850314383039787650749237519609027256648980365651438143735816362452"
120 ),
121 MontFp!(
122 "2231761616448584541799204987982427589306080774164492939411651502918197836282"
123 ),
124 MontFp!(
125 "975958182683693184298678181982021390187979817693304378783961528549635345076"
126 ),
127 MontFp!(
128 "6800777224506517112003788618327461160471360483680685236270115242024102433772"
129 ),
130 ],
131 [
132 MontFp!(
133 "2178456317658974621524416648664796240015650299869313616773773046556512624500"
134 ),
135 MontFp!(
136 "6108764474179910781895022974008558967594975622651332911031649475673777444941"
137 ),
138 MontFp!(
139 "322789571245927139906087806656368609474704183617327852687875513826059978167"
140 ),
141 MontFp!(
142 "2036015014603942867052188337935912876869958747975216855231584534899562463341"
143 ),
144 ],
145 [
146 MontFp!(
147 "6888589121497847879114382779391578918240281139874908089359455035911570474458"
148 ),
149 MontFp!(
150 "4932041139906557449394989927615093637991458700273301564730524306069053433570"
151 ),
152 MontFp!(
153 "6707233285329233695459704472887655906779798762621322395753642225481709082973"
154 ),
155 MontFp!(
156 "4279400969981279096458604462286536561659734209815053084820881239939402418016"
157 ),
158 ],
159 ];
160
161 let output = [
162 [
163 MontFp!(
164 "1151517511285686876033930673470210890642168091157372340172986380352373987142"
165 ),
166 MontFp!(
167 "1151517511285686876033930673470210890642168091157372340172986380352373987142"
168 ),
169 Felt::zero(),
170 Felt::zero(),
171 ],
172 [
173 MontFp!(
174 "6365899358248349268142114350217140688230280935934585545650923395666961413055"
175 ),
176 MontFp!(
177 "6365899358248349268142114350217140688230280935934585545650923395666961413055"
178 ),
179 MontFp!(
180 "6687234439711495246728724424832755914754252582501095871411974444826560185425"
181 ),
182 MontFp!(
183 "6687234439711495246728724424832755914754252582501095871411974444826560185425"
184 ),
185 ],
186 [
187 MontFp!(
188 "1259102676294307221997675460062050531223883403969519571426325121918383273022"
189 ),
190 MontFp!(
191 "1259102676294307221997675460062050531223883403969519571426325121918383273022"
192 ),
193 MontFp!(
194 "7394748313577717922329439561482524665112163885958294194408694881596009888759"
195 ),
196 MontFp!(
197 "7394748313577717922329439561482524665112163885958294194408694881596009888759"
198 ),
199 ],
200 [
201 MontFp!(
202 "1151517511285686876033930673470210890642168091157372340172986380352373987165"
203 ),
204 MontFp!(
205 "1151517511285686876033930673470210890642168091157372340172986380352373987165"
206 ),
207 MontFp!(
208 "8444461749428370424248824938781546531375899335154063827935233455917409239040"
209 ),
210 MontFp!(
211 "8444461749428370424248824938781546531375899335154063827935233455917409239040"
212 ),
213 ],
214 [
215 MontFp!(
216 "7962439147697478800520582761847111012106735318125829846366291618908473686116"
217 ),
218 MontFp!(
219 "7058751001080730959547442434495302260582693544412828808219138906337451517161"
220 ),
221 MontFp!(
222 "7610759523417427095136375189077605713450842926189142665114958923389951390483"
223 ),
224 MontFp!(
225 "7370601767943888934127439971298429071576548952526549407838407200704701145515"
226 ),
227 ],
228 [
229 MontFp!(
230 "2927660095822284546401031412254364029035550069433219717273462954925109590672"
231 ),
232 MontFp!(
233 "6929673295900641592120861566798023414690473061652437589990009194949549428303"
234 ),
235 MontFp!(
236 "4959604256674896033311385996155529284422440264041445539258111854751191937263"
237 ),
238 MontFp!(
239 "644775785228329987611955612280721302113108438087791143571578304392216755758"
240 ),
241 ],
242 [
243 MontFp!(
244 "950631625887038367895927182524611804160977170511614282563728402345375887472"
245 ),
246 MontFp!(
247 "2761794990801377404145971147931082875758064182610942949242394014861101949123"
248 ),
249 MontFp!(
250 "8292379064179071091961530677648164322527913498403800659027433703574803746886"
251 ),
252 MontFp!(
253 "5349708320358365651991136572392417727487783610421709871664347540256647040707"
254 ),
255 ],
256 [
257 MontFp!(
258 "1969676591619887399313777813313029730106501074884812896398494003208794257303"
259 ),
260 MontFp!(
261 "7623993127594691993810168322669423564777544844991491103471558310861331177665"
262 ),
263 MontFp!(
264 "7865489468706356141413765929518262062562091873670617664420962727992171677397"
265 ),
266 MontFp!(
267 "1047255922660906029293756125324473874091747869075898395946061648959722451391"
268 ),
269 ],
270 [
271 MontFp!(
272 "7028600421814477627558300765007849180036842437989558086681357484107076343216"
273 ),
274 MontFp!(
275 "2100349465037004852214713977415406790590064557129937251556358608846711292012"
276 ),
277 MontFp!(
278 "7794677823110842833881725728765381400261512740202187384149964282047633316580"
279 ),
280 MontFp!(
281 "1277567984187090426540102474916764011511418249317300200728389135555258671114"
282 ),
283 ],
284 [
285 MontFp!(
286 "5114352268268160726646255196019903626981936965659310958570594586662576745581"
287 ),
288 MontFp!(
289 "774860654520724039647175689904190465106549292473554403022581208001425309882"
290 ),
291 MontFp!(
292 "4521297766675132714960096996876587301299300215269750173311992361871990712733"
293 ),
294 MontFp!(
295 "880067337913507515189560951296717643033128059481477252400992450470381181296"
296 ),
297 ],
298 ];
299
300 for i in input.iter_mut() {
301 AnemoiEdOnBls12_377_4_3::sbox_layer(i);
302 }
303
304 for (&i, o) in input.iter().zip(output) {
305 assert_eq!(i, o);
306 }
307 }
308}