Program 3.3: Matrix multiplication with fast scalar product
Algorithmic cryptanalysis codes by Antoine Joux are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
void Mul(WORD res[DIM], WORD mat1[DIM], WORD mat2[DIM]) { int l,c,k; WORD val,mask; for (l=0;l<DIM;l++) res[l]=0; for (c=0;c<DIM;c++) { mask=0; for (k=0;k<DIM;k++) { mask^=(bit(mat2,k,c)<<k); } for (l=0;l<DIM;l++) { val=mat1[l]&mask; val^=(val>>16); val^=(val>>8); val^=(val>>4); val^=(val>>2); val^=(val>>1); if (val&1) flipbit(res,l,c); } } }
Credits for page styles: Dynamic Drive CSS Library