|
23 | 23 | import org.mockito.Mockito;
|
24 | 24 |
|
25 | 25 | /**
|
26 |
| - * Official RFC 5297 test vector taken from https://tools.ietf.org/html/rfc5297#appendix-A.1 |
| 26 | + * Official RFC 5297 test vector taken from https://tools.ietf.org/html/rfc5297#appendix-A.1 and https://tools.ietf.org/html/rfc5297#appendix-A.2 |
27 | 27 | */
|
28 | 28 | public class SivModeTest {
|
29 | 29 |
|
@@ -121,6 +121,58 @@ public void testDecryptAssociatedDataLimit() throws UnauthenticCiphertextExcepti
|
121 | 121 | new SivMode().decrypt(ctrKey, macKey, plaintext, new byte[127][0]);
|
122 | 122 | }
|
123 | 123 |
|
| 124 | + // CTR-AES https://tools.ietf.org/html/rfc5297#appendix-A.1 |
| 125 | + @Test |
| 126 | + public void testGenerateKeyStream1() { |
| 127 | + final byte[] ctrKey = {(byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, // |
| 128 | + (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, // |
| 129 | + (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, // |
| 130 | + (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff}; |
| 131 | + |
| 132 | + final byte[] ctr = {(byte) 0x85, (byte) 0x63, (byte) 0x2d, (byte) 0x07, // |
| 133 | + (byte) 0xc6, (byte) 0xe8, (byte) 0xf3, (byte) 0x7f, // |
| 134 | + (byte) 0x15, (byte) 0x0a, (byte) 0xcd, (byte) 0x32, // |
| 135 | + (byte) 0x0a, (byte) 0x2e, (byte) 0xcc, (byte) 0x93}; |
| 136 | + |
| 137 | + final byte[] expected = {(byte) 0x51, (byte) 0xe2, (byte) 0x18, (byte) 0xd2, // |
| 138 | + (byte) 0xc5, (byte) 0xa2, (byte) 0xab, (byte) 0x8c, // |
| 139 | + (byte) 0x43, (byte) 0x45, (byte) 0xc4, (byte) 0xa6, // |
| 140 | + (byte) 0x23, (byte) 0xb2, (byte) 0xf0, (byte) 0x8f}; |
| 141 | + |
| 142 | + final byte[] result = new SivMode().generateKeyStream(ctrKey, ctr, 1); |
| 143 | + Assert.assertArrayEquals(expected, result); |
| 144 | + } |
| 145 | + |
| 146 | + // CTR-AES https://tools.ietf.org/html/rfc5297#appendix-A.2 |
| 147 | + @Test |
| 148 | + public void testGenerateKeyStream2() { |
| 149 | + final byte[] ctrKey = {(byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, // |
| 150 | + (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, // |
| 151 | + (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, // |
| 152 | + (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f}; |
| 153 | + |
| 154 | + final byte[] ctr = {(byte) 0x7b, (byte) 0xdb, (byte) 0x6e, (byte) 0x3b, // |
| 155 | + (byte) 0x43, (byte) 0x26, (byte) 0x67, (byte) 0xeb, // |
| 156 | + (byte) 06, (byte) 0xf4, (byte) 0xd1, (byte) 0x4b, // |
| 157 | + (byte) 0x7f, (byte) 0x2f, (byte) 0xbd, (byte) 0x0f}; |
| 158 | + |
| 159 | + final byte[] expected = {(byte) 0xbf, (byte) 0xf8, (byte) 0x66, (byte) 0x5c, // |
| 160 | + (byte) 0xfd, (byte) 0xd7, (byte) 0x33, (byte) 0x63, // |
| 161 | + (byte) 0x55, (byte) 0x0f, (byte) 0x74, (byte) 0x00, // |
| 162 | + (byte) 0xe8, (byte) 0xf9, (byte) 0xd3, (byte) 0x76, // |
| 163 | + (byte) 0xb2, (byte) 0xc9, (byte) 0x08, (byte) 0x8e, // |
| 164 | + (byte) 0x71, (byte) 0x3b, (byte) 0x86, (byte) 0x17, // |
| 165 | + (byte) 0xd8, (byte) 0x83, (byte) 0x92, (byte) 0x26, // |
| 166 | + (byte) 0xd9, (byte) 0xf8, (byte) 0x81, (byte) 0x59, // |
| 167 | + (byte) 0x9e, (byte) 0x44, (byte) 0xd8, (byte) 0x27, // |
| 168 | + (byte) 0x23, (byte) 0x49, (byte) 0x49, (byte) 0xbc, // |
| 169 | + (byte) 0x1b, (byte) 0x12, (byte) 0x34, (byte) 0x8e, // |
| 170 | + (byte) 0xbc, (byte) 0x19, (byte) 0x5e, (byte) 0xc7}; |
| 171 | + |
| 172 | + final byte[] result = new SivMode().generateKeyStream(ctrKey, ctr, 3); |
| 173 | + Assert.assertArrayEquals(expected, result); |
| 174 | + } |
| 175 | + |
124 | 176 | @Test
|
125 | 177 | public void testS2v() {
|
126 | 178 | final byte[] macKey = {(byte) 0xff, (byte) 0xfe, (byte) 0xfd, (byte) 0xfc, //
|
|
0 commit comments