@@ -143,6 +143,56 @@ public void testEncryptDecryptWithEmptyPlaintextAndEmptyAssociatedData()
143
143
}
144
144
}
145
145
146
+ @ Test
147
+ public void testEncryptDecryptWithNullAssociatedData () throws GeneralSecurityException {
148
+ for (int keySize : keySizeInBytes ) {
149
+ DeterministicAead dead = new AesSiv (Random .randBytes (keySize ));
150
+ for (int triesPlaintext = 0 ; triesPlaintext < 100 ; triesPlaintext ++) {
151
+ byte [] plaintext = Random .randBytes (Random .randInt (1024 ) + 1 );
152
+ byte [] rebuiltPlaintext =
153
+ dead .decryptDeterministically (dead .encryptDeterministically (plaintext , null ), null );
154
+ assertEquals (Hex .encode (plaintext ), Hex .encode (rebuiltPlaintext ));
155
+ }
156
+ }
157
+ }
158
+
159
+ @ Test
160
+ public void testEncryptDecryptWithNullAndEmptyAssociatedDataEquivalent ()
161
+ throws GeneralSecurityException {
162
+ for (int keySize : keySizeInBytes ) {
163
+ DeterministicAead dead = new AesSiv (Random .randBytes (keySize ));
164
+ for (int triesPlaintext = 0 ; triesPlaintext < 100 ; triesPlaintext ++) {
165
+ byte [] plaintext = Random .randBytes (Random .randInt (1024 ) + 1 );
166
+ byte [] emptyAad = new byte [0 ];
167
+ byte [] emptyAadCiphertext = dead .encryptDeterministically (plaintext , emptyAad );
168
+ byte [] emptyAadRebuiltPlaintext =
169
+ dead .decryptDeterministically (emptyAadCiphertext , emptyAad );
170
+
171
+ byte [] nullAadCipherText = dead .encryptDeterministically (plaintext , null );
172
+ byte [] nullAadRebuiltPlaintext =
173
+ dead .decryptDeterministically (nullAadCipherText , null );
174
+
175
+ assertEquals (Hex .encode (plaintext ), Hex .encode (emptyAadRebuiltPlaintext ));
176
+ assertEquals (Hex .encode (plaintext ), Hex .encode (nullAadRebuiltPlaintext ));
177
+ assertEquals (Hex .encode (emptyAadCiphertext ), Hex .encode (nullAadCipherText ));
178
+ }
179
+ }
180
+ }
181
+
182
+ @ Test
183
+ public void testEncryptDecryptWithEmptyPlaintextAndNullAssociatedData ()
184
+ throws GeneralSecurityException {
185
+ for (int keySize : keySizeInBytes ) {
186
+ DeterministicAead dead = new AesSiv (Random .randBytes (keySize ));
187
+ for (int triesPlaintext = 0 ; triesPlaintext < 100 ; triesPlaintext ++) {
188
+ byte [] plaintext = new byte [0 ];
189
+ byte [] rebuiltPlaintext =
190
+ dead .decryptDeterministically (dead .encryptDeterministically (plaintext , null ), null );
191
+ assertEquals (Hex .encode (plaintext ), Hex .encode (rebuiltPlaintext ));
192
+ }
193
+ }
194
+ }
195
+
146
196
@ Test
147
197
public void testEncryptDecrypt () throws GeneralSecurityException {
148
198
for (int keySize : keySizeInBytes ) {
0 commit comments