diff --git a/examples/provider/CryptoBenchmark.java b/examples/provider/CryptoBenchmark.java index 44acfe4..b4fc884 100644 --- a/examples/provider/CryptoBenchmark.java +++ b/examples/provider/CryptoBenchmark.java @@ -36,10 +36,10 @@ public class CryptoBenchmark { private static final int DES3_BLOCK_SIZE = 8; private static final int GCM_TAG_LENGTH = 128; private static final int[] RSA_KEY_SIZES = {2048, 3072, 4096}; - private static final int TEST_MIN_TIME_SECONDS = 1; /* minimum time to run each test */ - private static final int SMALL_MESSAGE_SIZE = 32; /* small message size for RSA ops */ - private static final String[] ECC_CURVES = {"secp256r1"}; /* Can add more curves benchmark.c only uses secp256r1 */ - private static final int[] DH_KEY_SIZES = {2048}; /* Can add more key sizes benchmark.c only uses 2048 */ + private static final int TEST_MIN_TIME_SECONDS = 1; + private static final int SMALL_MESSAGE_SIZE = 32; + private static final String[] ECC_CURVES = {"secp256r1"}; + private static final int[] DH_KEY_SIZES = {2048}; private static final String DH_ALGORITHM = "DiffieHellman"; /* Class to store benchmark results */ @@ -51,9 +51,9 @@ public class CryptoBenchmark { /* Constructor */ BenchmarkResult(String provider, String operation, double throughput) { - this.provider = provider; - this.operation = operation; - this.throughput = throughput; + this.provider = provider; + this.operation = operation; + this.throughput = throughput; } } @@ -68,7 +68,8 @@ public class CryptoBenchmark { } } - /* Generic benchmark runner that executes an operation repeatedly for a minimum time */ + /* Benchmark runner that executes an operation repeatedly + * for a minimum time */ private static TimingResult runBenchmark(Runnable operation) { int ops = 0; long startTime = System.nanoTime(); @@ -87,14 +88,15 @@ public class CryptoBenchmark { } /* Generic function to print benchmark results with operations per second */ - private static void printBenchmarkResults(int operations, double totalTime, String operation, - String providerName, String mode) { + private static void printBenchmarkResults(int operations, double totalTime, + String operation, String providerName, String mode) { /* Variables for result calculations */ double avgTimeMs = (totalTime * 1000.0) / operations; double opsPerSec = operations / totalTime; /* Print formatted results */ - System.out.printf("%-12s %-8s %8d ops took %.3f sec, avg %.3f ms, %.3f ops/sec%n", + System.out.printf( + "%-12s %-8s %8d ops took %.3f sec, avg %.3f ms, %.3f ops/sec%n", operation + " (" + mode + ")", " ", operations, @@ -103,7 +105,8 @@ public class CryptoBenchmark { opsPerSec); /* Store results for delta table */ - results.add(new BenchmarkResult(providerName, operation + " (" + mode + ")", opsPerSec)); + results.add(new BenchmarkResult(providerName, operation + + " (" + mode + ")", opsPerSec)); } /* List to store all benchmark results */ @@ -135,7 +138,6 @@ public class CryptoBenchmark { return new byte[size]; } - /* Bytes sizes from WC_*_DIGEST_SIZE for corresponding algorithm in text.c */ private static int getHmacKeySize(String algorithm) { switch (algorithm) { case "HmacMD5": @@ -164,16 +166,19 @@ public class CryptoBenchmark { if (algorithm.contains("384")) return 48; if (algorithm.contains("512")) return 64; if (algorithm.contains("MD5")) return 16; - if (algorithm.contains("SHA1") || algorithm.contains("SHA-1")) return 20; + if (algorithm.contains("SHA1") || + algorithm.contains("SHA-1")) return 20; - System.out.println("Warning: Unknown HMAC algorithm " + algorithm + ", using default key size 32"); + System.out.println("Warning: Unknown HMAC algorithm " + + algorithm + ", using default key size 32"); return 32; } } @SuppressWarnings("deprecation") private static void printProviderInfo(Provider provider) { - System.out.printf("%s version: %s%n", provider.getName(), provider.getVersion()); + System.out.printf("%s version: %s%n", provider.getName(), + provider.getVersion()); } private static void setupProvidersForTest(Provider testProvider) { @@ -186,18 +191,20 @@ public class CryptoBenchmark { /* Add test provider at priority 1 */ Security.insertProviderAt(testProvider, 1); - /* For SunJCE tests, SunEC is typically already available in modern Java versions */ if (testProvider.getName().equals("SunJCE")) { /* SunEC should already be registered in Java 9+ */ if (Security.getProvider("SunEC") == null) { - System.out.println("Note: SunEC provider not available, some ECC operations may not work"); + System.out.println( + "Note: SunEC provider not available," + + " some ECC operations may not work"); } } } private static void setupDigestProvider(String testProviderName) { /* For digest operations, we need special handling */ - if (testProviderName.equals("wolfJCE") || testProviderName.equals("BC")) { + if (testProviderName.equals("wolfJCE") || + testProviderName.equals("BC")) { /* wolfJCE and BC can handle their own digests */ return; } else { @@ -205,12 +212,14 @@ public class CryptoBenchmark { Provider sunProvider = Security.getProvider("SUN"); if (sunProvider == null) { /* SUN provider should be built-in, but let's be safe */ - System.out.println("SUN provider not found for MessageDigest operations"); + System.out.println( + "SUN provider not found for MessageDigest operations"); } } } - private static KeyPairGenerator initializeKeyGenerator(String keyType, String keyGenProvider) throws Exception { + private static KeyPairGenerator initializeKeyGenerator(String keyType, + String keyGenProvider) throws Exception { KeyPairGenerator keyGen; if (keyType.equals("EC") && keyGenProvider.equals("SunEC")) { @@ -233,15 +242,18 @@ public class CryptoBenchmark { } /* Universal method to get algorithms for a specific provider and service type */ - private static Set getAlgorithmsForProvider(String providerName, String serviceType, Set wolfJCEAlgorithms) { + private static Set getAlgorithmsForProvider(String providerName, + String serviceType, Set wolfJCEAlgorithms) { Set algorithms = new TreeSet<>(); if (providerName.equals("SunJCE") && serviceType.equals("Signature")) { - algorithms.addAll(getAlgorithmsForService("SunRsaSign", serviceType)); + algorithms.addAll(getAlgorithmsForService("SunRsaSign", + serviceType)); algorithms.addAll(getAlgorithmsForService("SunEC", serviceType)); algorithms.addAll(getAlgorithmsForService("SUN", serviceType)); } else { - algorithms.addAll(getAlgorithmsForService(providerName, serviceType)); + algorithms.addAll(getAlgorithmsForService(providerName, + serviceType)); } if (providerName.equals("BC")) { @@ -252,7 +264,8 @@ public class CryptoBenchmark { if (wolfJCEAlgorithms.contains(normalized)) { normalizedAlgorithms.add(algorithm); } - } else if (serviceType.equals("Mac") || serviceType.equals("KeyGenerator")) { + } else if (serviceType.equals("Mac") || + serviceType.equals("KeyGenerator")) { String normalized = algorithm; if (wolfJCEAlgorithms.contains(normalized)) { @@ -288,14 +301,18 @@ public class CryptoBenchmark { } /* Get the baseline algorithms that wolfJCE supports for comparison */ - private static Set getWolfJCEAlgorithmsForService(String serviceType) { + private static Set getWolfJCEAlgorithmsForService( + String serviceType) { return getAlgorithmsForService("wolfJCE", serviceType); } /* Debug method to see what algorithms each provider actually supports */ - private static void debugPrintAlgorithms(String providerName, String serviceType) { - System.out.println("Debug: " + providerName + " " + serviceType + " algorithms:"); - Set algorithms = getAlgorithmsForService(providerName, serviceType); + private static void debugPrintAlgorithms(String providerName, + String serviceType) { + System.out.println("Debug: " + providerName + " " + + serviceType + " algorithms:"); + Set algorithms = + getAlgorithmsForService(providerName, serviceType); for (String alg : algorithms) { System.out.println(" " + alg); } @@ -303,7 +320,8 @@ public class CryptoBenchmark { } /* Universal method to get algorithms for a specific provider and service type */ - private static Set getAlgorithmsForService(String providerName, String serviceType) { + private static Set getAlgorithmsForService(String providerName, + String serviceType) { Set algorithms = new TreeSet<>(); Provider provider = Security.getProvider(providerName); @@ -317,7 +335,8 @@ public class CryptoBenchmark { String algorithm = service.getAlgorithm(); if (serviceType.equals("Mac")) { - if (algorithm.startsWith("Hmac") || algorithm.startsWith("HMAC")) { + if (algorithm.startsWith("Hmac") || + algorithm.startsWith("HMAC")) { algorithms.add(algorithm); } } else { @@ -340,10 +359,18 @@ public class CryptoBenchmark { double deltaPercent; System.out.println("\nPerformance Delta (compared to wolfJCE)"); - System.out.println("--------------------------------------------------------------------------------------"); - System.out.println("| Operation | Provider | Delta | Delta |"); - System.out.println("| | | Value* | (%) |"); - System.out.println("|----------------------------------------------|--------------|-------------|----------|"); + System.out.println( + "----------------------------------------------------------------" + + "----------------------"); + System.out.println( + "| Operation " + + " | Provider | Delta | Delta |"); + System.out.println( + "| " + + " | | Value* | (%) |"); + System.out.println( + "|-------------------------------" + + "---------------|--------------|-------------|----------|"); /* Group results by operation */ groupedResults = new HashMap<>(); @@ -354,7 +381,8 @@ public class CryptoBenchmark { } /* Sort operations by category and name for better grouping */ - List sortedOperations = new ArrayList<>(groupedResults.keySet()); + List sortedOperations = + new ArrayList<>(groupedResults.keySet()); Collections.sort(sortedOperations, (a, b) -> { String categoryA = getOperationCategory(a); String categoryB = getOperationCategory(b); @@ -374,7 +402,8 @@ public class CryptoBenchmark { if (wolfSpeed == 0.0) continue; - for (Map.Entry providerEntry : providerResults.entrySet()) { + for (Map.Entry providerEntry : + providerResults.entrySet()) { provider = providerEntry.getKey(); if (!provider.equals("wolfJCE")) { otherSpeed = providerEntry.getValue(); @@ -384,12 +413,15 @@ public class CryptoBenchmark { /* Calculate deltas */ deltaValue = wolfSpeed - otherSpeed; - deltaPercent = otherSpeed > 0 ? ((wolfSpeed / otherSpeed) - 1.0) * 100 : -100.0; + deltaPercent = + otherSpeed > 0 ? ((wolfSpeed / + otherSpeed) - 1.0) * 100 : -100.0; /* Create unique key to avoid duplicates */ String uniqueKey = operation + "|" + provider; if (!processedCombinations.contains(uniqueKey)) { - System.out.printf("| %-44s | %-12s | %+11.2f | %+8.1f |%n", + System.out.printf( + "| %-44s | %-12s | %+11.2f | %+8.1f |%n", displayOperation, provider, deltaValue, @@ -401,19 +433,26 @@ public class CryptoBenchmark { } } } - System.out.println("--------------------------------------------------------------------------------------"); - System.out.println("* Delta Value: MiB/s for symmetric ciphers, operations/second for RSA and ECC"); + System.out.println( + "--------------------------------------------------" + + "------------------------------------"); + System.out.println("* Delta Value: MiB/s for symmetric ciphers, " + + "operations/second for RSA and ECC"); } /* Helper method to categorize operations for sorting */ private static String getOperationCategory(String operation) { if (operation.contains("RSA")) return "A-RSA"; - if (operation.contains("ECC") || operation.contains("ECDH")) return "B-ECC"; - if (operation.contains("DH") && !operation.contains("ECDH")) return "C-DH"; + if (operation.contains("ECC") || + operation.contains("ECDH")) return "B-ECC"; + if (operation.contains("DH") && + !operation.contains("ECDH")) return "C-DH"; if (operation.contains("AES")) return "D-AES"; if (operation.contains("DES")) return "E-DES"; - if (operation.startsWith("HMAC") || operation.startsWith("Hmac")) return "F-HMAC"; - if (operation.contains("SHA") && !operation.contains("HMAC")) return "G-SHA"; + if (operation.startsWith("HMAC") || + operation.startsWith("Hmac")) return "F-HMAC"; + if (operation.contains("SHA") && + !operation.contains("HMAC")) return "G-SHA"; if (operation.contains("PBKDF2")) return "H-PBKDF2"; return "Z-Other"; } @@ -432,8 +471,8 @@ public class CryptoBenchmark { } /* Run symmetric encryption/decryption benchmarks */ - private static void runEncDecBenchmark(String algorithm, String mode, String padding, - String providerName) throws Exception { + private static void runEncDecBenchmark(String algorithm, + String mode, String padding, String providerName) throws Exception { SecretKey key; byte[] ivBytes; AlgorithmParameterSpec params; @@ -456,7 +495,8 @@ public class CryptoBenchmark { } else if (algorithm.equals("DESede")) { key = new SecretKeySpec(STATIC_DES3_KEY, "DESede"); } else { - throw new IllegalArgumentException("Unsupported algorithm: " + algorithm); + throw new IllegalArgumentException("Unsupported algorithm: " + + algorithm); } /* Generate random IV */ @@ -468,7 +508,8 @@ public class CryptoBenchmark { ivBytes = new byte[DES3_BLOCK_SIZE]; secureRandom.nextBytes(ivBytes); } else { - throw new IllegalArgumentException("Unsupported algorithm: " + algorithm); + throw new IllegalArgumentException("Unsupported algorithm: " + + algorithm); } if (mode.equals("GCM")) { @@ -517,7 +558,8 @@ public class CryptoBenchmark { System.out.printf(" %-40s %8.3f MiB took %.3f sec, %8.3f MiB/s%n", testName + " enc", dataSizeMiB, elapsedTime, encryptThroughput); - results.add(new BenchmarkResult(providerName, cipherName + " enc", encryptThroughput)); + results.add(new BenchmarkResult(providerName, cipherName + " enc", + encryptThroughput)); /* Benchmark decryption - run for 1 second */ startTime = System.nanoTime(); @@ -537,11 +579,13 @@ public class CryptoBenchmark { testName + " dec", dataSizeMiB, elapsedTime, decryptThroughput); /* Store decryption result */ - results.add(new BenchmarkResult(providerName, cipherName + " dec", decryptThroughput)); + results.add(new BenchmarkResult(providerName, cipherName + " dec", + decryptThroughput)); } /* Helper method to check if an algorithm is supported by the provider */ - private static boolean isAlgorithmSupported(String algorithm, String providerName) { + private static boolean isAlgorithmSupported(String algorithm, + String providerName) { try { MessageDigest.getInstance(algorithm, providerName); return true; @@ -551,7 +595,8 @@ public class CryptoBenchmark { } /* Run RSA benchmarks for specified provider and key size */ - private static void runRSABenchmark(String providerName, int keySize) throws Exception { + private static void runRSABenchmark(String providerName, + int keySize) throws Exception { /* Variables for benchmark operations */ KeyPairGenerator keyGen; Cipher cipher; @@ -591,7 +636,8 @@ public class CryptoBenchmark { } while (elapsedTime < TEST_MIN_TIME_SECONDS); keyGenOp = String.format("RSA %d key gen", keySize); - printBenchmarkResults(keyGenOps, elapsedTime, keyGenOp, providerName, cipherMode); + printBenchmarkResults(keyGenOps, elapsedTime, keyGenOp, providerName, + cipherMode); /* For 2048-bit keys, test public/private operations */ if (keySize == 2048) { @@ -609,7 +655,8 @@ public class CryptoBenchmark { elapsedTime = (System.nanoTime() - startTime) / 1_000_000_000.0; } while (elapsedTime < TEST_MIN_TIME_SECONDS); - printBenchmarkResults(publicOps, elapsedTime, "RSA 2048 public", providerName, cipherMode); + printBenchmarkResults(publicOps, elapsedTime, "RSA 2048 public", + providerName, cipherMode); /* Private key operations benchmark */ cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic()); @@ -625,12 +672,14 @@ public class CryptoBenchmark { elapsedTime = (System.nanoTime() - startTime) / 1_000_000_000.0; } while (elapsedTime < TEST_MIN_TIME_SECONDS); - printBenchmarkResults(privateOps, elapsedTime, "RSA 2048 private", providerName, cipherMode); + printBenchmarkResults(privateOps, elapsedTime, "RSA 2048 private", + providerName, cipherMode); } } /* ECC keygen benchmark */ - private static void runECCBenchmark(String providerName, String curveName) throws Exception { + private static void runECCBenchmark(String providerName, String curveName) + throws Exception { /* Initialize key generator */ final String finalProviderName; final KeyPairGenerator keyGen; @@ -655,7 +704,8 @@ public class CryptoBenchmark { }); String keyGenOp = String.format("ECC %s key gen", curveName); - printBenchmarkResults(result.operations, result.elapsedTime, keyGenOp, finalProviderName, "EC"); + printBenchmarkResults(result.operations, result.elapsedTime, keyGenOp, + finalProviderName, "EC"); } /* Get HMAC algorithms for a specific provider */ @@ -669,23 +719,27 @@ public class CryptoBenchmark { } /* Enhanced method to get HMAC algorithms for special provider cases, filtered by wolfJCE support */ - private static Set getHmacAlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { + private static Set getHmacAlgorithmsForProvider(String providerName, + Set wolfJCEAlgorithms) { return getAlgorithmsForProvider(providerName, "Mac", wolfJCEAlgorithms); } /* HMAC benchmark runner using the universal methods */ - private static void runHmacBenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runHmacBenchmarksForProvider(String providerName, + Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; if (providerName.equals("wolfJCE")) { supportedAlgorithms = wolfJCEAlgorithms; } else { - supportedAlgorithms = getHmacAlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getHmacAlgorithmsForProvider(providerName, + wolfJCEAlgorithms); } if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common HMAC algorithms found for provider " + providerName); + System.out.println(" No common HMAC algorithms found for provider " + + providerName); return; } @@ -700,7 +754,8 @@ public class CryptoBenchmark { } /* HMAC benchmark */ - private static void runHmacBenchmark(String algorithm, String providerName) throws Exception { + private static void runHmacBenchmark(String algorithm, String providerName) + throws Exception { Mac mac; byte[] testData; int ops = 0; @@ -742,14 +797,16 @@ public class CryptoBenchmark { double throughput = dataSizeMiB / elapsedTime; System.out.printf(" %-40s %8.3f MiB took %.3f sec, %8.3f MiB/s%n", - algorithm + " (" + providerName + ")", dataSizeMiB, elapsedTime, throughput); + algorithm + " (" + providerName + ")", dataSizeMiB, elapsedTime, + throughput); /* Store result */ results.add(new BenchmarkResult(providerName, algorithm, throughput)); } /* Run DH benchmarks for specified provider and key size */ - private static void runDHBenchmark(String providerName, int keySize) throws Exception { + private static void runDHBenchmark(String providerName, int keySize) + throws Exception { /* Variables for benchmark operations */ KeyPair keyPair1 = null; KeyPair keyPair2 = null; @@ -771,7 +828,8 @@ public class CryptoBenchmark { DHParameterSpec dhParams = new DHParameterSpec(p, g); /* Get KeyPairGenerator for DH */ - final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH", providerName); + final KeyPairGenerator keyGen = + KeyPairGenerator.getInstance("DH", providerName); keyGen.initialize(dhParams); /* Key Generation benchmark using helper */ @@ -784,7 +842,8 @@ public class CryptoBenchmark { }); String keyGenOp = String.format("DH %d key gen", keySize); - printBenchmarkResults(keyGenResult.operations, keyGenResult.elapsedTime, keyGenOp, providerName, DH_ALGORITHM); + printBenchmarkResults(keyGenResult.operations, keyGenResult.elapsedTime, + keyGenOp, providerName, DH_ALGORITHM); /* Generate key pairs for agreement operations */ keyPair1 = keyGen.generateKeyPair(); @@ -797,7 +856,8 @@ public class CryptoBenchmark { TimingResult agreementResult = runBenchmark(() -> { try { /* Create a new KeyAgreement instance for each operation */ - KeyAgreement keyAgreement = KeyAgreement.getInstance("DH", providerName); + KeyAgreement keyAgreement = KeyAgreement.getInstance("DH", + providerName); keyAgreement.init(finalKeyPair1.getPrivate()); keyAgreement.doPhase(finalKeyPair2.getPublic(), true); keyAgreement.generateSecret(); @@ -807,11 +867,13 @@ public class CryptoBenchmark { }); String agreementOp = String.format("DH %d agree", keySize); - printBenchmarkResults(agreementResult.operations, agreementResult.elapsedTime, agreementOp, providerName, DH_ALGORITHM); + printBenchmarkResults(agreementResult.operations, + agreementResult.elapsedTime, agreementOp, providerName, DH_ALGORITHM); } /* PBKDF2 benchmark */ - private static void runPBKDF2Benchmark(String algorithm, String providerName) throws Exception { + private static void runPBKDF2Benchmark(String algorithm, + String providerName) throws Exception { /* Variables for benchmark */ SecretKeyFactory secretKeyFactory; byte[] salt; @@ -828,14 +890,17 @@ public class CryptoBenchmark { /* Initialize SecretKeyFactory with specific provider */ try { - secretKeyFactory = SecretKeyFactory.getInstance(algorithm, providerName); + secretKeyFactory = SecretKeyFactory.getInstance(algorithm, + providerName); } catch (Exception e) { - System.out.printf(" %-40s Not supported by provider %s%n", algorithm, providerName); + System.out.printf(" %-40s Not supported by provider %s%n", + algorithm, providerName); return; } /* Create PBEKeySpec */ - PBEKeySpec pbeKeySpec = new PBEKeySpec(password, salt, iterationCount, keyLength * 8); + PBEKeySpec pbeKeySpec = new PBEKeySpec(password, salt, iterationCount, + keyLength * 8); /* Warm up phase */ for (int i = 0; i < WARMUP_ITERATIONS; i++) { @@ -867,7 +932,8 @@ public class CryptoBenchmark { } /* MessageDigest benchmark */ - private static void runMessageDigestBenchmark(String algorithm, String providerName) throws Exception { + private static void runMessageDigestBenchmark(String algorithm, + String providerName) throws Exception { MessageDigest md = MessageDigest.getInstance(algorithm, providerName); byte[] testData = generateTestData(DATA_SIZE); long ops = 0; @@ -891,12 +957,14 @@ public class CryptoBenchmark { double dataSizeMiB = (DATA_SIZE * ops) / (1024.0 * 1024.0); double throughput = dataSizeMiB / elapsedTime; System.out.printf("%-40s %8.3f MiB took %.3f sec, %8.3f MiB/s%n", - algorithm + " (" + providerName + ")", dataSizeMiB, elapsedTime, throughput); + algorithm + " (" + providerName + ")", dataSizeMiB, elapsedTime, + throughput); results.add(new BenchmarkResult(providerName, algorithm, throughput)); } /* Run signature benchmarks */ - private static void runSignatureBenchmark(String algorithm, String providerName) throws Exception { + private static void runSignatureBenchmark(String algorithm, + String providerName) throws Exception { KeyPairGenerator keyGen; Signature signature; byte[] testData; @@ -926,13 +994,13 @@ public class CryptoBenchmark { } else if (algorithmLower.contains("withecdsa")) { keyType = "EC"; if (providerName.equals("SunJCE")) { - /* Use SunEC if available, otherwise fall back to what's available */ Provider sunECProvider = Security.getProvider("SunEC"); if (sunECProvider != null) { keyGenProvider = "SunEC"; signatureProvider = "SunEC"; } else { - throw new Exception("SunEC provider not available for ECDSA operations"); + throw new Exception( + "SunEC provider not available for ECDSA operations"); } } } else if (algorithmLower.contains("withdsa")) { @@ -942,7 +1010,8 @@ public class CryptoBenchmark { signatureProvider = "SUN"; } } else { - throw new IllegalArgumentException("Unsupported signature algorithm: " + algorithm); + throw new IllegalArgumentException( + "Unsupported signature algorithm: " + algorithm); } try { @@ -984,8 +1053,10 @@ public class CryptoBenchmark { double signOpsPerSec = ops / elapsedTime; System.out.printf(" %-40s %8d ops took %.3f sec, %8.3f ops/sec%n", - algorithm + " sign (" + signatureProvider + ")", ops, elapsedTime, signOpsPerSec); - results.add(new BenchmarkResult(signatureProvider, algorithm + " sign", signOpsPerSec)); + algorithm + " sign (" + signatureProvider + ")", ops, + elapsedTime, signOpsPerSec); + results.add(new BenchmarkResult(signatureProvider, algorithm + + " sign", signOpsPerSec)); /* Benchmark verification */ ops = 0; @@ -1002,8 +1073,10 @@ public class CryptoBenchmark { double verifyOpsPerSec = ops / elapsedTime; System.out.printf(" %-40s %8d ops took %.3f sec, %8.3f ops/sec%n", - algorithm + " verify (" + signatureProvider + ")", ops, elapsedTime, verifyOpsPerSec); - results.add(new BenchmarkResult(signatureProvider, algorithm + " verify", verifyOpsPerSec)); + algorithm + " verify (" + signatureProvider + ")", ops, + elapsedTime, verifyOpsPerSec); + results.add(new BenchmarkResult(signatureProvider, algorithm + + " verify", verifyOpsPerSec)); } catch (Exception e) { System.err.printf(" %-40s Not supported: %s (%s)%n", @@ -1018,23 +1091,29 @@ public class CryptoBenchmark { } /* Enhanced method to get signature algorithms for special provider cases, filtered by wolfJCE support */ - private static Set getSignatureAlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { - return getAlgorithmsForProvider(providerName, "Signature", wolfJCEAlgorithms); + private static Set getSignatureAlgorithmsForProvider( + String providerName, Set wolfJCEAlgorithms) { + return getAlgorithmsForProvider(providerName, + "Signature", wolfJCEAlgorithms); } /* Signature benchmark runner */ - private static void runSignatureBenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runSignatureBenchmarksForProvider(String providerName, + Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; if (providerName.equals("wolfJCE")) { supportedAlgorithms = wolfJCEAlgorithms; } else { - supportedAlgorithms = getSignatureAlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getSignatureAlgorithmsForProvider( + providerName, wolfJCEAlgorithms); } if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common signature algorithms found for provider " + providerName); + System.out.println( + "No common signature algorithms found for provider " + + providerName); return; } @@ -1049,8 +1128,10 @@ public class CryptoBenchmark { } /* Enhanced method to get cipher algorithms for special provider cases, filtered by wolfJCE support */ - private static Set getCipherAlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { - Set providerAlgorithms = getAlgorithmsForService(providerName, "Cipher"); + private static Set getCipherAlgorithmsForProvider( + String providerName, Set wolfJCEAlgorithms) { + Set providerAlgorithms = getAlgorithmsForService(providerName, + "Cipher"); Set filteredAlgorithms = new TreeSet<>(); for (String wolfAlg : wolfJCEAlgorithms) { @@ -1075,8 +1156,10 @@ public class CryptoBenchmark { } /* Enhanced method to get PBKDF2 algorithms for special provider cases, filtered by wolfJCE support */ - private static Set getPBKDF2AlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { - Set providerAlgorithms = getAlgorithmsForService(providerName, "SecretKeyFactory"); + private static Set getPBKDF2AlgorithmsForProvider( + String providerName, Set wolfJCEAlgorithms) { + Set providerAlgorithms = getAlgorithmsForService(providerName, + "SecretKeyFactory"); Set filteredAlgorithms = new TreeSet<>(); for (String wolfAlg : wolfJCEAlgorithms) { @@ -1092,7 +1175,8 @@ public class CryptoBenchmark { } if (providerName.equals("BC")) { - String normalizedProviderAlg = providerAlg.replace("WITH", "With").replace("HMAC", "Hmac"); + String normalizedProviderAlg = providerAlg.replace("WITH", + "With").replace("HMAC", "Hmac"); if (normalizedProviderAlg.equalsIgnoreCase(wolfAlg)) { filteredAlgorithms.add(providerAlg); break; @@ -1105,18 +1189,22 @@ public class CryptoBenchmark { } /* Cipher benchmark runner using the universal methods */ - private static void runCipherBenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runCipherBenchmarksForProvider(String providerName, + Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; if (providerName.equals("wolfJCE")) { supportedAlgorithms = wolfJCEAlgorithms; } else { - supportedAlgorithms = getCipherAlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getCipherAlgorithmsForProvider(providerName, + wolfJCEAlgorithms); } if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common Cipher algorithms found for provider " + providerName); + System.out.println( + " No common Cipher algorithms found for provider " + + providerName); return; } @@ -1136,7 +1224,8 @@ public class CryptoBenchmark { /* Skip if DESede is not enabled */ if (baseAlg.equals("DESede") && !FeatureDetect.Des3Enabled()) { - System.out.printf(" %-40s DESede not enabled in wolfCrypt%n", + System.out.printf( + " %-40s DESede not enabled in wolfCrypt%n", algorithm + " (" + providerName + ")"); continue; } @@ -1154,19 +1243,20 @@ public class CryptoBenchmark { return getAlgorithmsForService(providerName, "MessageDigest"); } - /* Get the baseline MessageDigest algorithms that wolfJCE supports for comparison */ + /* Get the baseline MessageDigest algorithms wolfJCE supports comparison */ private static Set getWolfJCEMessageDigestAlgorithms() { return getWolfJCEAlgorithmsForService("MessageDigest"); } - /* Enhanced method to get MessageDigest algorithms for special provider cases, filtered by wolfJCE support */ - private static Set getMessageDigestAlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { + private static Set getMessageDigestAlgorithmsForProvider( + String providerName, Set wolfJCEAlgorithms) { Set algorithms; if (providerName.equals("wolfJCE")) { algorithms = new TreeSet<>(wolfJCEAlgorithms); } else { - algorithms = getAlgorithmsForProvider(providerName, "MessageDigest", wolfJCEAlgorithms); + algorithms = getAlgorithmsForProvider(providerName, "MessageDigest", + wolfJCEAlgorithms); } Set filteredAlgorithms = new TreeSet<>(); @@ -1191,17 +1281,22 @@ public class CryptoBenchmark { /* For BC, convert their format to standard format */ if (providerName.equals("BC")) { - if (normalized.startsWith("SHA3") && !normalized.contains("-")) { + if (normalized.startsWith("SHA3") && + !normalized.contains("-")) { if (normalized.equals("SHA3224")) normalized = "SHA3-224"; - else if (normalized.equals("SHA3256")) normalized = "SHA3-256"; - else if (normalized.equals("SHA3384")) normalized = "SHA3-384"; - else if (normalized.equals("SHA3512")) normalized = "SHA3-512"; + else if (normalized.equals("SHA3256")) normalized = + "SHA3-256"; + else if (normalized.equals("SHA3384")) normalized = + "SHA3-384"; + else if (normalized.equals("SHA3512")) normalized = + "SHA3-512"; } normalized = normalized.replace("SHA3", "SHA3-"); normalized = normalized.replace("SHA3--", "SHA3-"); } - if (normalizedWolfJCE.contains(normalized) && !addedNormalized.contains(normalized)) { + if (normalizedWolfJCE.contains(normalized) && + !addedNormalized.contains(normalized)) { if (normalized.equals("SHA-1")) { if (algorithm.equals("SHA-1")) { filteredAlgorithms.add(algorithm); @@ -1230,14 +1325,18 @@ public class CryptoBenchmark { } /* MessageDigest benchmark runner using the universal methods */ - private static void runMessageDigestBenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runMessageDigestBenchmarksForProvider( + String providerName, Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; - supportedAlgorithms = getMessageDigestAlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getMessageDigestAlgorithmsForProvider( + providerName, wolfJCEAlgorithms); if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common MessageDigest algorithms found for provider " + providerName); + System.out.println( + " No common MessageDigest algorithms found for provider " + + providerName); return; } @@ -1245,13 +1344,20 @@ public class CryptoBenchmark { try { /* Check if algorithm is enabled in wolfCrypt */ boolean isEnabled = true; - if (algorithm.equals("MD5") && !FeatureDetect.Md5Enabled()) isEnabled = false; - else if (algorithm.equals("SHA-1") && !FeatureDetect.ShaEnabled()) isEnabled = false; - else if (algorithm.equals("SHA-224") && !FeatureDetect.Sha224Enabled()) isEnabled = false; - else if (algorithm.equals("SHA-256") && !FeatureDetect.Sha256Enabled()) isEnabled = false; - else if (algorithm.equals("SHA-384") && !FeatureDetect.Sha384Enabled()) isEnabled = false; - else if (algorithm.equals("SHA-512") && !FeatureDetect.Sha512Enabled()) isEnabled = false; - else if (algorithm.startsWith("SHA3-") && !FeatureDetect.Sha3Enabled()) isEnabled = false; + if (algorithm.equals("MD5") && + !FeatureDetect.Md5Enabled()) isEnabled = false; + else if (algorithm.equals("SHA-1") && + !FeatureDetect.ShaEnabled()) isEnabled = false; + else if (algorithm.equals("SHA-224") && + !FeatureDetect.Sha224Enabled()) isEnabled = false; + else if (algorithm.equals("SHA-256") && + !FeatureDetect.Sha256Enabled()) isEnabled = false; + else if (algorithm.equals("SHA-384") && + !FeatureDetect.Sha384Enabled()) isEnabled = false; + else if (algorithm.equals("SHA-512") && + !FeatureDetect.Sha512Enabled()) isEnabled = false; + else if (algorithm.startsWith("SHA3-") && + !FeatureDetect.Sha3Enabled()) isEnabled = false; if (!isEnabled) { System.out.printf(" %-40s Not enabled in wolfCrypt%n", @@ -1273,25 +1379,30 @@ public class CryptoBenchmark { } /* PBKDF2 benchmark runner using the universal methods */ - private static void runPBKDF2BenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runPBKDF2BenchmarksForProvider(String providerName, + Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; if (providerName.equals("wolfJCE")) { supportedAlgorithms = wolfJCEAlgorithms; } else { - supportedAlgorithms = getPBKDF2AlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getPBKDF2AlgorithmsForProvider(providerName, + wolfJCEAlgorithms); } if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common SecretKeyFactory algorithms found for provider " + providerName); + System.out.println( + " No common SecretKeyFactory algorithms found for provider " + + providerName); return; } for (String algorithm : supportedAlgorithms) { try { /* Skip SHA3 algorithms for SunJCE */ - if (providerName.equals("SunJCE") && algorithm.contains("SHA3")) { + if (providerName.equals("SunJCE") && + algorithm.contains("SHA3")) { continue; } @@ -1303,25 +1414,24 @@ public class CryptoBenchmark { } } - /* Get the baseline cipher algorithms that wolfJCE supports for comparison */ private static Set getWolfJCECipherAlgorithms() { return getWolfJCEAlgorithmsForService("Cipher"); } - /* Get the baseline PBKDF2 algorithms that wolfJCE supports for comparison */ private static Set getWolfJCEPBKDF2Algorithms() { return getWolfJCEAlgorithmsForService("SecretKeyFactory"); } - /* Get the baseline signature algorithms that wolfJCE supports for comparison */ private static Set getWolfJCESignatureAlgorithms() { return getWolfJCEAlgorithmsForService("Signature"); } /* KeyGenerator benchmark */ - private static void runKeyGeneratorBenchmark(String algorithm, String providerName) throws Exception { + private static void runKeyGeneratorBenchmark( + String algorithm, String providerName) throws Exception { /* Initialize KeyGenerator with specific provider */ - final KeyGenerator keyGen = KeyGenerator.getInstance(algorithm, providerName); + final KeyGenerator keyGen = KeyGenerator.getInstance(algorithm, + providerName); /* Set appropriate key size based on algorithm */ if (algorithm.equals("AES")) { @@ -1332,7 +1442,8 @@ public class CryptoBenchmark { keyGen.init(168); } else if (algorithm.equals("RSA")) { keyGen.init(2048); - } else if (algorithm.startsWith("Hmac") || algorithm.startsWith("HMAC")) { + } else if (algorithm.startsWith("Hmac") || + algorithm.startsWith("HMAC")) { try { int keySize = getHmacKeySize(algorithm) * 8; keyGen.init(keySize); @@ -1340,10 +1451,13 @@ public class CryptoBenchmark { } } else { try { - KeyGenerator tempKeyGen = KeyGenerator.getInstance(algorithm, providerName); + KeyGenerator tempKeyGen = KeyGenerator.getInstance(algorithm, + providerName); tempKeyGen.generateKey(); } catch (Exception e) { - throw new IllegalArgumentException("Unsupported algorithm or unable to determine key size: " + algorithm); + throw new IllegalArgumentException( + "Unsupported algorithm or unable to determine key size: " + + algorithm); } } @@ -1363,30 +1477,38 @@ public class CryptoBenchmark { double opsPerSec = result.operations / result.elapsedTime; System.out.printf(" %-40s %8d ops took %.3f sec, %8.3f ops/sec%n", - algorithm + " (" + providerName + ")", result.operations, result.elapsedTime, opsPerSec); + algorithm + " (" + providerName + ")", result.operations, + result.elapsedTime, opsPerSec); /* Store result */ - results.add(new BenchmarkResult(providerName, algorithm + " keygen", opsPerSec)); + results.add(new BenchmarkResult(providerName, algorithm + " keygen", + opsPerSec)); } /* Get KeyGenerator algorithms for a specific provider */ - private static Set getKeyGeneratorAlgorithmsForProvider(String providerName, Set wolfJCEAlgorithms) { - return getAlgorithmsForProvider(providerName, "KeyGenerator", wolfJCEAlgorithms); + private static Set getKeyGeneratorAlgorithmsForProvider( + String providerName, Set wolfJCEAlgorithms) { + return getAlgorithmsForProvider(providerName, "KeyGenerator", + wolfJCEAlgorithms); } /* KeyGenerator benchmark runner */ - private static void runKeyGeneratorBenchmarksForProvider(String providerName, Set wolfJCEAlgorithms) { + private static void runKeyGeneratorBenchmarksForProvider( + String providerName, Set wolfJCEAlgorithms) { System.out.println("\n" + providerName + ":"); Set supportedAlgorithms; if (providerName.equals("wolfJCE")) { supportedAlgorithms = wolfJCEAlgorithms; } else { - supportedAlgorithms = getKeyGeneratorAlgorithmsForProvider(providerName, wolfJCEAlgorithms); + supportedAlgorithms = getKeyGeneratorAlgorithmsForProvider( + providerName, wolfJCEAlgorithms); } if (supportedAlgorithms.isEmpty()) { - System.out.println(" No common KeyGenerator algorithms found for provider " + providerName); + System.out.println( + " No common KeyGenerator algorithms found for provider " + + providerName); return; } @@ -1401,7 +1523,8 @@ public class CryptoBenchmark { } /* Run ECDH benchmarks for specified provider and curve */ - private static void runECDHBenchmark(String providerName, String curveName) throws Exception { + private static void runECDHBenchmark( + String providerName, String curveName) throws Exception { /* Variables for benchmark operations */ final String finalProviderName; final KeyPairGenerator keyGen; @@ -1429,7 +1552,8 @@ public class CryptoBenchmark { }); String keyGenOp = String.format("ECDH %s key gen", curveName); - printBenchmarkResults(keyGenResult.operations, keyGenResult.elapsedTime, keyGenOp, finalProviderName, "ECDH"); + printBenchmarkResults(keyGenResult.operations, keyGenResult.elapsedTime, + keyGenOp, finalProviderName, "ECDH"); /* Generate key pairs for agreement operations */ keyPair1 = keyGen.generateKeyPair(); @@ -1441,8 +1565,8 @@ public class CryptoBenchmark { TimingResult agreementResult = runBenchmark(() -> { try { - /* Create a new KeyAgreement instance for each operation to avoid "Object already has a key" error */ - KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", finalProviderName); + KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", + finalProviderName); keyAgreement.init(finalKeyPair1.getPrivate()); keyAgreement.doPhase(finalKeyPair2.getPublic(), true); keyAgreement.generateSecret(); @@ -1452,7 +1576,8 @@ public class CryptoBenchmark { }); String agreementOp = String.format("ECDH %s agree", curveName); - printBenchmarkResults(agreementResult.operations, agreementResult.elapsedTime, agreementOp, finalProviderName, "ECDH"); + printBenchmarkResults(agreementResult.operations, + agreementResult.elapsedTime, agreementOp, finalProviderName, "ECDH"); } public static void main(String[] args) { @@ -1461,8 +1586,10 @@ public class CryptoBenchmark { boolean hasBouncyCastle = false; Provider bcProvider = null; try { - Class bcClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); - bcProvider = (Provider) bcClass.getDeclaredConstructor().newInstance(); + Class bcClass = Class.forName( + "org.bouncycastle.jce.provider.BouncyCastleProvider"); + bcProvider = (Provider) + bcClass.getDeclaredConstructor().newInstance(); hasBouncyCastle = true; } catch (Exception e) { /* Bouncy Castle not available */ @@ -1470,12 +1597,12 @@ public class CryptoBenchmark { /* Create provider list based on availability */ java.util.List providerList = new java.util.ArrayList<>(); - java.util.List providerNameList = new java.util.ArrayList<>(); + java.util.List providerNameList = + new java.util.ArrayList<>(); providerList.add(new WolfCryptProvider()); providerNameList.add("wolfJCE"); - /* Get SunJCE provider using Security.getProvider instead of direct instantiation */ Provider sunJCE = Security.getProvider("SunJCE"); if (sunJCE != null) { providerList.add(sunJCE); @@ -1498,9 +1625,11 @@ public class CryptoBenchmark { } /* Run symmetric benchmarks with hardcoded algorithms (temporary fix) */ - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println(" Symmetric Cipher Benchmark"); - System.out.println("-----------------------------------------------------------------------------\n"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); setupProvidersForTest(providers[0]); Set wolfJCECipherAlgorithms = getWolfJCECipherAlgorithms(); @@ -1511,61 +1640,78 @@ public class CryptoBenchmark { System.out.println("\n" + providerName + ":"); try { - runEncDecBenchmark("AES", "CBC", "NoPadding", providerName); - runEncDecBenchmark("AES", "CBC", "PKCS5Padding", providerName); - runEncDecBenchmark("AES", "GCM", "NoPadding", providerName); + runEncDecBenchmark("AES", "CBC", "NoPadding", + providerName); + runEncDecBenchmark("AES", "CBC", "PKCS5Padding", + providerName); + runEncDecBenchmark("AES", "GCM", "NoPadding", + providerName); if (FeatureDetect.Des3Enabled()) { - runEncDecBenchmark("DESede", "CBC", "NoPadding", providerName); + runEncDecBenchmark("DESede", "CBC", "NoPadding", + providerName); } } catch (Exception e) { - System.out.printf(" Error testing symmetric ciphers for %s: %s%n", providerName, e.getMessage()); + System.out.printf( + " Error testing symmetric ciphers for %s: %s%n", + providerName, e.getMessage()); } } /* Run RSA benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("RSA Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); for (Provider provider : providers) { setupProvidersForTest(provider); - System.out.println("\n" + (provider.getName().equals("SunJCE") ? "SunJCE / SunRsaSign" : provider.getName()) + ":"); + System.out.println("\n" + (provider.getName().equals("SunJCE") + ? "SunJCE / SunRsaSign" : provider.getName()) + ":"); for (int keySize : RSA_KEY_SIZES) { try { runRSABenchmark(provider.getName(), keySize); } catch (Exception e) { - System.out.printf("Failed to benchmark RSA %d with provider %s: %s%n", + System.out.printf( + "Failed to benchmark RSA %d with provider %s: %s%n", keySize, provider.getName(), e.getMessage()); } } } /* Run ECC benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("ECC Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); for (Provider provider : providers) { - if (provider instanceof WolfCryptProvider && !FeatureDetect.EccKeyGenEnabled()) { + if (provider instanceof WolfCryptProvider && + !FeatureDetect.EccKeyGenEnabled()) { continue; } setupProvidersForTest(provider); - System.out.println("\n" + (provider.getName().equals("SunJCE") ? "SunJCE / SunEC" : provider.getName()) + ":"); + System.out.println("\n" + (provider.getName().equals("SunJCE") + ? "SunJCE / SunEC" : provider.getName()) + ":"); for (String curve : ECC_CURVES) { try { runECCBenchmark(provider.getName(), curve); } catch (Exception e) { - System.out.printf("Failed to benchmark %s with provider %s: %s%n", + System.out.printf( + "Failed to benchmark %s with provider %s: %s%n", curve, provider.getName(), e.getMessage()); } } } /* Run HMAC benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("HMAC Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); /* First, set up wolfJCE provider to get its algorithm list */ @@ -1574,17 +1720,21 @@ public class CryptoBenchmark { for (Provider provider : providers) { setupProvidersForTest(provider); - runHmacBenchmarksForProvider(provider.getName(), wolfJCEHmacAlgorithms); + runHmacBenchmarksForProvider(provider.getName(), + wolfJCEHmacAlgorithms); } /* Run DH benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("DH Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); for (Provider provider : providers) { - if (provider instanceof WolfCryptProvider && !FeatureDetect.DhEnabled()) { + if (provider instanceof WolfCryptProvider && + !FeatureDetect.DhEnabled()) { continue; } setupProvidersForTest(provider); @@ -1593,36 +1743,44 @@ public class CryptoBenchmark { try { runDHBenchmark(provider.getName(), keySize); } catch (Exception e) { - System.out.printf("Failed to benchmark DH %d with provider %s: %s%n", + System.out.printf( + "Failed to benchmark DH %d with provider %s: %s%n", keySize, provider.getName(), e.getMessage()); } } } - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("ECDH Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); for (Provider provider : providers) { - if (provider instanceof WolfCryptProvider && !FeatureDetect.EccDheEnabled()) { + if (provider instanceof WolfCryptProvider && + !FeatureDetect.EccDheEnabled()) { continue; } setupProvidersForTest(provider); - System.out.println("\n" + (provider.getName().equals("SunJCE") ? "SunJCE / SunEC" : provider.getName()) + ":"); + System.out.println("\n" + (provider.getName().equals("SunJCE") + ? "SunJCE / SunEC" : provider.getName()) + ":"); for (String curve : ECC_CURVES) { try { runECDHBenchmark(provider.getName(), curve); } catch (Exception e) { - System.out.printf("Failed to benchmark ECDH %s with provider %s: %s%n", + System.out.printf( + "Failed to benchmark ECDH %s with provider %s: %s%n", curve, provider.getName(), e.getMessage()); } } } /* Run PBKDF2 benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("PBKDF2 Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); /* First, set up wolfJCE provider to get its algorithm list */ setupProvidersForTest(providers[0]); @@ -1630,17 +1788,21 @@ public class CryptoBenchmark { for (Provider provider : providers) { setupProvidersForTest(provider); - runPBKDF2BenchmarksForProvider(provider.getName(), wolfJCEPBKDF2Algorithms); + runPBKDF2BenchmarksForProvider(provider.getName(), + wolfJCEPBKDF2Algorithms); } /* Run MessageDigest benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("MessageDigest Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); /* First, set up wolfJCE provider to get its algorithm list */ setupProvidersForTest(providers[0]); - Set wolfJCEMessageDigestAlgorithms = getWolfJCEMessageDigestAlgorithms(); + Set wolfJCEMessageDigestAlgorithms = + getWolfJCEMessageDigestAlgorithms(); for (Provider provider : providers) { setupProvidersForTest(provider); @@ -1648,18 +1810,22 @@ public class CryptoBenchmark { String digestProviderName = providerName; /* Handle special case for digest providers */ - if (!providerName.equals("wolfJCE") && !providerName.equals("BC")) { + if (!providerName.equals("wolfJCE") && + !providerName.equals("BC")) { digestProviderName = "SUN"; } setupDigestProvider(providerName); - runMessageDigestBenchmarksForProvider(digestProviderName, wolfJCEMessageDigestAlgorithms); + runMessageDigestBenchmarksForProvider(digestProviderName, + wolfJCEMessageDigestAlgorithms); } /* Run Signature benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("Signature Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); /* First, set up wolfJCE provider to get its algorithm list */ setupProvidersForTest(providers[0]); @@ -1667,24 +1833,30 @@ public class CryptoBenchmark { for (Provider provider : providers) { setupProvidersForTest(provider); - runSignatureBenchmarksForProvider(provider.getName(), wolfJCEAlgorithms); + runSignatureBenchmarksForProvider(provider.getName(), + wolfJCEAlgorithms); } /* Run KeyGenerator benchmarks with clean provider setup */ - System.out.println("\n-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------"); System.out.println("KeyGenerator Benchmark Results"); - System.out.println("-----------------------------------------------------------------------------"); + System.out.println("----------------------------------------------" + + "-------------------------------\n"); /* First, set up wolfJCE provider to get its algorithm list */ setupProvidersForTest(providers[0]); - Set wolfJCEKeyGenAlgorithms = getWolfJCEAlgorithmsForService("KeyGenerator"); + Set wolfJCEKeyGenAlgorithms = + getWolfJCEAlgorithmsForService("KeyGenerator"); for (Provider provider : providers) { setupProvidersForTest(provider); - runKeyGeneratorBenchmarksForProvider(provider.getName(), wolfJCEKeyGenAlgorithms); + runKeyGeneratorBenchmarksForProvider(provider.getName(), + wolfJCEKeyGenAlgorithms); } - System.out.println("-----------------------------------------------------------------------------\n"); + System.out.println("----------------------------------------------" + + "-------------------------------"); /* Print delta table */ printDeltaTable();