@Test public void dblTestVectors() { String[] testVectorInputs = { "0e04dfafc1efbf040140582859bf073a", "edf09de876c642ee4d78bce4ceedfc4f", "c8b43b5974960e7ce6a5dd85231e591a", "adf31e285d3d1e1d4ddefc1e5bec63e9", "826aa75b5e568eed3125bfb266c61d4e", }; String[] testVectorOutputs = { "1c09bf5f83df7e080280b050b37e0e74", "dbe13bd0ed8c85dc9af179c99ddbf819", "916876b2e92c1cf9cd4bbb0a463cb2b3", "5be63c50ba7a3c3a9bbdf83cb7d8c755", "04d54eb6bcad1dda624b7f64cd8c3a1b", }; byte[] r; for (int i = 0; i < testVectorInputs.length; i++) { r = AesUtil.dbl(Hex.decode(testVectorInputs[i])); assertEquals(testVectorOutputs[i], Hex.encode(r)); } }
static byte[] dbl(final byte[] value) { if (value.length != BLOCK_SIZE) { throw new IllegalArgumentException("value must be a block."); } byte[] res = new byte[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = (byte) (0xFE & (value[i] << 1)); if (i < BLOCK_SIZE - 1) { res[i] |= (byte) (0x01 & (value[i + 1] >> 7)); } } res[BLOCK_SIZE - 1] ^= (byte) (0x87 & (value[0] >> 7)); return res; }
AesUtil { static byte[] dbl(final byte[] value) { if (value.length != BLOCK_SIZE) { throw new IllegalArgumentException("value must be a block."); } byte[] res = new byte[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = (byte) (0xFE & (value[i] << 1)); if (i < BLOCK_SIZE - 1) { res[i] |= (byte) (0x01 & (value[i + 1] >> 7)); } } res[BLOCK_SIZE - 1] ^= (byte) (0x87 & (value[0] >> 7)); return res; } }
AesUtil { static byte[] dbl(final byte[] value) { if (value.length != BLOCK_SIZE) { throw new IllegalArgumentException("value must be a block."); } byte[] res = new byte[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = (byte) (0xFE & (value[i] << 1)); if (i < BLOCK_SIZE - 1) { res[i] |= (byte) (0x01 & (value[i + 1] >> 7)); } } res[BLOCK_SIZE - 1] ^= (byte) (0x87 & (value[0] >> 7)); return res; }  }
AesUtil { static byte[] dbl(final byte[] value) { if (value.length != BLOCK_SIZE) { throw new IllegalArgumentException("value must be a block."); } byte[] res = new byte[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = (byte) (0xFE & (value[i] << 1)); if (i < BLOCK_SIZE - 1) { res[i] |= (byte) (0x01 & (value[i + 1] >> 7)); } } res[BLOCK_SIZE - 1] ^= (byte) (0x87 & (value[0] >> 7)); return res; }   }
AesUtil { static byte[] dbl(final byte[] value) { if (value.length != BLOCK_SIZE) { throw new IllegalArgumentException("value must be a block."); } byte[] res = new byte[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = (byte) (0xFE & (value[i] << 1)); if (i < BLOCK_SIZE - 1) { res[i] |= (byte) (0x01 & (value[i + 1] >> 7)); } } res[BLOCK_SIZE - 1] ^= (byte) (0x87 & (value[0] >> 7)); return res; }   static final int BLOCK_SIZE; }