java-me - 我的 MixColumns 实现是否正确?
问题描述
我正在尝试在 J2ME 中实现 AES,我已经根据维基百科上的 C# 示例实现了我的:https ://en.wikipedia.org/wiki/Rijndael_MixColumns#Implementation_example 我的 AES 实现给出了不正确的结果,这是代码我最没有信心,所以我想确保它是正确的:
state
是以列主要顺序存储状态矩阵的字节数组。
public void mix_columns() {
byte[] new_state = new byte[16];
for (int i = 0; i < 4; i++) {
new_state[0|(i<<2)] = (byte)(
galois_field_multiply((byte)0x02, state[0|(i<<2)]) ^
galois_field_multiply((byte)0x03, state[1|(i<<2)]) ^
state[2|(i<<2)] ^
state[3|(i<<2)]
);
new_state[1|(i<<2)] = (byte)(
state[0|(i<<2)] ^
galois_field_multiply((byte)0x02, state[1|(i<<2)]) ^
galois_field_multiply((byte)0x03, state[2|(i<<2)]) ^
state[3|(i<<2)]
);
new_state[2|(i<<2)] = (byte)(
state[0|(i<<2)] ^
state[1|(i<<2)] ^
galois_field_multiply((byte)0x02, state[2|(i<<2)]) ^
galois_field_multiply((byte)0x03, state[3|(i<<2)])
);
new_state[3|(i<<2)] = (byte)(
galois_field_multiply((byte)0x03, state[0|(i<<2)]) ^
state[1|(i<<2)] ^
state[2|(i<<2)] ^
galois_field_multiply((byte)0x02, state[3|(i<<2)])
);
}
state = new_state;
}
解决方案
实现是正确的,在页面上有一个带有一些测试向量的部分。输入的每一列都可以使用这些测试向量之一单独测试,这些向量提供正确的结果。例如,您可以提供以下状态:
(byte)0xDB, (byte)0x13, (byte)0x53, (byte)0x45,
(byte)0xDB, (byte)0x13, (byte)0x53, (byte)0x45,
(byte)0xDB, (byte)0x13, (byte)0x53, (byte)0x45,
(byte)0xDB, (byte)0x13, (byte)0x53, (byte)0x45,
它将提供值:
(byte)0x8E, (byte)0x4D, (byte)0xA1, (byte)0xBC,
(byte)0x8E, (byte)0x4D, (byte)0xA1, (byte)0xBC,
(byte)0x8E, (byte)0x4D, (byte)0xA1, (byte)0xBC,
(byte)0x8E, (byte)0x4D, (byte)0xA1, (byte)0xBC,
推荐阅读
- javascript - 如何以凸面/外部方式使用边界收音机?
- lua - 错误:(类型 1):无法打开文件以读取 LaTeX 中的“ugmm8a.pfb”(字体已贬值)
- pandas - 当 column1 为 NaN 时合并两列
- constants - PHPUnit - 定义存储所有测试的函数结果的常量
- java - 为什么在定义复合键类时需要equals和hashcode?
- windows - 如何使用 intune 控制 Chrome 和 Edge 更新
- sql - SQL Server:使用字符串值时,DATEADD() 无法工作超过毫秒
- php - Laravel Collection 地图 - 无法将属性设置为 null 或 false
- sql-server - 如何使用 Linq 使用 LinqPad 过滤我的数据
- java - Spring Boot 自动生成带有属性的关联表