11
11
import java .io .IOException ;
12
12
import java .security .InvalidKeyException ;
13
13
14
- import javax .crypto .AEADBadTagException ;
15
14
import javax .crypto .IllegalBlockSizeException ;
16
15
import javax .crypto .SecretKey ;
17
16
import javax .crypto .spec .SecretKeySpec ;
@@ -76,7 +75,7 @@ public BlockCipher create() {
76
75
}
77
76
78
77
@ Test (expected = IllegalArgumentException .class )
79
- public void testDecryptWithInvalidKey1 () throws AEADBadTagException , IllegalBlockSizeException {
78
+ public void testDecryptWithInvalidKey1 () throws UnauthenticCiphertextException , IllegalBlockSizeException {
80
79
SecretKey key1 = Mockito .mock (SecretKey .class );
81
80
Mockito .when (key1 .getEncoded ()).thenReturn (null );
82
81
SecretKey key2 = Mockito .mock (SecretKey .class );
@@ -86,7 +85,7 @@ public void testDecryptWithInvalidKey1() throws AEADBadTagException, IllegalBloc
86
85
}
87
86
88
87
@ Test (expected = IllegalArgumentException .class )
89
- public void testDecryptWithInvalidKey2 () throws AEADBadTagException , IllegalBlockSizeException {
88
+ public void testDecryptWithInvalidKey2 () throws UnauthenticCiphertextException , IllegalBlockSizeException {
90
89
SecretKey key1 = Mockito .mock (SecretKey .class );
91
90
Mockito .when (key1 .getEncoded ()).thenReturn (new byte [16 ]);
92
91
SecretKey key2 = Mockito .mock (SecretKey .class );
@@ -96,7 +95,7 @@ public void testDecryptWithInvalidKey2() throws AEADBadTagException, IllegalBloc
96
95
}
97
96
98
97
@ Test (expected = IllegalBlockSizeException .class )
99
- public void testDecryptWithInvalidBlockSize () throws AEADBadTagException , IllegalBlockSizeException {
98
+ public void testDecryptWithInvalidBlockSize () throws UnauthenticCiphertextException , IllegalBlockSizeException {
100
99
final byte [] dummyKey = new byte [16 ];
101
100
final SecretKey ctrKey = new SecretKeySpec (dummyKey , "AES" );
102
101
final SecretKey macKey = new SecretKeySpec (dummyKey , "AES" );
@@ -114,7 +113,7 @@ public void testEncryptAssociatedDataLimit() {
114
113
}
115
114
116
115
@ Test (expected = IllegalArgumentException .class )
117
- public void testDecryptAssociatedDataLimit () throws AEADBadTagException , IllegalBlockSizeException {
116
+ public void testDecryptAssociatedDataLimit () throws UnauthenticCiphertextException , IllegalBlockSizeException {
118
117
final byte [] ctrKey = new byte [16 ];
119
118
final byte [] macKey = new byte [16 ];
120
119
final byte [] plaintext = new byte [80 ];
@@ -188,7 +187,7 @@ public void testSivEncrypt() {
188
187
}
189
188
190
189
@ Test
191
- public void testSivDecrypt () throws AEADBadTagException , IllegalBlockSizeException {
190
+ public void testSivDecrypt () throws UnauthenticCiphertextException , IllegalBlockSizeException {
192
191
final byte [] macKey = {(byte ) 0xff , (byte ) 0xfe , (byte ) 0xfd , (byte ) 0xfc , //
193
192
(byte ) 0xfb , (byte ) 0xfa , (byte ) 0xf9 , (byte ) 0xf8 , //
194
193
(byte ) 0xf7 , (byte ) 0xf6 , (byte ) 0xf5 , (byte ) 0xf4 , //
@@ -224,8 +223,8 @@ public void testSivDecrypt() throws AEADBadTagException, IllegalBlockSizeExcepti
224
223
Assert .assertArrayEquals (expected , result );
225
224
}
226
225
227
- @ Test (expected = AEADBadTagException .class )
228
- public void testSivDecryptWithInvalidKey () throws AEADBadTagException , IllegalBlockSizeException {
226
+ @ Test (expected = UnauthenticCiphertextException .class )
227
+ public void testSivDecryptWithInvalidKey () throws UnauthenticCiphertextException , IllegalBlockSizeException {
229
228
final byte [] macKey = {(byte ) 0xff , (byte ) 0xfe , (byte ) 0xfd , (byte ) 0xfc , //
230
229
(byte ) 0xfb , (byte ) 0xfa , (byte ) 0xf9 , (byte ) 0xf8 , //
231
230
(byte ) 0xf7 , (byte ) 0xf6 , (byte ) 0xf5 , (byte ) 0xf4 , //
@@ -256,7 +255,7 @@ public void testSivDecryptWithInvalidKey() throws AEADBadTagException, IllegalBl
256
255
}
257
256
258
257
@ Test (expected = IllegalBlockSizeException .class )
259
- public void testSivDecryptWithInvalidCiphertext () throws AEADBadTagException , IllegalBlockSizeException {
258
+ public void testSivDecryptWithInvalidCiphertext () throws UnauthenticCiphertextException , IllegalBlockSizeException {
260
259
final byte [] macKey = {(byte ) 0xff , (byte ) 0xfe , (byte ) 0xfd , (byte ) 0xfc , //
261
260
(byte ) 0xfb , (byte ) 0xfa , (byte ) 0xf9 , (byte ) 0xf8 , //
262
261
(byte ) 0xf7 , (byte ) 0xf6 , (byte ) 0xf5 , (byte ) 0xf4 , //
@@ -346,7 +345,7 @@ public void testNonceBasedAuthenticatedEncryption() throws InvalidKeyException {
346
345
}
347
346
348
347
@ Test
349
- public void testEncryptionAndDecryptionUsingJavaxCryptoApi () throws AEADBadTagException , IllegalBlockSizeException {
348
+ public void testEncryptionAndDecryptionUsingJavaxCryptoApi () throws UnauthenticCiphertextException , IllegalBlockSizeException {
350
349
final byte [] dummyKey = new byte [16 ];
351
350
final SecretKey ctrKey = new SecretKeySpec (dummyKey , "AES" );
352
351
final SecretKey macKey = new SecretKeySpec (dummyKey , "AES" );
@@ -423,7 +422,7 @@ public void testXorend() {
423
422
}
424
423
425
424
@ Test
426
- public void testGeneratedTestCases () throws IOException , AEADBadTagException , IllegalBlockSizeException {
425
+ public void testGeneratedTestCases () throws IOException , UnauthenticCiphertextException , IllegalBlockSizeException {
427
426
final EncryptionTestCase [] allTestCases = EncryptionTestCase .readTestCases ();
428
427
429
428
// Check that decryption fails if the wrong MAC key is used
@@ -440,7 +439,7 @@ public void testGeneratedTestCases() throws IOException, AEADBadTagException, Il
440
439
try {
441
440
new SivMode ().decrypt (testCase .getCtrKey (), macKey , testCase .getCiphertext (), testCase .getAssociatedData ());
442
441
Assert .fail ();
443
- } catch (AEADBadTagException ex ) {
442
+ } catch (UnauthenticCiphertextException ex ) {
444
443
// Test case passed.
445
444
}
446
445
}
@@ -460,7 +459,7 @@ public void testGeneratedTestCases() throws IOException, AEADBadTagException, Il
460
459
try {
461
460
new SivMode ().decrypt (testCase .getCtrKey (), testCase .getMacKey (), ciphertext , testCase .getAssociatedData ());
462
461
Assert .fail ();
463
- } catch (AEADBadTagException ex ) {
462
+ } catch (UnauthenticCiphertextException ex ) {
464
463
// Test case passed.
465
464
}
466
465
}
@@ -486,7 +485,7 @@ public void testGeneratedTestCases() throws IOException, AEADBadTagException, Il
486
485
try {
487
486
new SivMode ().decrypt (testCase .getCtrKey (), testCase .getMacKey (), testCase .getCiphertext (), ad );
488
487
Assert .fail ();
489
- } catch (AEADBadTagException ex ) {
488
+ } catch (UnauthenticCiphertextException ex ) {
490
489
// Test case passed.
491
490
}
492
491
@@ -503,7 +502,7 @@ public void testGeneratedTestCases() throws IOException, AEADBadTagException, Il
503
502
try {
504
503
new SivMode ().decrypt (testCase .getCtrKey (), testCase .getMacKey (), testCase .getCiphertext (), prependedAd );
505
504
Assert .fail ();
506
- } catch (AEADBadTagException ex ) {
505
+ } catch (UnauthenticCiphertextException ex ) {
507
506
// Test case passed.
508
507
}
509
508
@@ -514,7 +513,7 @@ public void testGeneratedTestCases() throws IOException, AEADBadTagException, Il
514
513
try {
515
514
new SivMode ().decrypt (testCase .getCtrKey (), testCase .getMacKey (), testCase .getCiphertext (), appendedAd );
516
515
Assert .fail ();
517
- } catch (AEADBadTagException ex ) {
516
+ } catch (UnauthenticCiphertextException ex ) {
518
517
// Test case passed.
519
518
}
520
519
}
0 commit comments