Skip to content

Commit 02449c7

Browse files
author
Jack Tjaden
committed
Improved benchmark script which installs newest version of BC via wget or curl
1 parent 6bc01e5 commit 02449c7

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

examples/provider/CryptoBenchmark.sh

+55-35
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,60 @@
33
# Flag to track if we downloaded BC during this session
44
BC_DOWNLOADED=false
55

6-
# Function to download Bouncy Castle JARs
6+
# Function to get the latest Bouncy Castle version from Maven Central
7+
get_latest_version() {
8+
local metadata_url="https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/maven-metadata.xml"
9+
if command -v curl >/dev/null; then
10+
curl -s "$metadata_url" | grep '<latest>' | sed -e 's/.*<latest>\(.*\)<\/latest>.*/\1/'
11+
elif command -v wget >/dev/null; then
12+
wget -q -O - "$metadata_url" | grep '<latest>' | sed -e 's/.*<latest>\(.*\)<\/latest>.*/\1/'
13+
else
14+
echo "Error: Neither curl nor wget is installed. Please install one to fetch the latest version."
15+
exit 1
16+
fi
17+
}
18+
19+
# Function to download Bouncy Castle JARs with the latest version
720
download_bc_jars() {
8-
local bc_version="1.79"
21+
local bc_version=$(get_latest_version)
922
local lib_dir="../../../lib"
10-
local bc_url="https://downloads.bouncycastle.org/java"
23+
local bc_url="https://repo1.maven.org/maven2/org/bouncycastle"
1124

12-
echo -n "Downloading Bouncy Castle JARs... "
25+
if [ -z "$bc_version" ]; then
26+
echo "failed (could not determine latest version)"
27+
return 1
28+
fi
1329

14-
# Create lib directory if it doesn't exist
15-
mkdir -p "$lib_dir" 2>/dev/null
30+
echo -n "Downloading Bouncy Castle JARs (version $bc_version)... "
31+
mkdir -p "$lib_dir" || {
32+
echo "failed (cannot create $lib_dir)"
33+
return 1
34+
}
1635

17-
# Download both required JARs
1836
if command -v wget >/dev/null; then
19-
wget -q -P "$lib_dir" "$bc_url/bcprov-jdk18on-$bc_version.jar" 2>/dev/null &&
20-
wget -q -P "$lib_dir" "$bc_url/bctls-jdk18on-$bc_version.jar" 2>/dev/null || return 1
37+
wget -P "$lib_dir" "$bc_url/bcprov-jdk18on/$bc_version/bcprov-jdk18on-$bc_version.jar" &&
38+
wget -P "$lib_dir" "$bc_url/bctls-jdk18on/$bc_version/bctls-jdk18on-$bc_version.jar" || {
39+
echo "failed (wget error: check URL or network)"
40+
return 1
41+
}
2142
elif command -v curl >/dev/null; then
22-
curl -s -L -o "$lib_dir/bcprov-jdk18on-$bc_version.jar" "$bc_url/bcprov-jdk18on-$bc_version.jar" 2>/dev/null &&
23-
curl -s -L -o "$lib_dir/bctls-jdk18on-$bc_version.jar" "$bc_url/bctls-jdk18on-$bc_version.jar" 2>/dev/null || return 1
43+
curl -L -o "$lib_dir/bcprov-jdk18on-$bc_version.jar" "$bc_url/bcprov-jdk18on/$bc_version/bcprov-jdk18on-$bc_version.jar" &&
44+
curl -L -o "$lib_dir/bctls-jdk18on-$bc_version.jar" "$bc_url/bctls-jdk18on/$bc_version/bctls-jdk18on-$bc_version.jar" || {
45+
echo "failed (curl error: check URL or network)"
46+
return 1
47+
}
2448
else
25-
echo "failed"
26-
echo "Error: Neither wget nor curl is available. Please install either wget or curl."
49+
echo "failed (neither wget nor curl installed)"
50+
echo "Please install wget or curl."
2751
return 1
2852
fi
2953

30-
# Verify downloads were successful
3154
if [ -f "$lib_dir/bcprov-jdk18on-$bc_version.jar" ] && [ -f "$lib_dir/bctls-jdk18on-$bc_version.jar" ]; then
3255
echo "done"
3356
BC_DOWNLOADED=true
3457
return 0
3558
else
36-
echo "failed"
59+
echo "failed (downloaded files not found)"
3760
return 1
3861
fi
3962
}
@@ -42,33 +65,32 @@ download_bc_jars() {
4265
cleanup_bc_jars() {
4366
local lib_dir="../../../lib"
4467
echo -n "Removing Bouncy Castle JARs... "
45-
rm -f "$lib_dir/bcprov-jdk18on-1.79.jar" "$lib_dir/bctls-jdk18on-1.79.jar" 2>/dev/null
46-
if [ $? -eq 0 ]; then
47-
echo "done"
48-
return 0
49-
else
50-
echo "failed"
51-
return 1
52-
fi
68+
rm -f "$lib_dir/bcprov-jdk18on-"*".jar" "$lib_dir/bctls-jdk18on-"*".jar" && echo "done" || echo "failed"
5369
}
5470

55-
cd ./examples/build/provider
56-
57-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../lib/:/usr/local/lib
71+
cd ./examples/build/provider || {
72+
echo "Error: Cannot change to ./examples/build/provider"
73+
exit 1
74+
}
5875

76+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../lib:/usr/local/lib
5977
CLASSPATH="../../../lib/wolfcrypt-jni.jar:."
6078

61-
if [ -f "../../../lib/bcprov-jdk18on-1.79.jar" ] && [ -f "../../../lib/bctls-jdk18on-1.79.jar" ]; then
62-
echo "Running crypto benchmark with Bouncy Castle"
63-
CLASSPATH="$CLASSPATH:../../../lib/bcprov-jdk18on-1.79.jar:../../../lib/bctls-jdk18on-1.79.jar"
79+
# Check for existing Bouncy Castle JARs (any version)
80+
if ls "../../../lib/bcprov-jdk18on-"*".jar" "../../../lib/bctls-jdk18on-"*".jar" 2>/dev/null; then
81+
latest_bc_jar=$(ls -t "../../../lib/bcprov-jdk18on-"*".jar" | head -n 1)
82+
bc_version=$(basename "$latest_bc_jar" | sed -e 's/bcprov-jdk18on-//' -e 's/.jar$//')
83+
echo "Running crypto benchmark with Bouncy Castle (version $bc_version)"
84+
CLASSPATH="$CLASSPATH:$latest_bc_jar:../../../lib/bctls-jdk18on-$bc_version.jar"
6485
else
6586
echo "Bouncy Castle JARs not found in lib directory"
6687
read -p "Would you like to download Bouncy Castle JARs? (y/n) " -n 1 -r
6788
echo
6889
if [[ $REPLY =~ ^[Yy]$ ]]; then
6990
if download_bc_jars; then
70-
echo "Running crypto benchmark with Bouncy Castle"
71-
CLASSPATH="$CLASSPATH:../../../lib/bcprov-jdk18on-1.79.jar:../../../lib/bctls-jdk18on-1.79.jar"
91+
bc_version=$(get_latest_version)
92+
echo "Running crypto benchmark with Bouncy Castle (version $bc_version)"
93+
CLASSPATH="$CLASSPATH:../../../lib/bcprov-jdk18on-$bc_version.jar:../../../lib/bctls-jdk18on-$bc_version.jar"
7294
else
7395
echo "Running crypto benchmark without Bouncy Castle due to download failure"
7496
fi
@@ -77,11 +99,9 @@ else
7799
fi
78100
fi
79101

80-
# Run the benchmark
81-
java -XX:-TieredCompilation -XX:ReservedCodeCacheSize=1024m -classpath $CLASSPATH -Dsun.boot.library.path=../../../lib/ CryptoBenchmark $@
102+
java -XX:-TieredCompilation -XX:ReservedCodeCacheSize=1024m -classpath "$CLASSPATH" -Dsun.boot.library.path=../../../lib/ CryptoBenchmark "$@"
82103

83-
# Always prompt for cleanup after benchmark completion if Bouncy Castle files exist
84-
if [ -f "../../../lib/bcprov-jdk18on-1.79.jar" ] && [ -f "../../../lib/bctls-jdk18on-1.79.jar" ]; then
104+
if ls "../../../lib/bcprov-jdk18on-"*".jar" "../../../lib/bctls-jdk18on-"*".jar" 2>/dev/null; then
85105
echo
86106
read -p "Would you like to remove the Bouncy Castle JARs? (y/n) " -n 1 -r
87107
echo

0 commit comments

Comments
 (0)