anemoi/jubjub/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 = 14;
32
33#[derive(Debug, Clone)]
38pub struct AnemoiJubjub_4_3;
39
40impl<'a> Anemoi<'a, Felt> for AnemoiJubjub_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 "32482331693491338912746715212804309955055762795010043428638444021114192055700"
78 ),
79 MontFp!(
80 "33492235896239677379318998127111915626105094764445420316563603803650677798024"
81 ),
82 MontFp!(
83 "40852276710209360508792143474575139079377611682724718279538612654089409265622"
84 ),
85 MontFp!(
86 "17454758553032001173448113737176508049912904137600528382743215109473773360326"
87 ),
88 ],
89 [
90 MontFp!(
91 "31697690150500698069891377539641413643042395767418268110622836737358937273733"
92 ),
93 MontFp!(
94 "14936182001098588566889068859187704904046509134953535684803012051039021870434"
95 ),
96 MontFp!(
97 "32062323223159678058199358518264370918121206315536336340273716710093585703133"
98 ),
99 MontFp!(
100 "43578186782945849558350591695416792423021334793450758127359220722483217294020"
101 ),
102 ],
103 [
104 MontFp!(
105 "2796790445465504069863714602407416422364873557800358379683833414928340335973"
106 ),
107 MontFp!(
108 "50511725679821395285809210187672021215784469444066791282435722882320350392529"
109 ),
110 MontFp!(
111 "50112751287890876405347006035294541681882836253933320043432504777600143388328"
112 ),
113 MontFp!(
114 "41948963963773661486224262314467774385457060500842151247193284107159670392404"
115 ),
116 ],
117 [
118 MontFp!(
119 "28260061041875208478247269981369481951055158365877458064135425915086050180900"
120 ),
121 MontFp!(
122 "7520225685750815501541377676439117981829586983869671058576304486742543973903"
123 ),
124 MontFp!(
125 "8494952710499081348150272321526897482079052146658268355582624763000698357905"
126 ),
127 MontFp!(
128 "18772239904024279219312393340394095284703500765493091002652166849996241645214"
129 ),
130 ],
131 [
132 MontFp!(
133 "25465323965862504985542346374283770884484816724541277131322984567785823028157"
134 ),
135 MontFp!(
136 "50757513099879106518371328917154053295290464515758867435875604163645682862350"
137 ),
138 MontFp!(
139 "14539035946163836242004436655669921153164985614622459585532484049600703380973"
140 ),
141 MontFp!(
142 "39702178203045326512186708524595197587076032375200691801935943638307284457274"
143 ),
144 ],
145 [
146 MontFp!(
147 "22325702346208357281572047271348765192338134444085978084526703993427739008304"
148 ),
149 MontFp!(
150 "24578203192850644218962499856076936668656423409248399287800807169536587510513"
151 ),
152 MontFp!(
153 "9321790521148453575621974423755572637302841662049080540134236232094996035474"
154 ),
155 MontFp!(
156 "14510393621755087595232205218034236411877322034688824965880542086718055104181"
157 ),
158 ],
159 ];
160
161 let output = [
162 [
163 MontFp!(
164 "14981678621464625851270783002338847382197300714436467949315331057125308909861"
165 ),
166 MontFp!(
167 "14981678621464625851270783002338847382197300714436467949315331057125308909861"
168 ),
169 Felt::zero(),
170 Felt::zero(),
171 ],
172 [
173 MontFp!(
174 "26465412774926089111718321100574595527540964126946526979500696246159200663557"
175 ),
176 MontFp!(
177 "26465412774926089111718321100574595527540964126946526979500696246159200663557"
178 ),
179 MontFp!(
180 "39248768654128688292658764022179785046913739642751806076985032101719802651189"
181 ),
182 MontFp!(
183 "39248768654128688292658764022179785046913739642751806076985032101719802651189"
184 ),
185 ],
186 [
187 MontFp!(
188 "12740277426642017153170591585468114140384764416905683044706614677794597857620"
189 ),
190 MontFp!(
191 "12740277426642017153170591585468114140384764416905683044706614677794597857620"
192 ),
193 MontFp!(
194 "14891594025153715433052427327081456214862500696375893038292967289916437753110"
195 ),
196 MontFp!(
197 "14891594025153715433052427327081456214862500696375893038292967289916437753110"
198 ),
199 ],
200 [
201 MontFp!(
202 "14981678621464625851270783002338847382197300714436467949315331057125308909869"
203 ),
204 MontFp!(
205 "14981678621464625851270783002338847382197300714436467949315331057125308909869"
206 ),
207 MontFp!(
208 "52435875175126190479447740508185965837690552500527637822603658699938581184512"
209 ),
210 MontFp!(
211 "52435875175126190479447740508185965837690552500527637822603658699938581184512"
212 ),
213 ],
214 [
215 MontFp!(
216 "38749778788788807438157413537102975071476628708211104721274035250192240168079"
217 ),
218 MontFp!(
219 "19369486497309312061277881946237029141267272740526359302517213808446553098970"
220 ),
221 MontFp!(
222 "7940094733038062793529515395991096371773571922094772311764220189482319521850"
223 ),
224 MontFp!(
225 "26266119181754811201402200824861638328199794191715057380805332617547011668524"
226 ),
227 ],
228 [
229 MontFp!(
230 "20608074707185814339023032907318341048383060410959412048522855428266725599501"
231 ),
232 MontFp!(
233 "9178271014237970602770079696700157329530996359568103524699637399592478664026"
234 ),
235 MontFp!(
236 "47701107590146914868900666400919442563800477593292665707156993009143683237879"
237 ),
238 MontFp!(
239 "3510820734179449653960543969996663318747627903356941277690341076519268089320"
240 ),
241 ],
242 [
243 MontFp!(
244 "29348846719777431077739407126342807736758386871395967810152454975269135235218"
245 ),
246 MontFp!(
247 "21508842860285579109338877542083339527955542046411533438794905664670390294342"
248 ),
249 MontFp!(
250 "18680328723324263359036886083981681379132175831892967815891811931257462555218"
251 ),
252 MontFp!(
253 "50828231123138782878622888054010576359796238754328986008387427720372912792647"
254 ),
255 ],
256 [
257 MontFp!(
258 "28657794794998556716272629977514546250764013681125064867971574349218114625172"
259 ),
260 MontFp!(
261 "33079740383457282208302947956039568254422672391664354749193994044721067903799"
262 ),
263 MontFp!(
264 "37580317454617942481981990175878994567582554412855387702681533543699169440689"
265 ),
266 MontFp!(
267 "33018635415713911861411428294953314819462172257288917961589949901293277681705"
268 ),
269 ],
270 [
271 MontFp!(
272 "17524907224496794164960512560601728614079536896047942054509883695026269668154"
273 ),
274 MontFp!(
275 "46178517456006085277643641965935320508071532111249706454076466951452882061038"
276 ),
277 MontFp!(
278 "47488030983205427803034359403088928732610191936586392174026127541604111983497"
279 ),
280 MontFp!(
281 "12310986098205956955072933932049021648030702019638927472504623814447230877781"
282 ),
283 ],
284 [
285 MontFp!(
286 "34907433682181565642896658109600276718836563559731138130401593764879942750513"
287 ),
288 MontFp!(
289 "38440948138990743326152617869356648218121822747512371141022332627266826516600"
290 ),
291 MontFp!(
292 "20173089575902300256118122563311893974442028804411441716578684902893120439744"
293 ),
294 MontFp!(
295 "5355371110856184363013743931928911946383876366869179081262327334887335950591"
296 ),
297 ],
298 ];
299
300 for i in input.iter_mut() {
301 AnemoiJubjub_4_3::sbox_layer(i);
302 }
303
304 for (&i, o) in input.iter().zip(output) {
305 assert_eq!(i, o);
306 }
307 }
308}