44import static org .junit .jupiter .api .Assertions .assertEquals ;
55import static org .junit .jupiter .api .Assertions .assertThrows ;
66
7- import java .util .Arrays ; // Added import
7+ import java .util .Arrays ;
88import org .junit .jupiter .api .Test ;
99
1010public class ChaCha20Test {
1111
1212 // Test vector from RFC 8439, Section 2.4.2.
1313 private static final byte [] RFC8439_KEY = hexStringToByteArray ("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" );
1414 private static final byte [] RFC8439_NONCE = hexStringToByteArray ("000000000000004a00000000" ); // Counter = 1, Nonce = 00000000 0000004a 00000000
15- private static final byte [] RFC8439_PLAINTEXT_64 = hexStringToByteArray ("4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a20" + "4966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f722074686520" + "6675747572652c2073756e73637265656e20776f756c642062652069742e" );
16- private static final byte [] RFC8439_CIPHERTEXT_64 = hexStringToByteArray ("6e2e359a2568f98041ba0728dd0d6981e97e7aec1d4360c20a27afccfd9fae0bf91b65c5524733ab8f583" + "75fcd4af034bd16adec164f7a2bda3dc0343a99a46c8b4172421b505877c570b1351d530635359a37e5f1" + "797b596a78c149d5d9963e696f8c792374c4314c67d163f97205463f668f438a0c20a3a7187" );
15+ private static final byte [] RFC8439_PLAINTEXT_64 = hexStringToByteArray ("4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a20"
16+ + "4966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f722074686520"
17+ + "6675747572652c2073756e73637265656e20776f756c642062652069742e" );
18+ private static final byte [] RFC8439_CIPHERTEXT_64 = hexStringToByteArray ("6e2e359a2568f98041ba0728dd0d6981e97e7aec1d4360c20a27afccfd9fae0bf91b65c5524733ab8f583"
19+ + "75fcd4af034bd16adec164f7a2bda3dc0343a99a46c8b4172421b505877c570b1351d530635359a37e5f1"
20+ + "797b596a78c149d5d9963e696f8c792374c4314c67d163f97205463f668f438a0c20a3a7187" );
1721
1822 // Test vector from RFC 8439, Section 2.4.2 for 114 bytes
1923 private static final byte [] RFC8439_PLAINTEXT_114 = Arrays .copyOf (RFC8439_PLAINTEXT_64 , 114 );
@@ -109,7 +113,7 @@ public void testNullInputs() {
109113 assertThrows (IllegalArgumentException .class , () -> ChaCha20 .encrypt (null , nonce , data ));
110114 assertThrows (IllegalArgumentException .class , () -> ChaCha20 .encrypt (key , null , data ));
111115 assertThrows (IllegalArgumentException .class , () -> ChaCha20 .encrypt (key , nonce , null ));
112- assertThrows (IllegalArgumentException .class , () -> ChaCha20 .decrypt (null , nonce , data ));
116+ assertThrows (IllegalArgumentException .class , () -> Cha - Cha20 .decrypt (null , nonce , data ));
113117 assertThrows (IllegalArgumentException .class , () -> ChaCha20 .decrypt (key , null , data ));
114118 assertThrows (IllegalArgumentException .class , () -> ChaCha20 .decrypt (key , nonce , null ));
115119 }
@@ -127,4 +131,3 @@ private static byte[] hexStringToByteArray(String s) {
127131 return data ;
128132 }
129133}
130-
0 commit comments