@@ -11,7 +11,7 @@ public class InsecureIVorNonceSource {
1111
1212 // BAD: AES-GCM with static IV from a byte array
1313 public byte [] encryptWithStaticIvByteArrayWithInitializer (byte [] key , byte [] plaintext ) throws Exception {
14- byte [] iv = new byte [] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 5 }; // $Source
14+ byte [] iv = new byte [] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 5 };
1515
1616 GCMParameterSpec ivSpec = new GCMParameterSpec (128 , iv );
1717 SecretKeySpec keySpec = new SecretKeySpec (key , "AES" );
@@ -24,20 +24,20 @@ public byte[] encryptWithStaticIvByteArrayWithInitializer(byte[] key, byte[] pla
2424
2525 // BAD: AES-GCM with static IV from zero-initialized byte array
2626 public byte [] encryptWithZeroStaticIvByteArray (byte [] key , byte [] plaintext ) throws Exception {
27- byte [] iv = new byte [16 ]; // $Source
27+ byte [] iv = new byte [16 ];
2828
2929 GCMParameterSpec ivSpec = new GCMParameterSpec (128 , iv );
3030 SecretKeySpec keySpec = new SecretKeySpec (key , "AES" );
3131
3232 Cipher cipher = Cipher .getInstance ("AES/GCM/PKCS5PADDING" );
33- cipher .init (Cipher .ENCRYPT_MODE , keySpec , ivSpec ); // $Alert[java/quantum/unknown-iv-or-nonce-initialization ]
33+ cipher .init (Cipher .ENCRYPT_MODE , keySpec , ivSpec ); // $Alert[java/quantum/unknown-iv-or-nonce-source ]
3434 cipher .update (plaintext );
3535 return cipher .doFinal ();
3636 }
3737
3838 // BAD: AES-CBC with static IV from 1-initialized byte array
3939 public byte [] encryptWithStaticIvByteArray (byte [] key , byte [] plaintext ) throws Exception {
40- byte [] iv = new byte [16 ]; // $Source
40+ byte [] iv = new byte [16 ];
4141 for (byte i = 0 ; i < iv .length ; i ++) {
4242 iv [i ] = 1 ;
4343 }
@@ -56,7 +56,7 @@ public byte[] encryptWithOneOfStaticIvs01(byte[] key, byte[] plaintext) throws E
5656 byte [][] staticIvs = new byte [][] {
5757 { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 5 },
5858 { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 42 }
59- }; // $Source
59+ };
6060
6161 GCMParameterSpec ivSpec = new GCMParameterSpec (128 , staticIvs [1 ]);
6262 SecretKeySpec keySpec = new SecretKeySpec (key , "AES" );
@@ -72,7 +72,7 @@ public byte[] encryptWithOneOfStaticIvs02(byte[] key, byte[] plaintext) throws E
7272 byte [][] staticIvs = new byte [][] {
7373 new byte [] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 5 },
7474 new byte [] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 , 2 , 3 , 4 , 42 }
75- }; // $Source
75+ };
7676
7777 GCMParameterSpec ivSpec = new GCMParameterSpec (128 , staticIvs [1 ]);
7878 SecretKeySpec keySpec = new SecretKeySpec (key , "AES" );
@@ -86,15 +86,15 @@ public byte[] encryptWithOneOfStaticIvs02(byte[] key, byte[] plaintext) throws E
8686 // BAD: AES-GCM with static IV from a zero-initialized multidimensional byte array
8787 public byte [] encryptWithOneOfStaticZeroIvs (byte [] key , byte [] plaintext ) throws Exception {
8888 byte [][] ivs = new byte [][] {
89- new byte [8 ], // $Source
90- new byte [16 ] // $Source
89+ new byte [8 ],
90+ new byte [16 ]
9191 };
9292
9393 GCMParameterSpec ivSpec = new GCMParameterSpec (128 , ivs [1 ]);
9494 SecretKeySpec keySpec = new SecretKeySpec (key , "AES" );
9595
9696 Cipher cipher = Cipher .getInstance ("AES/GCM/PKCS5PADDING" );
97- cipher .init (Cipher .ENCRYPT_MODE , keySpec , ivSpec ); // $Alert[java/quantum/unknown-iv-or-nonce-initialization ]
97+ cipher .init (Cipher .ENCRYPT_MODE , keySpec , ivSpec ); // $Alert[java/quantum/unknown-iv-or-nonce-source ]
9898 cipher .update (plaintext );
9999 return cipher .doFinal ();
100100 }
@@ -191,7 +191,7 @@ public byte[] encryptWithGeneratedIvByteArray(byte[] key, byte[] plaintext) thro
191191 public byte [] generateInsecureRandomBytes (int numBytes ) {
192192 Random random = new Random ();
193193 byte [] bytes = new byte [numBytes ];
194- random .nextBytes (bytes ); // $Source
194+ random .nextBytes (bytes );
195195 return bytes ;
196196 }
197197
0 commit comments