private static byte[][] MixColumns(byte[][] s) { int[] sp = new int[4]; byte b02 = (byte)0x02, b03 = (byte)0x03; for (int c = 0; c < 4; c++) { sp[0] = AESFeistel.FFMul(b02, s[0][c]) ^ AESFeistel.FFMul(b03, s[1][c]) ^ s[2][c] ^ s[3][c]; sp[1] = s[0][c] ^ AESFeistel.FFMul(b02, s[1][c]) ^ AESFeistel.FFMul(b03, s[2][c]) ^ s[3][c]; sp[2] = s[0][c] ^ s[1][c] ^ AESFeistel.FFMul(b02, s[2][c]) ^ AESFeistel.FFMul(b03, s[3][c]); sp[3] = AESFeistel.FFMul(b03, s[0][c]) ^ s[1][c] ^ s[2][c] ^ AESFeistel.FFMul(b02, s[3][c]); for (int i = 0; i < 4; i++) { s[i][c] = (byte)(sp[i]); } } return(s); }
private static byte[][] InvMixColumns(byte[][] s) { int[] sp = new int[4]; byte b02 = (byte)0x0e, b03 = (byte)0x0b, b04 = (byte)0x0d, b05 = (byte)0x09; for (int c = 0; c < 4; c++) { sp[0] = AESFeistel.FFMul(b02, s[0][c]) ^ AESFeistel.FFMul(b03, s[1][c]) ^ AESFeistel.FFMul(b04, s[2][c]) ^ AESFeistel.FFMul(b05, s[3][c]); sp[1] = AESFeistel.FFMul(b05, s[0][c]) ^ AESFeistel.FFMul(b02, s[1][c]) ^ AESFeistel.FFMul(b03, s[2][c]) ^ AESFeistel.FFMul(b04, s[3][c]); sp[2] = AESFeistel.FFMul(b04, s[0][c]) ^ AESFeistel.FFMul(b05, s[1][c]) ^ AESFeistel.FFMul(b02, s[2][c]) ^ AESFeistel.FFMul(b03, s[3][c]); sp[3] = AESFeistel.FFMul(b03, s[0][c]) ^ AESFeistel.FFMul(b04, s[1][c]) ^ AESFeistel.FFMul(b05, s[2][c]) ^ AESFeistel.FFMul(b02, s[3][c]); for (int i = 0; i < 4; i++) { s[i][c] = (byte)(sp[i]); } } return(s); }