private static byte GFDet(byte[][] mtx) { if (mtx.Length == 2) { byte tm = GF.Multiply(mtx[0][0], mtx[1][1]); tm ^= GF.Multiply(mtx[1][0], mtx[0][1]); return(tm); } byte res = 0; for (int i = 0; i < mtx.Length; ++i) { byte detSub = GFDet(SubMatrix(mtx, i, 0)); res ^= GF.Multiply(mtx[i][0], detSub); } return(res); }
private static void MixColumns(byte[] state, int offset, int Nb, byte[][] mtx) { for (int col = 0; col < Nb; col++) { byte[] resVector = new byte[4]; for (int bIndex = 0; bIndex < 4; bIndex++) { for (int j = 0; j < 4; j++) { resVector[bIndex] ^= GF.Multiply(mtx[bIndex][j], state[offset + j * Nb + col]); } } for (int j = 0; j < 4; j++) { state[offset + j * Nb + col] = resVector[j]; } } }