Best JavaScript code snippet using wpt
keccak256.js
Source:keccak256.js
1// https://github.com/denoland/deno_std/blob/main/hash/_sha3/keccakf.ts2const KECCAK_ROUNDS = 24;3const KECCAK_RC = [4 0x1,5 0x0,6 0x8082,7 0x0,8 0x808a,9 0x80000000,10 0x80008000,11 0x80000000,12 0x808b,13 0x0,14 0x80000001,15 0x0,16 0x80008081,17 0x80000000,18 0x8009,19 0x80000000,20 0x8a,21 0x0,22 0x88,23 0x0,24 0x80008009,25 0x0,26 0x8000000a,27 0x0,28 0x8000808b,29 0x0,30 0x8b,31 0x80000000,32 0x8089,33 0x80000000,34 0x8003,35 0x80000000,36 0x8002,37 0x80000000,38 0x80,39 0x80000000,40 0x800a,41 0x0,42 0x8000000a,43 0x80000000,44 0x80008081,45 0x80000000,46 0x8080,47 0x80000000,48 0x80000001,49 0x0,50 0x80008008,51 0x80000000,52];53function keccakf(state) {54 const s = new Uint32Array(state.buffer);55 let bc0 = 0;56 let bc1 = 0;57 let bc2 = 0;58 let bc3 = 0;59 let bc4 = 0;60 let bc5 = 0;61 let bc6 = 0;62 let bc7 = 0;63 let bc8 = 0;64 let bc9 = 0;65 let d0 = 0;66 let d1 = 0;67 let d2 = 0;68 let d3 = 0;69 let d4 = 0;70 let d5 = 0;71 let d6 = 0;72 let d7 = 0;73 let d8 = 0;74 let d9 = 0;75 let t0 = 0;76 let t1 = 0;77 for (let n = 0; n < KECCAK_ROUNDS * 2; n += 8) {78 // Round 179 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];80 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];81 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];82 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];83 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];84 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];85 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];86 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];87 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];88 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];89 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));90 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));91 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));92 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));93 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));94 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));95 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));96 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));97 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));98 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));99 bc0 = s[0] ^ d0;100 bc1 = s[1] ^ d1;101 t0 = s[12] ^ d2;102 t1 = s[13] ^ d3;103 bc2 = (t1 << 12) | (t0 >>> 20);104 bc3 = (t0 << 12) | (t1 >>> 20);105 t0 = s[24] ^ d4;106 t1 = s[25] ^ d5;107 bc4 = (t1 << 11) | (t0 >>> 21);108 bc5 = (t0 << 11) | (t1 >>> 21);109 t0 = s[36] ^ d6;110 t1 = s[37] ^ d7;111 bc6 = (t0 << 21) | (t1 >>> 11);112 bc7 = (t1 << 21) | (t0 >>> 11);113 t0 = s[48] ^ d8;114 t1 = s[49] ^ d9;115 bc8 = (t0 << 14) | (t1 >>> 18);116 bc9 = (t1 << 14) | (t0 >>> 18);117 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n];118 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 1];119 s[12] = bc2 ^ (bc6 & ~bc4);120 s[13] = bc3 ^ (bc7 & ~bc5);121 s[24] = bc4 ^ (bc8 & ~bc6);122 s[25] = bc5 ^ (bc9 & ~bc7);123 s[36] = bc6 ^ (bc0 & ~bc8);124 s[37] = bc7 ^ (bc1 & ~bc9);125 s[48] = bc8 ^ (bc2 & ~bc0);126 s[49] = bc9 ^ (bc3 & ~bc1);127 t0 = s[20] ^ d0;128 t1 = s[21] ^ d1;129 bc4 = (t0 << 3) | (t1 >>> 29);130 bc5 = (t1 << 3) | (t0 >>> 29);131 t0 = s[32] ^ d2;132 t1 = s[33] ^ d3;133 bc6 = (t1 << 13) | (t0 >>> 19);134 bc7 = (t0 << 13) | (t1 >>> 19);135 t0 = s[44] ^ d4;136 t1 = s[45] ^ d5;137 bc8 = (t1 << 29) | (t0 >>> 3);138 bc9 = (t0 << 29) | (t1 >>> 3);139 t0 = s[6] ^ d6;140 t1 = s[7] ^ d7;141 bc0 = (t0 << 28) | (t1 >>> 4);142 bc1 = (t1 << 28) | (t0 >>> 4);143 t0 = s[18] ^ d8;144 t1 = s[19] ^ d9;145 bc2 = (t0 << 20) | (t1 >>> 12);146 bc3 = (t1 << 20) | (t0 >>> 12);147 s[20] = bc0 ^ (bc4 & ~bc2);148 s[21] = bc1 ^ (bc5 & ~bc3);149 s[32] = bc2 ^ (bc6 & ~bc4);150 s[33] = bc3 ^ (bc7 & ~bc5);151 s[44] = bc4 ^ (bc8 & ~bc6);152 s[45] = bc5 ^ (bc9 & ~bc7);153 s[6] = bc6 ^ (bc0 & ~bc8);154 s[7] = bc7 ^ (bc1 & ~bc9);155 s[18] = bc8 ^ (bc2 & ~bc0);156 s[19] = bc9 ^ (bc3 & ~bc1);157 t0 = s[40] ^ d0;158 t1 = s[41] ^ d1;159 bc8 = (t0 << 18) | (t1 >>> 14);160 bc9 = (t1 << 18) | (t0 >>> 14);161 t0 = s[2] ^ d2;162 t1 = s[3] ^ d3;163 bc0 = (t0 << 1) | (t1 >>> 31);164 bc1 = (t1 << 1) | (t0 >>> 31);165 t0 = s[14] ^ d4;166 t1 = s[15] ^ d5;167 bc2 = (t0 << 6) | (t1 >>> 26);168 bc3 = (t1 << 6) | (t0 >>> 26);169 t0 = s[26] ^ d6;170 t1 = s[27] ^ d7;171 bc4 = (t0 << 25) | (t1 >>> 7);172 bc5 = (t1 << 25) | (t0 >>> 7);173 t0 = s[38] ^ d8;174 t1 = s[39] ^ d9;175 bc6 = (t0 << 8) | (t1 >>> 24);176 bc7 = (t1 << 8) | (t0 >>> 24);177 s[40] = bc0 ^ (bc4 & ~bc2);178 s[41] = bc1 ^ (bc5 & ~bc3);179 s[2] = bc2 ^ (bc6 & ~bc4);180 s[3] = bc3 ^ (bc7 & ~bc5);181 s[14] = bc4 ^ (bc8 & ~bc6);182 s[15] = bc5 ^ (bc9 & ~bc7);183 s[26] = bc6 ^ (bc0 & ~bc8);184 s[27] = bc7 ^ (bc1 & ~bc9);185 s[38] = bc8 ^ (bc2 & ~bc0);186 s[39] = bc9 ^ (bc3 & ~bc1);187 t0 = s[10] ^ d0;188 t1 = s[11] ^ d1;189 bc2 = (t1 << 4) | (t0 >>> 28);190 bc3 = (t0 << 4) | (t1 >>> 28);191 t0 = s[22] ^ d2;192 t1 = s[23] ^ d3;193 bc4 = (t0 << 10) | (t1 >>> 22);194 bc5 = (t1 << 10) | (t0 >>> 22);195 t0 = s[34] ^ d4;196 t1 = s[35] ^ d5;197 bc6 = (t0 << 15) | (t1 >>> 17);198 bc7 = (t1 << 15) | (t0 >>> 17);199 t0 = s[46] ^ d6;200 t1 = s[47] ^ d7;201 bc8 = (t1 << 24) | (t0 >>> 8);202 bc9 = (t0 << 24) | (t1 >>> 8);203 t0 = s[8] ^ d8;204 t1 = s[9] ^ d9;205 bc0 = (t0 << 27) | (t1 >>> 5);206 bc1 = (t1 << 27) | (t0 >>> 5);207 s[10] = bc0 ^ (bc4 & ~bc2);208 s[11] = bc1 ^ (bc5 & ~bc3);209 s[22] = bc2 ^ (bc6 & ~bc4);210 s[23] = bc3 ^ (bc7 & ~bc5);211 s[34] = bc4 ^ (bc8 & ~bc6);212 s[35] = bc5 ^ (bc9 & ~bc7);213 s[46] = bc6 ^ (bc0 & ~bc8);214 s[47] = bc7 ^ (bc1 & ~bc9);215 s[8] = bc8 ^ (bc2 & ~bc0);216 s[9] = bc9 ^ (bc3 & ~bc1);217 t0 = s[30] ^ d0;218 t1 = s[31] ^ d1;219 bc6 = (t1 << 9) | (t0 >>> 23);220 bc7 = (t0 << 9) | (t1 >>> 23);221 t0 = s[42] ^ d2;222 t1 = s[43] ^ d3;223 bc8 = (t0 << 2) | (t1 >>> 30);224 bc9 = (t1 << 2) | (t0 >>> 30);225 t0 = s[4] ^ d4;226 t1 = s[5] ^ d5;227 bc0 = (t1 << 30) | (t0 >>> 2);228 bc1 = (t0 << 30) | (t1 >>> 2);229 t0 = s[16] ^ d6;230 t1 = s[17] ^ d7;231 bc2 = (t1 << 23) | (t0 >>> 9);232 bc3 = (t0 << 23) | (t1 >>> 9);233 t0 = s[28] ^ d8;234 t1 = s[29] ^ d9;235 bc4 = (t1 << 7) | (t0 >>> 25);236 bc5 = (t0 << 7) | (t1 >>> 25);237 s[30] = bc0 ^ (bc4 & ~bc2);238 s[31] = bc1 ^ (bc5 & ~bc3);239 s[42] = bc2 ^ (bc6 & ~bc4);240 s[43] = bc3 ^ (bc7 & ~bc5);241 s[4] = bc4 ^ (bc8 & ~bc6);242 s[5] = bc5 ^ (bc9 & ~bc7);243 s[16] = bc6 ^ (bc0 & ~bc8);244 s[17] = bc7 ^ (bc1 & ~bc9);245 s[28] = bc8 ^ (bc2 & ~bc0);246 s[29] = bc9 ^ (bc3 & ~bc1);247 // Round 2248 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];249 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];250 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];251 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];252 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];253 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];254 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];255 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];256 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];257 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];258 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));259 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));260 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));261 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));262 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));263 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));264 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));265 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));266 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));267 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));268 bc0 = s[0] ^ d0;269 bc1 = s[1] ^ d1;270 t0 = s[32] ^ d2;271 t1 = s[33] ^ d3;272 bc2 = (t1 << 12) | (t0 >>> 20);273 bc3 = (t0 << 12) | (t1 >>> 20);274 t0 = s[14] ^ d4;275 t1 = s[15] ^ d5;276 bc4 = (t1 << 11) | (t0 >>> 21);277 bc5 = (t0 << 11) | (t1 >>> 21);278 t0 = s[46] ^ d6;279 t1 = s[47] ^ d7;280 bc6 = (t0 << 21) | (t1 >>> 11);281 bc7 = (t1 << 21) | (t0 >>> 11);282 t0 = s[28] ^ d8;283 t1 = s[29] ^ d9;284 bc8 = (t0 << 14) | (t1 >>> 18);285 bc9 = (t1 << 14) | (t0 >>> 18);286 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 2];287 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 3];288 s[32] = bc2 ^ (bc6 & ~bc4);289 s[33] = bc3 ^ (bc7 & ~bc5);290 s[14] = bc4 ^ (bc8 & ~bc6);291 s[15] = bc5 ^ (bc9 & ~bc7);292 s[46] = bc6 ^ (bc0 & ~bc8);293 s[47] = bc7 ^ (bc1 & ~bc9);294 s[28] = bc8 ^ (bc2 & ~bc0);295 s[29] = bc9 ^ (bc3 & ~bc1);296 t0 = s[40] ^ d0;297 t1 = s[41] ^ d1;298 bc4 = (t0 << 3) | (t1 >>> 29);299 bc5 = (t1 << 3) | (t0 >>> 29);300 t0 = s[22] ^ d2;301 t1 = s[23] ^ d3;302 bc6 = (t1 << 13) | (t0 >>> 19);303 bc7 = (t0 << 13) | (t1 >>> 19);304 t0 = s[4] ^ d4;305 t1 = s[5] ^ d5;306 bc8 = (t1 << 29) | (t0 >>> 3);307 bc9 = (t0 << 29) | (t1 >>> 3);308 t0 = s[36] ^ d6;309 t1 = s[37] ^ d7;310 bc0 = (t0 << 28) | (t1 >>> 4);311 bc1 = (t1 << 28) | (t0 >>> 4);312 t0 = s[18] ^ d8;313 t1 = s[19] ^ d9;314 bc2 = (t0 << 20) | (t1 >>> 12);315 bc3 = (t1 << 20) | (t0 >>> 12);316 s[40] = bc0 ^ (bc4 & ~bc2);317 s[41] = bc1 ^ (bc5 & ~bc3);318 s[22] = bc2 ^ (bc6 & ~bc4);319 s[23] = bc3 ^ (bc7 & ~bc5);320 s[4] = bc4 ^ (bc8 & ~bc6);321 s[5] = bc5 ^ (bc9 & ~bc7);322 s[36] = bc6 ^ (bc0 & ~bc8);323 s[37] = bc7 ^ (bc1 & ~bc9);324 s[18] = bc8 ^ (bc2 & ~bc0);325 s[19] = bc9 ^ (bc3 & ~bc1);326 t0 = s[30] ^ d0;327 t1 = s[31] ^ d1;328 bc8 = (t0 << 18) | (t1 >>> 14);329 bc9 = (t1 << 18) | (t0 >>> 14);330 t0 = s[12] ^ d2;331 t1 = s[13] ^ d3;332 bc0 = (t0 << 1) | (t1 >>> 31);333 bc1 = (t1 << 1) | (t0 >>> 31);334 t0 = s[44] ^ d4;335 t1 = s[45] ^ d5;336 bc2 = (t0 << 6) | (t1 >>> 26);337 bc3 = (t1 << 6) | (t0 >>> 26);338 t0 = s[26] ^ d6;339 t1 = s[27] ^ d7;340 bc4 = (t0 << 25) | (t1 >>> 7);341 bc5 = (t1 << 25) | (t0 >>> 7);342 t0 = s[8] ^ d8;343 t1 = s[9] ^ d9;344 bc6 = (t0 << 8) | (t1 >>> 24);345 bc7 = (t1 << 8) | (t0 >>> 24);346 s[30] = bc0 ^ (bc4 & ~bc2);347 s[31] = bc1 ^ (bc5 & ~bc3);348 s[12] = bc2 ^ (bc6 & ~bc4);349 s[13] = bc3 ^ (bc7 & ~bc5);350 s[44] = bc4 ^ (bc8 & ~bc6);351 s[45] = bc5 ^ (bc9 & ~bc7);352 s[26] = bc6 ^ (bc0 & ~bc8);353 s[27] = bc7 ^ (bc1 & ~bc9);354 s[8] = bc8 ^ (bc2 & ~bc0);355 s[9] = bc9 ^ (bc3 & ~bc1);356 t0 = s[20] ^ d0;357 t1 = s[21] ^ d1;358 bc2 = (t1 << 4) | (t0 >>> 28);359 bc3 = (t0 << 4) | (t1 >>> 28);360 t0 = s[2] ^ d2;361 t1 = s[3] ^ d3;362 bc4 = (t0 << 10) | (t1 >>> 22);363 bc5 = (t1 << 10) | (t0 >>> 22);364 t0 = s[34] ^ d4;365 t1 = s[35] ^ d5;366 bc6 = (t0 << 15) | (t1 >>> 17);367 bc7 = (t1 << 15) | (t0 >>> 17);368 t0 = s[16] ^ d6;369 t1 = s[17] ^ d7;370 bc8 = (t1 << 24) | (t0 >>> 8);371 bc9 = (t0 << 24) | (t1 >>> 8);372 t0 = s[48] ^ d8;373 t1 = s[49] ^ d9;374 bc0 = (t0 << 27) | (t1 >>> 5);375 bc1 = (t1 << 27) | (t0 >>> 5);376 s[20] = bc0 ^ (bc4 & ~bc2);377 s[21] = bc1 ^ (bc5 & ~bc3);378 s[2] = bc2 ^ (bc6 & ~bc4);379 s[3] = bc3 ^ (bc7 & ~bc5);380 s[34] = bc4 ^ (bc8 & ~bc6);381 s[35] = bc5 ^ (bc9 & ~bc7);382 s[16] = bc6 ^ (bc0 & ~bc8);383 s[17] = bc7 ^ (bc1 & ~bc9);384 s[48] = bc8 ^ (bc2 & ~bc0);385 s[49] = bc9 ^ (bc3 & ~bc1);386 t0 = s[10] ^ d0;387 t1 = s[11] ^ d1;388 bc6 = (t1 << 9) | (t0 >>> 23);389 bc7 = (t0 << 9) | (t1 >>> 23);390 t0 = s[42] ^ d2;391 t1 = s[43] ^ d3;392 bc8 = (t0 << 2) | (t1 >>> 30);393 bc9 = (t1 << 2) | (t0 >>> 30);394 t0 = s[24] ^ d4;395 t1 = s[25] ^ d5;396 bc0 = (t1 << 30) | (t0 >>> 2);397 bc1 = (t0 << 30) | (t1 >>> 2);398 t0 = s[6] ^ d6;399 t1 = s[7] ^ d7;400 bc2 = (t1 << 23) | (t0 >>> 9);401 bc3 = (t0 << 23) | (t1 >>> 9);402 t0 = s[38] ^ d8;403 t1 = s[39] ^ d9;404 bc4 = (t1 << 7) | (t0 >>> 25);405 bc5 = (t0 << 7) | (t1 >>> 25);406 s[10] = bc0 ^ (bc4 & ~bc2);407 s[11] = bc1 ^ (bc5 & ~bc3);408 s[42] = bc2 ^ (bc6 & ~bc4);409 s[43] = bc3 ^ (bc7 & ~bc5);410 s[24] = bc4 ^ (bc8 & ~bc6);411 s[25] = bc5 ^ (bc9 & ~bc7);412 s[6] = bc6 ^ (bc0 & ~bc8);413 s[7] = bc7 ^ (bc1 & ~bc9);414 s[38] = bc8 ^ (bc2 & ~bc0);415 s[39] = bc9 ^ (bc3 & ~bc1);416 // Round 3417 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];418 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];419 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];420 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];421 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];422 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];423 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];424 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];425 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];426 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];427 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));428 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));429 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));430 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));431 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));432 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));433 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));434 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));435 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));436 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));437 bc0 = s[0] ^ d0;438 bc1 = s[1] ^ d1;439 t0 = s[22] ^ d2;440 t1 = s[23] ^ d3;441 bc2 = (t1 << 12) | (t0 >>> 20);442 bc3 = (t0 << 12) | (t1 >>> 20);443 t0 = s[44] ^ d4;444 t1 = s[45] ^ d5;445 bc4 = (t1 << 11) | (t0 >>> 21);446 bc5 = (t0 << 11) | (t1 >>> 21);447 t0 = s[16] ^ d6;448 t1 = s[17] ^ d7;449 bc6 = (t0 << 21) | (t1 >>> 11);450 bc7 = (t1 << 21) | (t0 >>> 11);451 t0 = s[38] ^ d8;452 t1 = s[39] ^ d9;453 bc8 = (t0 << 14) | (t1 >>> 18);454 bc9 = (t1 << 14) | (t0 >>> 18);455 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 4];456 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 5];457 s[22] = bc2 ^ (bc6 & ~bc4);458 s[23] = bc3 ^ (bc7 & ~bc5);459 s[44] = bc4 ^ (bc8 & ~bc6);460 s[45] = bc5 ^ (bc9 & ~bc7);461 s[16] = bc6 ^ (bc0 & ~bc8);462 s[17] = bc7 ^ (bc1 & ~bc9);463 s[38] = bc8 ^ (bc2 & ~bc0);464 s[39] = bc9 ^ (bc3 & ~bc1);465 t0 = s[30] ^ d0;466 t1 = s[31] ^ d1;467 bc4 = (t0 << 3) | (t1 >>> 29);468 bc5 = (t1 << 3) | (t0 >>> 29);469 t0 = s[2] ^ d2;470 t1 = s[3] ^ d3;471 bc6 = (t1 << 13) | (t0 >>> 19);472 bc7 = (t0 << 13) | (t1 >>> 19);473 t0 = s[24] ^ d4;474 t1 = s[25] ^ d5;475 bc8 = (t1 << 29) | (t0 >>> 3);476 bc9 = (t0 << 29) | (t1 >>> 3);477 t0 = s[46] ^ d6;478 t1 = s[47] ^ d7;479 bc0 = (t0 << 28) | (t1 >>> 4);480 bc1 = (t1 << 28) | (t0 >>> 4);481 t0 = s[18] ^ d8;482 t1 = s[19] ^ d9;483 bc2 = (t0 << 20) | (t1 >>> 12);484 bc3 = (t1 << 20) | (t0 >>> 12);485 s[30] = bc0 ^ (bc4 & ~bc2);486 s[31] = bc1 ^ (bc5 & ~bc3);487 s[2] = bc2 ^ (bc6 & ~bc4);488 s[3] = bc3 ^ (bc7 & ~bc5);489 s[24] = bc4 ^ (bc8 & ~bc6);490 s[25] = bc5 ^ (bc9 & ~bc7);491 s[46] = bc6 ^ (bc0 & ~bc8);492 s[47] = bc7 ^ (bc1 & ~bc9);493 s[18] = bc8 ^ (bc2 & ~bc0);494 s[19] = bc9 ^ (bc3 & ~bc1);495 t0 = s[10] ^ d0;496 t1 = s[11] ^ d1;497 bc8 = (t0 << 18) | (t1 >>> 14);498 bc9 = (t1 << 18) | (t0 >>> 14);499 t0 = s[32] ^ d2;500 t1 = s[33] ^ d3;501 bc0 = (t0 << 1) | (t1 >>> 31);502 bc1 = (t1 << 1) | (t0 >>> 31);503 t0 = s[4] ^ d4;504 t1 = s[5] ^ d5;505 bc2 = (t0 << 6) | (t1 >>> 26);506 bc3 = (t1 << 6) | (t0 >>> 26);507 t0 = s[26] ^ d6;508 t1 = s[27] ^ d7;509 bc4 = (t0 << 25) | (t1 >>> 7);510 bc5 = (t1 << 25) | (t0 >>> 7);511 t0 = s[48] ^ d8;512 t1 = s[49] ^ d9;513 bc6 = (t0 << 8) | (t1 >>> 24);514 bc7 = (t1 << 8) | (t0 >>> 24);515 s[10] = bc0 ^ (bc4 & ~bc2);516 s[11] = bc1 ^ (bc5 & ~bc3);517 s[32] = bc2 ^ (bc6 & ~bc4);518 s[33] = bc3 ^ (bc7 & ~bc5);519 s[4] = bc4 ^ (bc8 & ~bc6);520 s[5] = bc5 ^ (bc9 & ~bc7);521 s[26] = bc6 ^ (bc0 & ~bc8);522 s[27] = bc7 ^ (bc1 & ~bc9);523 s[48] = bc8 ^ (bc2 & ~bc0);524 s[49] = bc9 ^ (bc3 & ~bc1);525 t0 = s[40] ^ d0;526 t1 = s[41] ^ d1;527 bc2 = (t1 << 4) | (t0 >>> 28);528 bc3 = (t0 << 4) | (t1 >>> 28);529 t0 = s[12] ^ d2;530 t1 = s[13] ^ d3;531 bc4 = (t0 << 10) | (t1 >>> 22);532 bc5 = (t1 << 10) | (t0 >>> 22);533 t0 = s[34] ^ d4;534 t1 = s[35] ^ d5;535 bc6 = (t0 << 15) | (t1 >>> 17);536 bc7 = (t1 << 15) | (t0 >>> 17);537 t0 = s[6] ^ d6;538 t1 = s[7] ^ d7;539 bc8 = (t1 << 24) | (t0 >>> 8);540 bc9 = (t0 << 24) | (t1 >>> 8);541 t0 = s[28] ^ d8;542 t1 = s[29] ^ d9;543 bc0 = (t0 << 27) | (t1 >>> 5);544 bc1 = (t1 << 27) | (t0 >>> 5);545 s[40] = bc0 ^ (bc4 & ~bc2);546 s[41] = bc1 ^ (bc5 & ~bc3);547 s[12] = bc2 ^ (bc6 & ~bc4);548 s[13] = bc3 ^ (bc7 & ~bc5);549 s[34] = bc4 ^ (bc8 & ~bc6);550 s[35] = bc5 ^ (bc9 & ~bc7);551 s[6] = bc6 ^ (bc0 & ~bc8);552 s[7] = bc7 ^ (bc1 & ~bc9);553 s[28] = bc8 ^ (bc2 & ~bc0);554 s[29] = bc9 ^ (bc3 & ~bc1);555 t0 = s[20] ^ d0;556 t1 = s[21] ^ d1;557 bc6 = (t1 << 9) | (t0 >>> 23);558 bc7 = (t0 << 9) | (t1 >>> 23);559 t0 = s[42] ^ d2;560 t1 = s[43] ^ d3;561 bc8 = (t0 << 2) | (t1 >>> 30);562 bc9 = (t1 << 2) | (t0 >>> 30);563 t0 = s[14] ^ d4;564 t1 = s[15] ^ d5;565 bc0 = (t1 << 30) | (t0 >>> 2);566 bc1 = (t0 << 30) | (t1 >>> 2);567 t0 = s[36] ^ d6;568 t1 = s[37] ^ d7;569 bc2 = (t1 << 23) | (t0 >>> 9);570 bc3 = (t0 << 23) | (t1 >>> 9);571 t0 = s[8] ^ d8;572 t1 = s[9] ^ d9;573 bc4 = (t1 << 7) | (t0 >>> 25);574 bc5 = (t0 << 7) | (t1 >>> 25);575 s[20] = bc0 ^ (bc4 & ~bc2);576 s[21] = bc1 ^ (bc5 & ~bc3);577 s[42] = bc2 ^ (bc6 & ~bc4);578 s[43] = bc3 ^ (bc7 & ~bc5);579 s[14] = bc4 ^ (bc8 & ~bc6);580 s[15] = bc5 ^ (bc9 & ~bc7);581 s[36] = bc6 ^ (bc0 & ~bc8);582 s[37] = bc7 ^ (bc1 & ~bc9);583 s[8] = bc8 ^ (bc2 & ~bc0);584 s[9] = bc9 ^ (bc3 & ~bc1);585 // Round 4586 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];587 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];588 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];589 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];590 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];591 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];592 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];593 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];594 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];595 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];596 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));597 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));598 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));599 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));600 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));601 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));602 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));603 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));604 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));605 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));606 bc0 = s[0] ^ d0;607 bc1 = s[1] ^ d1;608 t0 = s[2] ^ d2;609 t1 = s[3] ^ d3;610 bc2 = (t1 << 12) | (t0 >>> 20);611 bc3 = (t0 << 12) | (t1 >>> 20);612 t0 = s[4] ^ d4;613 t1 = s[5] ^ d5;614 bc4 = (t1 << 11) | (t0 >>> 21);615 bc5 = (t0 << 11) | (t1 >>> 21);616 t0 = s[6] ^ d6;617 t1 = s[7] ^ d7;618 bc6 = (t0 << 21) | (t1 >>> 11);619 bc7 = (t1 << 21) | (t0 >>> 11);620 t0 = s[8] ^ d8;621 t1 = s[9] ^ d9;622 bc8 = (t0 << 14) | (t1 >>> 18);623 bc9 = (t1 << 14) | (t0 >>> 18);624 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 6];625 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 7];626 s[2] = bc2 ^ (bc6 & ~bc4);627 s[3] = bc3 ^ (bc7 & ~bc5);628 s[4] = bc4 ^ (bc8 & ~bc6);629 s[5] = bc5 ^ (bc9 & ~bc7);630 s[6] = bc6 ^ (bc0 & ~bc8);631 s[7] = bc7 ^ (bc1 & ~bc9);632 s[8] = bc8 ^ (bc2 & ~bc0);633 s[9] = bc9 ^ (bc3 & ~bc1);634 t0 = s[10] ^ d0;635 t1 = s[11] ^ d1;636 bc4 = (t0 << 3) | (t1 >>> 29);637 bc5 = (t1 << 3) | (t0 >>> 29);638 t0 = s[12] ^ d2;639 t1 = s[13] ^ d3;640 bc6 = (t1 << 13) | (t0 >>> 19);641 bc7 = (t0 << 13) | (t1 >>> 19);642 t0 = s[14] ^ d4;643 t1 = s[15] ^ d5;644 bc8 = (t1 << 29) | (t0 >>> 3);645 bc9 = (t0 << 29) | (t1 >>> 3);646 t0 = s[16] ^ d6;647 t1 = s[17] ^ d7;648 bc0 = (t0 << 28) | (t1 >>> 4);649 bc1 = (t1 << 28) | (t0 >>> 4);650 t0 = s[18] ^ d8;651 t1 = s[19] ^ d9;652 bc2 = (t0 << 20) | (t1 >>> 12);653 bc3 = (t1 << 20) | (t0 >>> 12);654 s[10] = bc0 ^ (bc4 & ~bc2);655 s[11] = bc1 ^ (bc5 & ~bc3);656 s[12] = bc2 ^ (bc6 & ~bc4);657 s[13] = bc3 ^ (bc7 & ~bc5);658 s[14] = bc4 ^ (bc8 & ~bc6);659 s[15] = bc5 ^ (bc9 & ~bc7);660 s[16] = bc6 ^ (bc0 & ~bc8);661 s[17] = bc7 ^ (bc1 & ~bc9);662 s[18] = bc8 ^ (bc2 & ~bc0);663 s[19] = bc9 ^ (bc3 & ~bc1);664 t0 = s[20] ^ d0;665 t1 = s[21] ^ d1;666 bc8 = (t0 << 18) | (t1 >>> 14);667 bc9 = (t1 << 18) | (t0 >>> 14);668 t0 = s[22] ^ d2;669 t1 = s[23] ^ d3;670 bc0 = (t0 << 1) | (t1 >>> 31);671 bc1 = (t1 << 1) | (t0 >>> 31);672 t0 = s[24] ^ d4;673 t1 = s[25] ^ d5;674 bc2 = (t0 << 6) | (t1 >>> 26);675 bc3 = (t1 << 6) | (t0 >>> 26);676 t0 = s[26] ^ d6;677 t1 = s[27] ^ d7;678 bc4 = (t0 << 25) | (t1 >>> 7);679 bc5 = (t1 << 25) | (t0 >>> 7);680 t0 = s[28] ^ d8;681 t1 = s[29] ^ d9;682 bc6 = (t0 << 8) | (t1 >>> 24);683 bc7 = (t1 << 8) | (t0 >>> 24);684 s[20] = bc0 ^ (bc4 & ~bc2);685 s[21] = bc1 ^ (bc5 & ~bc3);686 s[22] = bc2 ^ (bc6 & ~bc4);687 s[23] = bc3 ^ (bc7 & ~bc5);688 s[24] = bc4 ^ (bc8 & ~bc6);689 s[25] = bc5 ^ (bc9 & ~bc7);690 s[26] = bc6 ^ (bc0 & ~bc8);691 s[27] = bc7 ^ (bc1 & ~bc9);692 s[28] = bc8 ^ (bc2 & ~bc0);693 s[29] = bc9 ^ (bc3 & ~bc1);694 t0 = s[30] ^ d0;695 t1 = s[31] ^ d1;696 bc2 = (t1 << 4) | (t0 >>> 28);697 bc3 = (t0 << 4) | (t1 >>> 28);698 t0 = s[32] ^ d2;699 t1 = s[33] ^ d3;700 bc4 = (t0 << 10) | (t1 >>> 22);701 bc5 = (t1 << 10) | (t0 >>> 22);702 t0 = s[34] ^ d4;703 t1 = s[35] ^ d5;704 bc6 = (t0 << 15) | (t1 >>> 17);705 bc7 = (t1 << 15) | (t0 >>> 17);706 t0 = s[36] ^ d6;707 t1 = s[37] ^ d7;708 bc8 = (t1 << 24) | (t0 >>> 8);709 bc9 = (t0 << 24) | (t1 >>> 8);710 t0 = s[38] ^ d8;711 t1 = s[39] ^ d9;712 bc0 = (t0 << 27) | (t1 >>> 5);713 bc1 = (t1 << 27) | (t0 >>> 5);714 s[30] = bc0 ^ (bc4 & ~bc2);715 s[31] = bc1 ^ (bc5 & ~bc3);716 s[32] = bc2 ^ (bc6 & ~bc4);717 s[33] = bc3 ^ (bc7 & ~bc5);718 s[34] = bc4 ^ (bc8 & ~bc6);719 s[35] = bc5 ^ (bc9 & ~bc7);720 s[36] = bc6 ^ (bc0 & ~bc8);721 s[37] = bc7 ^ (bc1 & ~bc9);722 s[38] = bc8 ^ (bc2 & ~bc0);723 s[39] = bc9 ^ (bc3 & ~bc1);724 t0 = s[40] ^ d0;725 t1 = s[41] ^ d1;726 bc6 = (t1 << 9) | (t0 >>> 23);727 bc7 = (t0 << 9) | (t1 >>> 23);728 t0 = s[42] ^ d2;729 t1 = s[43] ^ d3;730 bc8 = (t0 << 2) | (t1 >>> 30);731 bc9 = (t1 << 2) | (t0 >>> 30);732 t0 = s[44] ^ d4;733 t1 = s[45] ^ d5;734 bc0 = (t1 << 30) | (t0 >>> 2);735 bc1 = (t0 << 30) | (t1 >>> 2);736 t0 = s[46] ^ d6;737 t1 = s[47] ^ d7;738 bc2 = (t1 << 23) | (t0 >>> 9);739 bc3 = (t0 << 23) | (t1 >>> 9);740 t0 = s[48] ^ d8;741 t1 = s[49] ^ d9;742 bc4 = (t1 << 7) | (t0 >>> 25);743 bc5 = (t0 << 7) | (t1 >>> 25);744 s[40] = bc0 ^ (bc4 & ~bc2);745 s[41] = bc1 ^ (bc5 & ~bc3);746 s[42] = bc2 ^ (bc6 & ~bc4);747 s[43] = bc3 ^ (bc7 & ~bc5);748 s[44] = bc4 ^ (bc8 & ~bc6);749 s[45] = bc5 ^ (bc9 & ~bc7);750 s[46] = bc6 ^ (bc0 & ~bc8);751 s[47] = bc7 ^ (bc1 & ~bc9);752 s[48] = bc8 ^ (bc2 & ~bc0);753 s[49] = bc9 ^ (bc3 & ~bc1);754 }755}756// https://github.com/denoland/deno_std/blob/main/hash/_sha3/sponge.ts757const STATE_SIZE = 200;758const TYPE_ERROR_MSG = "sha3: `data` is invalid type";759class Sponge {760 #option;761 #state;762 #rp;763 #absorbing;764 constructor(option) {765 this.#option = option;766 this.#state = new Uint8Array(STATE_SIZE);767 this.#rp = 0;768 this.#absorbing = true;769 }770 /** Applies padding to internal state */771 pad() {772 this.#state[this.#rp] ^= this.#option.dsbyte;773 this.#state[this.#option.rate - 1] ^= 0x80;774 }775 /** Squeezes internal state */776 squeeze(length) {777 if (length < 0) {778 throw new Error("sha3: length cannot be negative");779 }780 this.pad();781 const hash = new Uint8Array(length);782 let pos = 0;783 while (length > 0) {784 const r = length > this.#option.rate ? this.#option.rate : length;785 this.#option.permutator(this.#state);786 hash.set(this.#state.slice(0, r), pos);787 length -= r;788 pos += r;789 }790 this.#absorbing = false;791 return hash;792 }793 /** Updates internal state by absorbing */794 update(data) {795 if (!this.#absorbing) {796 throw new Error("sha3: cannot update already finalized hash");797 }798 let msg;799 if (typeof data === "string") {800 msg = new TextEncoder().encode(data);801 } else if (typeof data === "object") {802 if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {803 msg = new Uint8Array(data);804 } else {805 throw new Error(TYPE_ERROR_MSG);806 }807 } else {808 throw new Error(TYPE_ERROR_MSG);809 }810 let rp = this.#rp;811 for (let i = 0; i < msg.length; ++i) {812 this.#state[rp++] ^= msg[i];813 if (rp >= this.#option.rate) {814 this.#option.permutator(this.#state);815 rp = 0;816 }817 }818 this.#rp = rp;819 return this;820 }821 /** Returns the hash in ArrayBuffer */822 digest() {823 return this.squeeze(this.#option.bitsize >> 3);824 }825}826// https://github.com/denoland/deno_std/blob/main/hash/_sha3/keccak.ts827export class Keccak256 extends Sponge {828 constructor() {829 super({830 bitsize: 256,831 rate: 136,832 dsbyte: 1,833 permutator: keccakf,834 });835 }...
keccakf.ts
Source:keccakf.ts
1// Ported from Go:2// https://github.com/golang/crypto/blob/master/sha3/keccakf.go3// Copyright 2011 The Go Authors. All rights reserved. BSD license.4// https://github.com/golang/go/blob/master/LICENSE5// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.6// This module is browser compatible.7const KECCAK_ROUNDS = 24;8const KECCAK_RC: number[] = [9 0x1,10 0x0,11 0x8082,12 0x0,13 0x808a,14 0x80000000,15 0x80008000,16 0x80000000,17 0x808b,18 0x0,19 0x80000001,20 0x0,21 0x80008081,22 0x80000000,23 0x8009,24 0x80000000,25 0x8a,26 0x0,27 0x88,28 0x0,29 0x80008009,30 0x0,31 0x8000000a,32 0x0,33 0x8000808b,34 0x0,35 0x8b,36 0x80000000,37 0x8089,38 0x80000000,39 0x8003,40 0x80000000,41 0x8002,42 0x80000000,43 0x80,44 0x80000000,45 0x800a,46 0x0,47 0x8000000a,48 0x80000000,49 0x80008081,50 0x80000000,51 0x8080,52 0x80000000,53 0x80000001,54 0x0,55 0x80008008,56 0x80000000,57];58/** keccak1600 permutation function */59export function keccakf(state: Uint8Array): void {60 const s = new Uint32Array(state.buffer);61 let bc0 = 0;62 let bc1 = 0;63 let bc2 = 0;64 let bc3 = 0;65 let bc4 = 0;66 let bc5 = 0;67 let bc6 = 0;68 let bc7 = 0;69 let bc8 = 0;70 let bc9 = 0;71 let d0 = 0;72 let d1 = 0;73 let d2 = 0;74 let d3 = 0;75 let d4 = 0;76 let d5 = 0;77 let d6 = 0;78 let d7 = 0;79 let d8 = 0;80 let d9 = 0;81 let t0 = 0;82 let t1 = 0;83 for (let n = 0; n < KECCAK_ROUNDS * 2; n += 8) {84 // Round 185 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];86 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];87 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];88 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];89 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];90 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];91 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];92 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];93 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];94 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];95 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));96 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));97 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));98 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));99 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));100 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));101 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));102 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));103 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));104 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));105 bc0 = s[0] ^ d0;106 bc1 = s[1] ^ d1;107 t0 = s[12] ^ d2;108 t1 = s[13] ^ d3;109 bc2 = (t1 << 12) | (t0 >>> 20);110 bc3 = (t0 << 12) | (t1 >>> 20);111 t0 = s[24] ^ d4;112 t1 = s[25] ^ d5;113 bc4 = (t1 << 11) | (t0 >>> 21);114 bc5 = (t0 << 11) | (t1 >>> 21);115 t0 = s[36] ^ d6;116 t1 = s[37] ^ d7;117 bc6 = (t0 << 21) | (t1 >>> 11);118 bc7 = (t1 << 21) | (t0 >>> 11);119 t0 = s[48] ^ d8;120 t1 = s[49] ^ d9;121 bc8 = (t0 << 14) | (t1 >>> 18);122 bc9 = (t1 << 14) | (t0 >>> 18);123 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n];124 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 1];125 s[12] = bc2 ^ (bc6 & ~bc4);126 s[13] = bc3 ^ (bc7 & ~bc5);127 s[24] = bc4 ^ (bc8 & ~bc6);128 s[25] = bc5 ^ (bc9 & ~bc7);129 s[36] = bc6 ^ (bc0 & ~bc8);130 s[37] = bc7 ^ (bc1 & ~bc9);131 s[48] = bc8 ^ (bc2 & ~bc0);132 s[49] = bc9 ^ (bc3 & ~bc1);133 t0 = s[20] ^ d0;134 t1 = s[21] ^ d1;135 bc4 = (t0 << 3) | (t1 >>> 29);136 bc5 = (t1 << 3) | (t0 >>> 29);137 t0 = s[32] ^ d2;138 t1 = s[33] ^ d3;139 bc6 = (t1 << 13) | (t0 >>> 19);140 bc7 = (t0 << 13) | (t1 >>> 19);141 t0 = s[44] ^ d4;142 t1 = s[45] ^ d5;143 bc8 = (t1 << 29) | (t0 >>> 3);144 bc9 = (t0 << 29) | (t1 >>> 3);145 t0 = s[6] ^ d6;146 t1 = s[7] ^ d7;147 bc0 = (t0 << 28) | (t1 >>> 4);148 bc1 = (t1 << 28) | (t0 >>> 4);149 t0 = s[18] ^ d8;150 t1 = s[19] ^ d9;151 bc2 = (t0 << 20) | (t1 >>> 12);152 bc3 = (t1 << 20) | (t0 >>> 12);153 s[20] = bc0 ^ (bc4 & ~bc2);154 s[21] = bc1 ^ (bc5 & ~bc3);155 s[32] = bc2 ^ (bc6 & ~bc4);156 s[33] = bc3 ^ (bc7 & ~bc5);157 s[44] = bc4 ^ (bc8 & ~bc6);158 s[45] = bc5 ^ (bc9 & ~bc7);159 s[6] = bc6 ^ (bc0 & ~bc8);160 s[7] = bc7 ^ (bc1 & ~bc9);161 s[18] = bc8 ^ (bc2 & ~bc0);162 s[19] = bc9 ^ (bc3 & ~bc1);163 t0 = s[40] ^ d0;164 t1 = s[41] ^ d1;165 bc8 = (t0 << 18) | (t1 >>> 14);166 bc9 = (t1 << 18) | (t0 >>> 14);167 t0 = s[2] ^ d2;168 t1 = s[3] ^ d3;169 bc0 = (t0 << 1) | (t1 >>> 31);170 bc1 = (t1 << 1) | (t0 >>> 31);171 t0 = s[14] ^ d4;172 t1 = s[15] ^ d5;173 bc2 = (t0 << 6) | (t1 >>> 26);174 bc3 = (t1 << 6) | (t0 >>> 26);175 t0 = s[26] ^ d6;176 t1 = s[27] ^ d7;177 bc4 = (t0 << 25) | (t1 >>> 7);178 bc5 = (t1 << 25) | (t0 >>> 7);179 t0 = s[38] ^ d8;180 t1 = s[39] ^ d9;181 bc6 = (t0 << 8) | (t1 >>> 24);182 bc7 = (t1 << 8) | (t0 >>> 24);183 s[40] = bc0 ^ (bc4 & ~bc2);184 s[41] = bc1 ^ (bc5 & ~bc3);185 s[2] = bc2 ^ (bc6 & ~bc4);186 s[3] = bc3 ^ (bc7 & ~bc5);187 s[14] = bc4 ^ (bc8 & ~bc6);188 s[15] = bc5 ^ (bc9 & ~bc7);189 s[26] = bc6 ^ (bc0 & ~bc8);190 s[27] = bc7 ^ (bc1 & ~bc9);191 s[38] = bc8 ^ (bc2 & ~bc0);192 s[39] = bc9 ^ (bc3 & ~bc1);193 t0 = s[10] ^ d0;194 t1 = s[11] ^ d1;195 bc2 = (t1 << 4) | (t0 >>> 28);196 bc3 = (t0 << 4) | (t1 >>> 28);197 t0 = s[22] ^ d2;198 t1 = s[23] ^ d3;199 bc4 = (t0 << 10) | (t1 >>> 22);200 bc5 = (t1 << 10) | (t0 >>> 22);201 t0 = s[34] ^ d4;202 t1 = s[35] ^ d5;203 bc6 = (t0 << 15) | (t1 >>> 17);204 bc7 = (t1 << 15) | (t0 >>> 17);205 t0 = s[46] ^ d6;206 t1 = s[47] ^ d7;207 bc8 = (t1 << 24) | (t0 >>> 8);208 bc9 = (t0 << 24) | (t1 >>> 8);209 t0 = s[8] ^ d8;210 t1 = s[9] ^ d9;211 bc0 = (t0 << 27) | (t1 >>> 5);212 bc1 = (t1 << 27) | (t0 >>> 5);213 s[10] = bc0 ^ (bc4 & ~bc2);214 s[11] = bc1 ^ (bc5 & ~bc3);215 s[22] = bc2 ^ (bc6 & ~bc4);216 s[23] = bc3 ^ (bc7 & ~bc5);217 s[34] = bc4 ^ (bc8 & ~bc6);218 s[35] = bc5 ^ (bc9 & ~bc7);219 s[46] = bc6 ^ (bc0 & ~bc8);220 s[47] = bc7 ^ (bc1 & ~bc9);221 s[8] = bc8 ^ (bc2 & ~bc0);222 s[9] = bc9 ^ (bc3 & ~bc1);223 t0 = s[30] ^ d0;224 t1 = s[31] ^ d1;225 bc6 = (t1 << 9) | (t0 >>> 23);226 bc7 = (t0 << 9) | (t1 >>> 23);227 t0 = s[42] ^ d2;228 t1 = s[43] ^ d3;229 bc8 = (t0 << 2) | (t1 >>> 30);230 bc9 = (t1 << 2) | (t0 >>> 30);231 t0 = s[4] ^ d4;232 t1 = s[5] ^ d5;233 bc0 = (t1 << 30) | (t0 >>> 2);234 bc1 = (t0 << 30) | (t1 >>> 2);235 t0 = s[16] ^ d6;236 t1 = s[17] ^ d7;237 bc2 = (t1 << 23) | (t0 >>> 9);238 bc3 = (t0 << 23) | (t1 >>> 9);239 t0 = s[28] ^ d8;240 t1 = s[29] ^ d9;241 bc4 = (t1 << 7) | (t0 >>> 25);242 bc5 = (t0 << 7) | (t1 >>> 25);243 s[30] = bc0 ^ (bc4 & ~bc2);244 s[31] = bc1 ^ (bc5 & ~bc3);245 s[42] = bc2 ^ (bc6 & ~bc4);246 s[43] = bc3 ^ (bc7 & ~bc5);247 s[4] = bc4 ^ (bc8 & ~bc6);248 s[5] = bc5 ^ (bc9 & ~bc7);249 s[16] = bc6 ^ (bc0 & ~bc8);250 s[17] = bc7 ^ (bc1 & ~bc9);251 s[28] = bc8 ^ (bc2 & ~bc0);252 s[29] = bc9 ^ (bc3 & ~bc1);253 // Round 2254 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];255 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];256 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];257 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];258 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];259 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];260 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];261 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];262 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];263 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];264 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));265 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));266 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));267 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));268 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));269 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));270 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));271 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));272 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));273 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));274 bc0 = s[0] ^ d0;275 bc1 = s[1] ^ d1;276 t0 = s[32] ^ d2;277 t1 = s[33] ^ d3;278 bc2 = (t1 << 12) | (t0 >>> 20);279 bc3 = (t0 << 12) | (t1 >>> 20);280 t0 = s[14] ^ d4;281 t1 = s[15] ^ d5;282 bc4 = (t1 << 11) | (t0 >>> 21);283 bc5 = (t0 << 11) | (t1 >>> 21);284 t0 = s[46] ^ d6;285 t1 = s[47] ^ d7;286 bc6 = (t0 << 21) | (t1 >>> 11);287 bc7 = (t1 << 21) | (t0 >>> 11);288 t0 = s[28] ^ d8;289 t1 = s[29] ^ d9;290 bc8 = (t0 << 14) | (t1 >>> 18);291 bc9 = (t1 << 14) | (t0 >>> 18);292 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 2];293 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 3];294 s[32] = bc2 ^ (bc6 & ~bc4);295 s[33] = bc3 ^ (bc7 & ~bc5);296 s[14] = bc4 ^ (bc8 & ~bc6);297 s[15] = bc5 ^ (bc9 & ~bc7);298 s[46] = bc6 ^ (bc0 & ~bc8);299 s[47] = bc7 ^ (bc1 & ~bc9);300 s[28] = bc8 ^ (bc2 & ~bc0);301 s[29] = bc9 ^ (bc3 & ~bc1);302 t0 = s[40] ^ d0;303 t1 = s[41] ^ d1;304 bc4 = (t0 << 3) | (t1 >>> 29);305 bc5 = (t1 << 3) | (t0 >>> 29);306 t0 = s[22] ^ d2;307 t1 = s[23] ^ d3;308 bc6 = (t1 << 13) | (t0 >>> 19);309 bc7 = (t0 << 13) | (t1 >>> 19);310 t0 = s[4] ^ d4;311 t1 = s[5] ^ d5;312 bc8 = (t1 << 29) | (t0 >>> 3);313 bc9 = (t0 << 29) | (t1 >>> 3);314 t0 = s[36] ^ d6;315 t1 = s[37] ^ d7;316 bc0 = (t0 << 28) | (t1 >>> 4);317 bc1 = (t1 << 28) | (t0 >>> 4);318 t0 = s[18] ^ d8;319 t1 = s[19] ^ d9;320 bc2 = (t0 << 20) | (t1 >>> 12);321 bc3 = (t1 << 20) | (t0 >>> 12);322 s[40] = bc0 ^ (bc4 & ~bc2);323 s[41] = bc1 ^ (bc5 & ~bc3);324 s[22] = bc2 ^ (bc6 & ~bc4);325 s[23] = bc3 ^ (bc7 & ~bc5);326 s[4] = bc4 ^ (bc8 & ~bc6);327 s[5] = bc5 ^ (bc9 & ~bc7);328 s[36] = bc6 ^ (bc0 & ~bc8);329 s[37] = bc7 ^ (bc1 & ~bc9);330 s[18] = bc8 ^ (bc2 & ~bc0);331 s[19] = bc9 ^ (bc3 & ~bc1);332 t0 = s[30] ^ d0;333 t1 = s[31] ^ d1;334 bc8 = (t0 << 18) | (t1 >>> 14);335 bc9 = (t1 << 18) | (t0 >>> 14);336 t0 = s[12] ^ d2;337 t1 = s[13] ^ d3;338 bc0 = (t0 << 1) | (t1 >>> 31);339 bc1 = (t1 << 1) | (t0 >>> 31);340 t0 = s[44] ^ d4;341 t1 = s[45] ^ d5;342 bc2 = (t0 << 6) | (t1 >>> 26);343 bc3 = (t1 << 6) | (t0 >>> 26);344 t0 = s[26] ^ d6;345 t1 = s[27] ^ d7;346 bc4 = (t0 << 25) | (t1 >>> 7);347 bc5 = (t1 << 25) | (t0 >>> 7);348 t0 = s[8] ^ d8;349 t1 = s[9] ^ d9;350 bc6 = (t0 << 8) | (t1 >>> 24);351 bc7 = (t1 << 8) | (t0 >>> 24);352 s[30] = bc0 ^ (bc4 & ~bc2);353 s[31] = bc1 ^ (bc5 & ~bc3);354 s[12] = bc2 ^ (bc6 & ~bc4);355 s[13] = bc3 ^ (bc7 & ~bc5);356 s[44] = bc4 ^ (bc8 & ~bc6);357 s[45] = bc5 ^ (bc9 & ~bc7);358 s[26] = bc6 ^ (bc0 & ~bc8);359 s[27] = bc7 ^ (bc1 & ~bc9);360 s[8] = bc8 ^ (bc2 & ~bc0);361 s[9] = bc9 ^ (bc3 & ~bc1);362 t0 = s[20] ^ d0;363 t1 = s[21] ^ d1;364 bc2 = (t1 << 4) | (t0 >>> 28);365 bc3 = (t0 << 4) | (t1 >>> 28);366 t0 = s[2] ^ d2;367 t1 = s[3] ^ d3;368 bc4 = (t0 << 10) | (t1 >>> 22);369 bc5 = (t1 << 10) | (t0 >>> 22);370 t0 = s[34] ^ d4;371 t1 = s[35] ^ d5;372 bc6 = (t0 << 15) | (t1 >>> 17);373 bc7 = (t1 << 15) | (t0 >>> 17);374 t0 = s[16] ^ d6;375 t1 = s[17] ^ d7;376 bc8 = (t1 << 24) | (t0 >>> 8);377 bc9 = (t0 << 24) | (t1 >>> 8);378 t0 = s[48] ^ d8;379 t1 = s[49] ^ d9;380 bc0 = (t0 << 27) | (t1 >>> 5);381 bc1 = (t1 << 27) | (t0 >>> 5);382 s[20] = bc0 ^ (bc4 & ~bc2);383 s[21] = bc1 ^ (bc5 & ~bc3);384 s[2] = bc2 ^ (bc6 & ~bc4);385 s[3] = bc3 ^ (bc7 & ~bc5);386 s[34] = bc4 ^ (bc8 & ~bc6);387 s[35] = bc5 ^ (bc9 & ~bc7);388 s[16] = bc6 ^ (bc0 & ~bc8);389 s[17] = bc7 ^ (bc1 & ~bc9);390 s[48] = bc8 ^ (bc2 & ~bc0);391 s[49] = bc9 ^ (bc3 & ~bc1);392 t0 = s[10] ^ d0;393 t1 = s[11] ^ d1;394 bc6 = (t1 << 9) | (t0 >>> 23);395 bc7 = (t0 << 9) | (t1 >>> 23);396 t0 = s[42] ^ d2;397 t1 = s[43] ^ d3;398 bc8 = (t0 << 2) | (t1 >>> 30);399 bc9 = (t1 << 2) | (t0 >>> 30);400 t0 = s[24] ^ d4;401 t1 = s[25] ^ d5;402 bc0 = (t1 << 30) | (t0 >>> 2);403 bc1 = (t0 << 30) | (t1 >>> 2);404 t0 = s[6] ^ d6;405 t1 = s[7] ^ d7;406 bc2 = (t1 << 23) | (t0 >>> 9);407 bc3 = (t0 << 23) | (t1 >>> 9);408 t0 = s[38] ^ d8;409 t1 = s[39] ^ d9;410 bc4 = (t1 << 7) | (t0 >>> 25);411 bc5 = (t0 << 7) | (t1 >>> 25);412 s[10] = bc0 ^ (bc4 & ~bc2);413 s[11] = bc1 ^ (bc5 & ~bc3);414 s[42] = bc2 ^ (bc6 & ~bc4);415 s[43] = bc3 ^ (bc7 & ~bc5);416 s[24] = bc4 ^ (bc8 & ~bc6);417 s[25] = bc5 ^ (bc9 & ~bc7);418 s[6] = bc6 ^ (bc0 & ~bc8);419 s[7] = bc7 ^ (bc1 & ~bc9);420 s[38] = bc8 ^ (bc2 & ~bc0);421 s[39] = bc9 ^ (bc3 & ~bc1);422 // Round 3423 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];424 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];425 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];426 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];427 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];428 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];429 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];430 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];431 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];432 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];433 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));434 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));435 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));436 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));437 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));438 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));439 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));440 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));441 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));442 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));443 bc0 = s[0] ^ d0;444 bc1 = s[1] ^ d1;445 t0 = s[22] ^ d2;446 t1 = s[23] ^ d3;447 bc2 = (t1 << 12) | (t0 >>> 20);448 bc3 = (t0 << 12) | (t1 >>> 20);449 t0 = s[44] ^ d4;450 t1 = s[45] ^ d5;451 bc4 = (t1 << 11) | (t0 >>> 21);452 bc5 = (t0 << 11) | (t1 >>> 21);453 t0 = s[16] ^ d6;454 t1 = s[17] ^ d7;455 bc6 = (t0 << 21) | (t1 >>> 11);456 bc7 = (t1 << 21) | (t0 >>> 11);457 t0 = s[38] ^ d8;458 t1 = s[39] ^ d9;459 bc8 = (t0 << 14) | (t1 >>> 18);460 bc9 = (t1 << 14) | (t0 >>> 18);461 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 4];462 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 5];463 s[22] = bc2 ^ (bc6 & ~bc4);464 s[23] = bc3 ^ (bc7 & ~bc5);465 s[44] = bc4 ^ (bc8 & ~bc6);466 s[45] = bc5 ^ (bc9 & ~bc7);467 s[16] = bc6 ^ (bc0 & ~bc8);468 s[17] = bc7 ^ (bc1 & ~bc9);469 s[38] = bc8 ^ (bc2 & ~bc0);470 s[39] = bc9 ^ (bc3 & ~bc1);471 t0 = s[30] ^ d0;472 t1 = s[31] ^ d1;473 bc4 = (t0 << 3) | (t1 >>> 29);474 bc5 = (t1 << 3) | (t0 >>> 29);475 t0 = s[2] ^ d2;476 t1 = s[3] ^ d3;477 bc6 = (t1 << 13) | (t0 >>> 19);478 bc7 = (t0 << 13) | (t1 >>> 19);479 t0 = s[24] ^ d4;480 t1 = s[25] ^ d5;481 bc8 = (t1 << 29) | (t0 >>> 3);482 bc9 = (t0 << 29) | (t1 >>> 3);483 t0 = s[46] ^ d6;484 t1 = s[47] ^ d7;485 bc0 = (t0 << 28) | (t1 >>> 4);486 bc1 = (t1 << 28) | (t0 >>> 4);487 t0 = s[18] ^ d8;488 t1 = s[19] ^ d9;489 bc2 = (t0 << 20) | (t1 >>> 12);490 bc3 = (t1 << 20) | (t0 >>> 12);491 s[30] = bc0 ^ (bc4 & ~bc2);492 s[31] = bc1 ^ (bc5 & ~bc3);493 s[2] = bc2 ^ (bc6 & ~bc4);494 s[3] = bc3 ^ (bc7 & ~bc5);495 s[24] = bc4 ^ (bc8 & ~bc6);496 s[25] = bc5 ^ (bc9 & ~bc7);497 s[46] = bc6 ^ (bc0 & ~bc8);498 s[47] = bc7 ^ (bc1 & ~bc9);499 s[18] = bc8 ^ (bc2 & ~bc0);500 s[19] = bc9 ^ (bc3 & ~bc1);501 t0 = s[10] ^ d0;502 t1 = s[11] ^ d1;503 bc8 = (t0 << 18) | (t1 >>> 14);504 bc9 = (t1 << 18) | (t0 >>> 14);505 t0 = s[32] ^ d2;506 t1 = s[33] ^ d3;507 bc0 = (t0 << 1) | (t1 >>> 31);508 bc1 = (t1 << 1) | (t0 >>> 31);509 t0 = s[4] ^ d4;510 t1 = s[5] ^ d5;511 bc2 = (t0 << 6) | (t1 >>> 26);512 bc3 = (t1 << 6) | (t0 >>> 26);513 t0 = s[26] ^ d6;514 t1 = s[27] ^ d7;515 bc4 = (t0 << 25) | (t1 >>> 7);516 bc5 = (t1 << 25) | (t0 >>> 7);517 t0 = s[48] ^ d8;518 t1 = s[49] ^ d9;519 bc6 = (t0 << 8) | (t1 >>> 24);520 bc7 = (t1 << 8) | (t0 >>> 24);521 s[10] = bc0 ^ (bc4 & ~bc2);522 s[11] = bc1 ^ (bc5 & ~bc3);523 s[32] = bc2 ^ (bc6 & ~bc4);524 s[33] = bc3 ^ (bc7 & ~bc5);525 s[4] = bc4 ^ (bc8 & ~bc6);526 s[5] = bc5 ^ (bc9 & ~bc7);527 s[26] = bc6 ^ (bc0 & ~bc8);528 s[27] = bc7 ^ (bc1 & ~bc9);529 s[48] = bc8 ^ (bc2 & ~bc0);530 s[49] = bc9 ^ (bc3 & ~bc1);531 t0 = s[40] ^ d0;532 t1 = s[41] ^ d1;533 bc2 = (t1 << 4) | (t0 >>> 28);534 bc3 = (t0 << 4) | (t1 >>> 28);535 t0 = s[12] ^ d2;536 t1 = s[13] ^ d3;537 bc4 = (t0 << 10) | (t1 >>> 22);538 bc5 = (t1 << 10) | (t0 >>> 22);539 t0 = s[34] ^ d4;540 t1 = s[35] ^ d5;541 bc6 = (t0 << 15) | (t1 >>> 17);542 bc7 = (t1 << 15) | (t0 >>> 17);543 t0 = s[6] ^ d6;544 t1 = s[7] ^ d7;545 bc8 = (t1 << 24) | (t0 >>> 8);546 bc9 = (t0 << 24) | (t1 >>> 8);547 t0 = s[28] ^ d8;548 t1 = s[29] ^ d9;549 bc0 = (t0 << 27) | (t1 >>> 5);550 bc1 = (t1 << 27) | (t0 >>> 5);551 s[40] = bc0 ^ (bc4 & ~bc2);552 s[41] = bc1 ^ (bc5 & ~bc3);553 s[12] = bc2 ^ (bc6 & ~bc4);554 s[13] = bc3 ^ (bc7 & ~bc5);555 s[34] = bc4 ^ (bc8 & ~bc6);556 s[35] = bc5 ^ (bc9 & ~bc7);557 s[6] = bc6 ^ (bc0 & ~bc8);558 s[7] = bc7 ^ (bc1 & ~bc9);559 s[28] = bc8 ^ (bc2 & ~bc0);560 s[29] = bc9 ^ (bc3 & ~bc1);561 t0 = s[20] ^ d0;562 t1 = s[21] ^ d1;563 bc6 = (t1 << 9) | (t0 >>> 23);564 bc7 = (t0 << 9) | (t1 >>> 23);565 t0 = s[42] ^ d2;566 t1 = s[43] ^ d3;567 bc8 = (t0 << 2) | (t1 >>> 30);568 bc9 = (t1 << 2) | (t0 >>> 30);569 t0 = s[14] ^ d4;570 t1 = s[15] ^ d5;571 bc0 = (t1 << 30) | (t0 >>> 2);572 bc1 = (t0 << 30) | (t1 >>> 2);573 t0 = s[36] ^ d6;574 t1 = s[37] ^ d7;575 bc2 = (t1 << 23) | (t0 >>> 9);576 bc3 = (t0 << 23) | (t1 >>> 9);577 t0 = s[8] ^ d8;578 t1 = s[9] ^ d9;579 bc4 = (t1 << 7) | (t0 >>> 25);580 bc5 = (t0 << 7) | (t1 >>> 25);581 s[20] = bc0 ^ (bc4 & ~bc2);582 s[21] = bc1 ^ (bc5 & ~bc3);583 s[42] = bc2 ^ (bc6 & ~bc4);584 s[43] = bc3 ^ (bc7 & ~bc5);585 s[14] = bc4 ^ (bc8 & ~bc6);586 s[15] = bc5 ^ (bc9 & ~bc7);587 s[36] = bc6 ^ (bc0 & ~bc8);588 s[37] = bc7 ^ (bc1 & ~bc9);589 s[8] = bc8 ^ (bc2 & ~bc0);590 s[9] = bc9 ^ (bc3 & ~bc1);591 // Round 4592 bc0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];593 bc1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];594 bc2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];595 bc3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];596 bc4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];597 bc5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];598 bc6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];599 bc7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];600 bc8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];601 bc9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];602 d0 = bc8 ^ ((bc2 << 1) | (bc3 >>> 31));603 d1 = bc9 ^ ((bc3 << 1) | (bc2 >>> 31));604 d2 = bc0 ^ ((bc4 << 1) | (bc5 >>> 31));605 d3 = bc1 ^ ((bc5 << 1) | (bc4 >>> 31));606 d4 = bc2 ^ ((bc6 << 1) | (bc7 >>> 31));607 d5 = bc3 ^ ((bc7 << 1) | (bc6 >>> 31));608 d6 = bc4 ^ ((bc8 << 1) | (bc9 >>> 31));609 d7 = bc5 ^ ((bc9 << 1) | (bc8 >>> 31));610 d8 = bc6 ^ ((bc0 << 1) | (bc1 >>> 31));611 d9 = bc7 ^ ((bc1 << 1) | (bc0 >>> 31));612 bc0 = s[0] ^ d0;613 bc1 = s[1] ^ d1;614 t0 = s[2] ^ d2;615 t1 = s[3] ^ d3;616 bc2 = (t1 << 12) | (t0 >>> 20);617 bc3 = (t0 << 12) | (t1 >>> 20);618 t0 = s[4] ^ d4;619 t1 = s[5] ^ d5;620 bc4 = (t1 << 11) | (t0 >>> 21);621 bc5 = (t0 << 11) | (t1 >>> 21);622 t0 = s[6] ^ d6;623 t1 = s[7] ^ d7;624 bc6 = (t0 << 21) | (t1 >>> 11);625 bc7 = (t1 << 21) | (t0 >>> 11);626 t0 = s[8] ^ d8;627 t1 = s[9] ^ d9;628 bc8 = (t0 << 14) | (t1 >>> 18);629 bc9 = (t1 << 14) | (t0 >>> 18);630 s[0] = bc0 ^ (bc4 & ~bc2) ^ KECCAK_RC[n + 6];631 s[1] = bc1 ^ (bc5 & ~bc3) ^ KECCAK_RC[n + 7];632 s[2] = bc2 ^ (bc6 & ~bc4);633 s[3] = bc3 ^ (bc7 & ~bc5);634 s[4] = bc4 ^ (bc8 & ~bc6);635 s[5] = bc5 ^ (bc9 & ~bc7);636 s[6] = bc6 ^ (bc0 & ~bc8);637 s[7] = bc7 ^ (bc1 & ~bc9);638 s[8] = bc8 ^ (bc2 & ~bc0);639 s[9] = bc9 ^ (bc3 & ~bc1);640 t0 = s[10] ^ d0;641 t1 = s[11] ^ d1;642 bc4 = (t0 << 3) | (t1 >>> 29);643 bc5 = (t1 << 3) | (t0 >>> 29);644 t0 = s[12] ^ d2;645 t1 = s[13] ^ d3;646 bc6 = (t1 << 13) | (t0 >>> 19);647 bc7 = (t0 << 13) | (t1 >>> 19);648 t0 = s[14] ^ d4;649 t1 = s[15] ^ d5;650 bc8 = (t1 << 29) | (t0 >>> 3);651 bc9 = (t0 << 29) | (t1 >>> 3);652 t0 = s[16] ^ d6;653 t1 = s[17] ^ d7;654 bc0 = (t0 << 28) | (t1 >>> 4);655 bc1 = (t1 << 28) | (t0 >>> 4);656 t0 = s[18] ^ d8;657 t1 = s[19] ^ d9;658 bc2 = (t0 << 20) | (t1 >>> 12);659 bc3 = (t1 << 20) | (t0 >>> 12);660 s[10] = bc0 ^ (bc4 & ~bc2);661 s[11] = bc1 ^ (bc5 & ~bc3);662 s[12] = bc2 ^ (bc6 & ~bc4);663 s[13] = bc3 ^ (bc7 & ~bc5);664 s[14] = bc4 ^ (bc8 & ~bc6);665 s[15] = bc5 ^ (bc9 & ~bc7);666 s[16] = bc6 ^ (bc0 & ~bc8);667 s[17] = bc7 ^ (bc1 & ~bc9);668 s[18] = bc8 ^ (bc2 & ~bc0);669 s[19] = bc9 ^ (bc3 & ~bc1);670 t0 = s[20] ^ d0;671 t1 = s[21] ^ d1;672 bc8 = (t0 << 18) | (t1 >>> 14);673 bc9 = (t1 << 18) | (t0 >>> 14);674 t0 = s[22] ^ d2;675 t1 = s[23] ^ d3;676 bc0 = (t0 << 1) | (t1 >>> 31);677 bc1 = (t1 << 1) | (t0 >>> 31);678 t0 = s[24] ^ d4;679 t1 = s[25] ^ d5;680 bc2 = (t0 << 6) | (t1 >>> 26);681 bc3 = (t1 << 6) | (t0 >>> 26);682 t0 = s[26] ^ d6;683 t1 = s[27] ^ d7;684 bc4 = (t0 << 25) | (t1 >>> 7);685 bc5 = (t1 << 25) | (t0 >>> 7);686 t0 = s[28] ^ d8;687 t1 = s[29] ^ d9;688 bc6 = (t0 << 8) | (t1 >>> 24);689 bc7 = (t1 << 8) | (t0 >>> 24);690 s[20] = bc0 ^ (bc4 & ~bc2);691 s[21] = bc1 ^ (bc5 & ~bc3);692 s[22] = bc2 ^ (bc6 & ~bc4);693 s[23] = bc3 ^ (bc7 & ~bc5);694 s[24] = bc4 ^ (bc8 & ~bc6);695 s[25] = bc5 ^ (bc9 & ~bc7);696 s[26] = bc6 ^ (bc0 & ~bc8);697 s[27] = bc7 ^ (bc1 & ~bc9);698 s[28] = bc8 ^ (bc2 & ~bc0);699 s[29] = bc9 ^ (bc3 & ~bc1);700 t0 = s[30] ^ d0;701 t1 = s[31] ^ d1;702 bc2 = (t1 << 4) | (t0 >>> 28);703 bc3 = (t0 << 4) | (t1 >>> 28);704 t0 = s[32] ^ d2;705 t1 = s[33] ^ d3;706 bc4 = (t0 << 10) | (t1 >>> 22);707 bc5 = (t1 << 10) | (t0 >>> 22);708 t0 = s[34] ^ d4;709 t1 = s[35] ^ d5;710 bc6 = (t0 << 15) | (t1 >>> 17);711 bc7 = (t1 << 15) | (t0 >>> 17);712 t0 = s[36] ^ d6;713 t1 = s[37] ^ d7;714 bc8 = (t1 << 24) | (t0 >>> 8);715 bc9 = (t0 << 24) | (t1 >>> 8);716 t0 = s[38] ^ d8;717 t1 = s[39] ^ d9;718 bc0 = (t0 << 27) | (t1 >>> 5);719 bc1 = (t1 << 27) | (t0 >>> 5);720 s[30] = bc0 ^ (bc4 & ~bc2);721 s[31] = bc1 ^ (bc5 & ~bc3);722 s[32] = bc2 ^ (bc6 & ~bc4);723 s[33] = bc3 ^ (bc7 & ~bc5);724 s[34] = bc4 ^ (bc8 & ~bc6);725 s[35] = bc5 ^ (bc9 & ~bc7);726 s[36] = bc6 ^ (bc0 & ~bc8);727 s[37] = bc7 ^ (bc1 & ~bc9);728 s[38] = bc8 ^ (bc2 & ~bc0);729 s[39] = bc9 ^ (bc3 & ~bc1);730 t0 = s[40] ^ d0;731 t1 = s[41] ^ d1;732 bc6 = (t1 << 9) | (t0 >>> 23);733 bc7 = (t0 << 9) | (t1 >>> 23);734 t0 = s[42] ^ d2;735 t1 = s[43] ^ d3;736 bc8 = (t0 << 2) | (t1 >>> 30);737 bc9 = (t1 << 2) | (t0 >>> 30);738 t0 = s[44] ^ d4;739 t1 = s[45] ^ d5;740 bc0 = (t1 << 30) | (t0 >>> 2);741 bc1 = (t0 << 30) | (t1 >>> 2);742 t0 = s[46] ^ d6;743 t1 = s[47] ^ d7;744 bc2 = (t1 << 23) | (t0 >>> 9);745 bc3 = (t0 << 23) | (t1 >>> 9);746 t0 = s[48] ^ d8;747 t1 = s[49] ^ d9;748 bc4 = (t1 << 7) | (t0 >>> 25);749 bc5 = (t0 << 7) | (t1 >>> 25);750 s[40] = bc0 ^ (bc4 & ~bc2);751 s[41] = bc1 ^ (bc5 & ~bc3);752 s[42] = bc2 ^ (bc6 & ~bc4);753 s[43] = bc3 ^ (bc7 & ~bc5);754 s[44] = bc4 ^ (bc8 & ~bc6);755 s[45] = bc5 ^ (bc9 & ~bc7);756 s[46] = bc6 ^ (bc0 & ~bc8);757 s[47] = bc7 ^ (bc1 & ~bc9);758 s[48] = bc8 ^ (bc2 & ~bc0);759 s[49] = bc9 ^ (bc3 & ~bc1);760 }...
Background.js
Source:Background.js
1// Classe com as imagens de fundo para renderização2class Background {3 constructor(game){4 this.game = game5 this.sky = null6 this.nextSky = null7 this.BC1 = null8 this.nextBC1 = null9 this.BC2 = null10 this.nextBC2 = null11 this.BC3 = null12 this.nextBC3 = null13 this.offSetX = 014 this.offSetY = 015 this.nextAlpha = 116 this.currentAlpha = 117 }18 render(ctx, canvasWidth, canvasHeight){19 let HMDraw = HelperMethods.draw20 let HMMath = HelperMethods.math21 let BC1Correction = 0.000222 let BC2Correction = 0.000423 let BC3Correction = 0.000624 let BC1X = this.offSetX*BC1Correction*this.game.player.speed25 let BC2X = this.offSetX*BC2Correction*this.game.player.speed26 let BC3X = this.offSetX*BC3Correction*this.game.player.speed27 if (this.BC1 !== null){28 if (BC1X > this.BC1.width){29 BC1X -= this.BC1.width30 }31 if (BC1X < 0){32 BC1X +=this.BC1.width33 }34 }35 if (this.BC2 !== null){36 if (BC2X > this.BC2.width){37 BC2X -= this.BC2.width38 }39 if (BC2X < 0){40 BC2X +=this.BC2.width41 }42 }43 if (this.BC3 !== null){44 if (BC3X > this.BC3.width){45 BC3X -= this.BC3.width46 }47 if (BC3X < 0){48 BC3X += this.BC3.width49 }50 }51 let BC1Y = HMMath.setMaxMin(-20 + this.offSetY*BC1Correction, 0, -50)52 let BC2Y = HMMath.setMaxMin(-20 + this.offSetY*BC2Correction, 0, -50)53 let BC3Y = HMMath.setMaxMin(-20 + this.offSetY*BC3Correction, 0, -50)54 this.sky !== null && HMDraw.drawSpriteWithAlpha(ctx, this.sky, 0, 0,Game.STANDARD_WIDTH, Game.STANDARD_HEIGHT, this.currentAlpha, canvasWidth, canvasHeight)55 this.nextSky !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextSky, 0, 0,Game.STANDARD_WIDTH, Game.STANDARD_HEIGHT, this.nextAlpha, canvasWidth, canvasHeight)56 this.BC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC1,BC1X - this.BC1.width, BC1Y,this.BC1.width, this.BC1.height, this.currentAlpha, canvasWidth, canvasHeight)57 this.BC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC1, BC1X, BC1Y,this.BC1.width, this.BC1.height, this.currentAlpha, canvasWidth, canvasHeight)58 this.BC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC1, BC1X + this.BC1.width, BC1Y,this.BC1.width, this.BC1.height, this.currentAlpha, canvasWidth, canvasHeight)59 this.nextBC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC1, BC1X - this.BC1.width, BC1Y,this.nextBC1.width, this.nextBC1.height, this.nextAlpha, canvasWidth, canvasHeight)60 this.nextBC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC1, BC1X, BC1Y,this.nextBC1.width, this.nextBC1.height, this.nextAlpha, canvasWidth, canvasHeight)61 this.nextBC1 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC1, BC1X + this.BC1.width, BC1Y,this.nextBC1.width, this.nextBC1.height, this.nextAlpha, canvasWidth, canvasHeight)62 this.BC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC2,BC2X - this.BC2.width, BC2Y,this.BC2.width, this.BC2.height, this.currentAlpha, canvasWidth, canvasHeight)63 this.BC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC2, BC2X, BC2Y,this.BC2.width, this.BC2.height, this.currentAlpha, canvasWidth, canvasHeight)64 this.BC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC2, BC2X + this.BC2.width, BC2Y,this.BC2.width, this.BC2.height, this.currentAlpha, canvasWidth, canvasHeight)65 this.nextBC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC2, BC2X - this.BC2.width, BC2Y,this.nextBC2.width, this.nextBC2.height, this.nextAlpha, canvasWidth, canvasHeight)66 this.nextBC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC2, BC2X, BC2Y,this.nextBC2.width, this.nextBC2.height, this.nextAlpha, canvasWidth, canvasHeight)67 this.nextBC2 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC2, BC2X + this.BC2.width, BC2Y,this.nextBC2.width, this.nextBC2.height, this.nextAlpha, canvasWidth, canvasHeight)68 this.BC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC3,BC3X - this.BC3.width, BC3Y,this.BC3.width, this.BC3.height, this.currentAlpha, canvasWidth, canvasHeight)69 this.BC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC3, BC3X, BC3Y,this.BC3.width, this.BC3.height, this.currentAlpha, canvasWidth, canvasHeight)70 this.BC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.BC3, BC3X + this.BC3.width, BC3Y,this.BC3.width, this.BC3.height, this.currentAlpha, canvasWidth, canvasHeight)71 this.nextBC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC3, BC3X - this.BC3.width, BC3Y,this.nextBC3.width, this.nextBC3.height, this.nextAlpha, canvasWidth, canvasHeight)72 this.nextBC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC3, BC3X, BC3Y,this.nextBC3.width, this.nextBC3.height, this.nextAlpha, canvasWidth, canvasHeight)73 this.nextBC3 !== null && HMDraw.drawSpriteWithAlpha(ctx, this.nextBC3, BC3X + this.BC3.width, BC3Y,this.nextBC3.width, this.nextBC3.height, this.nextAlpha, canvasWidth, canvasHeight)74 }75 update(){76 if (this.sky === null || this.BC1 === null || this.BC2 === null || this.BC3 === null){77 this.changeBackground(this.game.currentStage, false);78 }79 if (this.nextAlpha < 1 ){80 if (this.game.road.findSegment(this.game.player.z - Game.SEGMENT_LENGTH) !== this.game.player.currentSegment){81 this.currentAlpha -= 0.02582 this.nextAlpha += 0.02583 }84 if (this.nextAlpha > 1){85 this.nextSky = null86 this.nextBC1 = null87 this.nextBC2 = null88 this.nextBC3 = null89 this.currentAlpha = 190 this.changeBackground(this.game.currentStage, false)91 }92 }93 this.offSetX = -(this.game.road.findSegment(this.game.player.z).curve + this.game.player.x*2)94 this.offSetY = this.game.road.findSegment(this.game.player.z).worldPoints.y95 }96 changeBackground(stage, next) {97 let sky, BC1, BC2, BC398 switch (stage) {99 case Game.SUBURB:100 sky = Images.subBackgrounds[0]101 BC1 = Images.subBackgrounds[1]102 BC2 = Images.subBackgrounds[2]103 BC3 = Images.subBackgrounds[3]104 break105 case Game.CITY:106 sky = Images.cityBackgrounds[0]107 BC1 = Images.cityBackgrounds[1]108 BC2 = Images.cityBackgrounds[2]109 BC3 = Images.cityBackgrounds[3]110 break111 case Game.FARM:112 sky = Images.farmBackgrounds[0]113 BC1 = Images.farmBackgrounds[1]114 BC2 = Images.farmBackgrounds[2]115 BC3 = Images.farmBackgrounds[3]116 break117 case Game.FOREST:118 sky = Images.forestBackgrounds[0]119 BC1 = Images.forestBackgrounds[1]120 BC2 = Images.forestBackgrounds[2]121 BC3 = Images.forestBackgrounds[3]122 break123 case Game.BEACH:124 sky = Images.beachBackgrounds[0]125 BC1 = Images.beachBackgrounds[1]126 BC2 = Images.beachBackgrounds[2]127 BC3 = Images.beachBackgrounds[3]128 break129 default:130 sky = null131 BC1 = null132 BC2 = null133 BC3 = null134 }135 if (next){136 this.nextSky = sky137 this.nextBC1 = BC1138 this.nextBC2 = BC2139 this.nextBC3 = BC3140 } else{141 this.sky = sky142 this.BC1 = BC1143 this.BC2 = BC2144 this.BC3 = BC3145 }146 }...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var bc3 = new wptoolkit.BC3();3bc3.setKey('your key here');4bc3.setSecret('your secret here');5bc3.setToken('your token here');6bc3.setTokenSecret('your token secret here');7bc3.get('statuses/home_timeline', function(err, data) {8 if(err) {9 console.log(err);10 }11 else {12 console.log(data);13 }14});15[Back to top](#table-of-contents)16[Back to top](#table-of-contents)17[Back to top](#table-of-contents)18var wptoolkit = require('wptoolkit');19var bc4 = new wptoolkit.BC4();20bc4.setAccessToken('your access token here');21bc4.get('user', function(err, data) {22 if(err) {23 console.log(err);24 }25 else {26 console.log(data);27 }28});29[Back to top](#table-of-contents)30[Back to top](#table-of-contents)31[Back to top](#table-of-contents)32var wptoolkit = require('wptoolkit');33var bc5 = new wptoolkit.BC5();34bc5.setAccessToken('your access token here');35bc5.get('user', function(err, data) {36 if(err) {37 console.log(err);38 }39 else {40 console.log(data);41 }42});43[Back to top](#table-of-
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!