55import java .nio .charset .StandardCharsets ;
66import java .security .KeyPair ;
77import java .security .KeyPairGenerator ;
8+ import java .security .PEMEncoder ;
89import java .security .Security ;
910import java .security .Signature ;
1011import java .util .Base64 ;
1112
1213public class SignatureTest {
1314
14- public static final String OUTPUT = "%-15s %-12s %-12s %-10s %n" ;
15+ public static final String OUTPUT = "%-15s %-12s %-12s %-12s %-12s %n" ;
1516
1617 static void main (String [] args ) throws Exception {
1718 Security .addProvider (new BouncyCastleProvider ());
1819
1920 String payload = new String (SignatureTest .class .getClassLoader ().getResourceAsStream ("payload" ).readAllBytes (), StandardCharsets .UTF_8 );
20- int count = 10 ;
21+ int countFast = 100 ;
22+ int countSlow = 10 ;
2123
22- System .out .printf (OUTPUT , "Algorithm" , "Size" , "Size (url)" , "Time (ms)" );
24+ System .out .printf (OUTPUT , "Algorithm" , "Size" , "Size (url)" , "Key Size" , " Time (ms)" );
2325 for (SignatureAlgorithms a : SignatureAlgorithms .values ()) {
2426 KeyPairGenerator keyPairGenerator = a .getProvider () != null ? KeyPairGenerator .getInstance (a .getKeyPairAlgorithm (), a .getProvider ()) : KeyPairGenerator .getInstance (a .getKeyPairAlgorithm ());
2527 keyPairGenerator .initialize (a .getSpec ());
2628 KeyPair keyPair = keyPairGenerator .generateKeyPair ();
2729
2830 byte [] signedBytes = new byte [0 ];
2931 long start = System .currentTimeMillis ();
32+
33+ int count = a .getName ().startsWith ("SLH_DSA" ) ? countSlow : countFast ;
3034 for (int i = 0 ; i <= count ; i ++) {
3135 Signature signature = a .getProvider () != null ? Signature .getInstance (a .getAlgorithm (), a .getProvider ()) : Signature .getInstance (a .getAlgorithm ());
3236 signature .initSign (keyPair .getPrivate ());
@@ -37,8 +41,11 @@ static void main(String[] args) throws Exception {
3741 long time = System .currentTimeMillis () - start ;
3842 String signatureEncoded = Base64 .getUrlEncoder ().encodeToString (signedBytes );
3943
40- System .out .printf (OUTPUT , a .getName (), signedBytes .length , signatureEncoded .length (), (double ) time / count );
44+ byte [] publicKeyEncoded = PEMEncoder .of ().encode (keyPair .getPublic ());
45+
46+ System .out .printf (OUTPUT , a .getName (), signedBytes .length , signatureEncoded .length (), publicKeyEncoded .length , (double ) time / count );
4147 }
48+
4249 }
4350
4451
0 commit comments