Skip to content

Commit

Permalink
Implemented logic to check if BC is available
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Tjaden committed Jan 6, 2025
1 parent a1975e7 commit a86067d
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions examples/provider/CryptoBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Arrays;

import com.wolfssl.provider.jce.WolfCryptProvider;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class CryptoBenchmark {
/* Constants for benchmark configuration */
Expand Down Expand Up @@ -151,14 +150,37 @@ private static void runBenchmark(String algorithm, String mode, String providerN

public static void main(String[] args) {
try {
/* Array of providers to test */
Provider[] providers = {
new WolfCryptProvider(),
new com.sun.crypto.provider.SunJCE(),
new BouncyCastleProvider()
};
/* Check if Bouncy Castle is available */
boolean hasBouncyCastle = false;
Provider bcProvider = null;
try {
Class<?> bcClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
bcProvider = (Provider) bcClass.getDeclaredConstructor().newInstance();
hasBouncyCastle = true;
} catch (Exception e) {
// Bouncy Castle not available
}

/* Create provider list based on availability */
java.util.List<Provider> providerList = new java.util.ArrayList<>();
java.util.List<String> providerNameList = new java.util.ArrayList<>();

/* Always add wolfJCE first */
providerList.add(new WolfCryptProvider());
providerNameList.add("wolfJCE");

/* Always add SunJCE second */
providerList.add(new com.sun.crypto.provider.SunJCE());
providerNameList.add("SunJCE");

/* Add Bouncy Castle if available */
if (hasBouncyCastle && bcProvider != null) {
providerList.add(bcProvider);
providerNameList.add("BC");
}

String[] providerNames = {"wolfJCE", "SunJCE", "BC"};
Provider[] providers = providerList.toArray(new Provider[0]);
String[] providerNames = providerNameList.toArray(new String[0]);

System.out.println("------------------------------------------------------------------------------");
System.out.println(" JCE Crypto Provider Benchmark");
Expand Down

0 comments on commit a86067d

Please sign in to comment.