@@ -45,6 +45,7 @@ public String getName()
4545 public void performTest ()
4646 throws Exception
4747 {
48+ testVectorsAsconCXof128_512 ();
4849 DigestTest .checkXof (new AsconXof128 (), 1429 , 317 , new SecureRandom (), this );
4950 DigestTest .checkXof (new AsconCXof128 (), 1429 , 317 , new SecureRandom (), this );
5051 DigestTest .checkXof (new AsconXof (AsconXof .AsconParameters .AsconXof ), 1429 , 317 , new SecureRandom (), this );
@@ -520,6 +521,12 @@ public void testVectorsXof_AsconXof128()
520521 implTestVectorsXof (new AsconXof128 (), "crypto/ascon/asconxof128" , "LWC_HASH_KAT_256.txt" );
521522 }
522523
524+ public void testVectorsAsconCXof128_512 ()
525+ throws Exception
526+ {
527+ implTestVectorsAsconCXof128 (512 / 8 , "crypto/ascon/asconcxof128" , "LWC_CXOF_KAT_128_512.txt" );
528+ }
529+
523530 public void testVectorsXof_AsconXof ()
524531 throws Exception
525532 {
@@ -1172,6 +1179,54 @@ private void implTestVectorsEngine(AEADCipher ascon, String path, String filenam
11721179 }
11731180 }
11741181
1182+ private void implTestVectorsAsconCXof128 (int hash_length , String path , String filename )
1183+ throws Exception
1184+ {
1185+ Random random = new Random ();
1186+
1187+ InputStream src = TestResourceFinder .findTestResource (path , filename );
1188+ BufferedReader bin = new BufferedReader (new InputStreamReader (src ));
1189+ String line ;
1190+ HashMap <String , String > map = new HashMap <String , String >();
1191+ while ((line = bin .readLine ()) != null )
1192+ {
1193+ int a = line .indexOf ('=' );
1194+ if (a < 0 )
1195+ {
1196+ byte [] zByte = Hex .decode ((String )map .get ("Z" ));
1197+ byte [] ptByte = Hex .decode ((String )map .get ("Msg" ));
1198+ byte [] expected = Hex .decode ((String )map .get ("MD" ));
1199+
1200+ byte [] hash = new byte [hash_length ];
1201+
1202+ AsconCXof128 ascon = new AsconCXof128 (zByte );
1203+ ascon .update (ptByte , 0 , ptByte .length );
1204+ ascon .doFinal (hash , 0 , hash_length );
1205+ if (!areEqual (hash , expected ))
1206+ {
1207+ mismatch ("Keystream " + map .get ("Count" ), (String )map .get ("MD" ), hash );
1208+ }
1209+
1210+ if (ptByte .length > 1 )
1211+ {
1212+ int split = random .nextInt (ptByte .length - 1 ) + 1 ;
1213+ ascon = new AsconCXof128 (zByte );
1214+ ascon .update (ptByte , 0 , split );
1215+ ascon .update (ptByte , split , ptByte .length - split );
1216+ ascon .doFinal (hash , 0 , hash_length );
1217+ if (!areEqual (hash , expected ))
1218+ {
1219+ mismatch ("Keystream " + map .get ("Count" ), (String )map .get ("MD" ), hash );
1220+ }
1221+ }
1222+ }
1223+ else
1224+ {
1225+ map .put (line .substring (0 , a ).trim (), line .substring (a + 1 ).trim ());
1226+ }
1227+ }
1228+ }
1229+
11751230 private void implTestVectorsXof (Xof ascon , String path , String filename )
11761231 throws Exception
11771232 {
0 commit comments