Program 3.7: Elementary matrix multiplication over GF(p)
Algorithmic cryptanalysis codes by Antoine Joux are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
#include <stdio.h> #include <stdlib.h> #define TYPE unsigned short #define MODULO 46337 /* Also works with primes up to 65521*/ #define access(M,i,j,size) M[(i)+((j)*(size))] void matmul(TYPE * A, TYPE * B, TYPE *Res, int size) { int i,j,k; unsigned int tmp; for(i=0;i<size;i++) for(j=0;j<size;j++) { tmp=0; for(k=0;k<size;k++) { tmp=(tmp+access(A,i,k,size)*access(B,k,j,size))%MODULO; } access(Res,i,j,size)=tmp; } }
Credits for page styles: Dynamic Drive CSS Library