Add Benchmark scripts
parent
5fe398b424
commit
ef14ade6d8
|
|
@ -34,9 +34,18 @@
|
|||
#ifndef WOLFCRYPT_MAGIC
|
||||
#define WOLFCRYPT_MAGIC "WOLFSSL"
|
||||
#endif
|
||||
/*
|
||||
MIN_BUFFER_SIZE of less than
|
||||
*/
|
||||
#ifndef MIN_BUFFER_SIZE
|
||||
#define MIN_BUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
/*
|
||||
For optimum performance, MAX_BUFFER_SIZE should be >= page_size and less than
|
||||
system memory in order to prevent memory fragmentation,better work with MMU
|
||||
memory alignments, leverage cache speedup, and minimize OS overhead.
|
||||
*/
|
||||
#ifndef MAX_BUFFER_SIZE
|
||||
/* Use upto 1 GByte of RAM */
|
||||
#define MAX_BUFFER_SIZE (1 << 30)
|
||||
|
|
@ -92,6 +101,10 @@ static size_t get_optimal_buffer_sz(int fd, size_t memory_size)
|
|||
optimal_size = block_size;
|
||||
file_size = get_file_sz(fd);
|
||||
|
||||
if (optimal_size > MAX_BUFFER_SIZE) {
|
||||
optimal_size = MAX_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
while (optimal_size * 2 <= memory_size &&
|
||||
optimal_size * 2 <= MAX_BUFFER_SIZE &&
|
||||
optimal_size <= file_size) {
|
||||
|
|
@ -298,8 +311,8 @@ exit:
|
|||
\param out_file file name to hold plain text
|
||||
\param key_str key must be 32 Bytes
|
||||
*/
|
||||
int decrypt_file_AesGCM(const char* in_file, const char* out_file,
|
||||
const char* key_str)
|
||||
int decrypt_file_AesGCM(const char *in_file, const char *out_file,
|
||||
const char *key_str)
|
||||
{
|
||||
byte* in_buf;
|
||||
byte* out_buf;
|
||||
|
|
@ -433,8 +446,9 @@ exit:
|
|||
}
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
int encrypt_file(const char* in_file, const char* out_file,
|
||||
const char* key_str, const char *iv_str)
|
||||
what
|
||||
int encrypt_file(const char *in_file, const char *out_file,
|
||||
const char *key_str, const char *iv_str)
|
||||
{
|
||||
int in_fd;
|
||||
int in_len;
|
||||
|
|
@ -713,15 +727,15 @@ exit:
|
|||
|
||||
int sanityTest_default(int file_sz) {
|
||||
|
||||
const char* cmd_enc ="./aesgcm-file-encrypt -e 256 -m 1 \
|
||||
const char *cmd_enc ="./aesgcm-file-encrypt -e 256 -m 1 \
|
||||
-k 77CF00EC060192530B5D06B6B426799B \
|
||||
-v 77CF00EC060192530B5D06B6B426799B \
|
||||
-i text.bin -o text2cipher.bin";
|
||||
const char* cmd_dec ="./aesgcm-file-encrypt -d 256 -m 1 \
|
||||
const char *cmd_dec ="./aesgcm-file-encrypt -d 256 -m 1 \
|
||||
-k 77CF00EC060192530B5D06B6B426799B \
|
||||
-i text2cipher.bin -o text2cipher2text.bin";
|
||||
const char* cmd_diff = "diff -q text.bin text2cipher2text.bin";
|
||||
char buffer[MIN_BUFFER_SIZE];
|
||||
const char *cmd_diff = "diff -q text.bin text2cipher2text.bin";
|
||||
char buffer[1024];
|
||||
|
||||
sprintf(buffer,"dd if=/dev/urandom bs=1024 count=%d | head -c %d > \
|
||||
text.bin", (file_sz/1024)+1, file_sz);
|
||||
|
|
@ -747,15 +761,15 @@ text.bin", (file_sz/1024)+1, file_sz);
|
|||
pclose(pipe);
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
const char* cmd_enc_evp ="./aesgcm-file-encrypt -e 256 -m 1 \
|
||||
const char *cmd_enc_evp ="./aesgcm-file-encrypt -e 256 -m 1 \
|
||||
-k 77CF00EC060192530B5D06B6B426799B \
|
||||
-v 77CF00EC060192530B5D06B6B426799B \
|
||||
-i text.bin -o text2cipher.evp.bin";
|
||||
const char* cmd_dec_evp ="./aesgcm-file-encrypt -d 256 -m 1 \
|
||||
const char *cmd_dec_evp ="./aesgcm-file-encrypt -d 256 -m 1 \
|
||||
-k 77CF00EC060192530B5D06B6B426799B \
|
||||
-i text2cipher.evp.bin -o text2cipher2text.evp.bin";
|
||||
const char* cmd_diff_evp = "diff -q text.bin text2cipher2text.evp.bin";
|
||||
const char* cmd_diff_gcm_evp = "diff -q text2cipher2text.bin \
|
||||
const char *cmd_diff_evp = "diff -q text.bin text2cipher2text.evp.bin";
|
||||
const char *cmd_diff_gcm_evp = "diff -q text2cipher2text.bin \
|
||||
text2cipher2text.evp.bin";
|
||||
|
||||
if (system(cmd_enc_evp) != 0 || system(cmd_dec_evp) != 0 ) {
|
||||
|
|
@ -821,10 +835,10 @@ test will create three files:text.bin, cipher, decrypted plain. \n");
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* inFile = NULL;
|
||||
const char* ivStr = NULL;
|
||||
const char* keyStr = NULL;
|
||||
const char* outFile = NULL;
|
||||
const char *inFile = NULL;
|
||||
const char *ivStr = NULL;
|
||||
const char *keyStr = NULL;
|
||||
const char *outFile = NULL;
|
||||
int file_sz = 0;
|
||||
int key_sz = 0;
|
||||
int method = 0;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@
|
|||
# set -x
|
||||
|
||||
echo "aesgcm-file-encrypt tests"
|
||||
echo "./aesgcm-file-encrypt -b to run benchmark after building wolfSSL with"
|
||||
echo "./configure --enable-aesgcm-stream && sudo make install"
|
||||
|
||||
# Define the output CSV file
|
||||
output_file="aesgcm_times.csv"
|
||||
output_file_header="aesgcm_times_header.csv"
|
||||
partition="/dev/nvme0n1p8"
|
||||
|
||||
keyStr=$(cat /dev/urandom | base64 | head -c 32)
|
||||
echo "key = $keyStr"
|
||||
|
|
@ -10,58 +17,57 @@ echo "key = $keyStr"
|
|||
ivStr=$(cat /dev/urandom | base64 | head -c 16)
|
||||
echo "IV = $ivStr"
|
||||
|
||||
|
||||
if [[ "$1" == "-b" ]] || [[ "$1" == "--bench" ]]; then
|
||||
cp "$output_file" "$output_file.back"
|
||||
echo "File-size,Buffer-size,AES-256-GCM-enc,AES-256-GCM-dec" > "$output_file"
|
||||
|
||||
buffer_sizes=("32" "64" "128" "256" "512" "1024" "2048" "4096" "8192" "12288" "20480" "1073741824")
|
||||
|
||||
for b_size in "${buffer_sizes[@]}"
|
||||
do
|
||||
rm aesgcm-file-encrypt text*
|
||||
make clean
|
||||
make CPPFLAGS="-DMAX_BUFFER_SIZE=$b_size -DMIN_BUFFER_SIZE=32" aesgcm-file-encrypt
|
||||
|
||||
# Define an array of file sizes to test
|
||||
|
||||
file_sizes=("10M" "50M" "100M" "500M" "1G")
|
||||
|
||||
# Define the output CSV file and write the header row
|
||||
output_file="aesgcm_times.csv"
|
||||
|
||||
echo "System Information:" > "$output_file"
|
||||
echo "--------------------" >> "$output_file"
|
||||
echo "Hostname: $(hostname)" >> "$output_file"
|
||||
echo "Kernel Version: $(uname -r)" >> "$output_file"
|
||||
echo "Processor Type: $(uname -m)" >> "$output_file"
|
||||
echo "Operating System: $(lsb_release -d | awk '{print $2,$3,$4,$5}')" >> "$output_file"
|
||||
echo "CPU Info: $(lscpu | grep 'Model name' | cut -d':' -f2 | sed 's/^ //')" >> "$output_file"
|
||||
echo "Memory Info: $(free -h | grep 'Mem' | awk '{print $2}')" >> "$output_file"
|
||||
|
||||
echo "File Size, Encryption, Decryption, Encryption EVP, Decryption EVP" > "$output_file"
|
||||
|
||||
echo "System Information:" > "$output_file_header"
|
||||
echo "--------------------" >> "$output_file_header"
|
||||
echo "Hostname: $(hostname)" >> "$output_file_header"
|
||||
echo "Kernel Version: $(uname -r)" >> "$output_file_header"
|
||||
echo "Processor Type: $(uname -m)" >> "$output_file_header"
|
||||
echo "Operating System: $(lsb_release -d | awk '{print $2,$3,$4,$5}')" >> "$output_file_header"
|
||||
echo "CPU Info: $(lscpu | grep 'Model name' | cut -d':' -f2 | sed 's/^ //')" >> "$output_file_header"
|
||||
echo "Memory Info: $(free -h | grep 'Mem' | awk '{print $2}')" >> "$output_file_header"
|
||||
echo "The page size is: $(sudo blockdev --getbsz $partition) bytes." >> "$output_file_header"
|
||||
echo "The sector size of the disk is: $(sudo blockdev --getss $partition) bytes." >> "$output_file_header"
|
||||
|
||||
# Loop over each file size and measure performance
|
||||
for size in "${file_sizes[@]}"
|
||||
do
|
||||
# Generate a test file of the given size
|
||||
text_file=text_"$size".bin
|
||||
dd if=/dev/urandom of=$text_file bs=$size count=1 conv=fsync
|
||||
# Generate a test file of the given size
|
||||
text_file=text_"$size".bin
|
||||
dd if=/dev/urandom of=$text_file bs=$size count=1 conv=fsync
|
||||
|
||||
t_aesgcm_e="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i $text_file -o text2cipher.bin > /dev/null 2>&1) 2>&1 )"
|
||||
t_aesgcm_d="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -d 256 -m 1 -k $keyStr -v $ivStr -i text2cipher.bin -o text2cipher2text.bin > /dev/null 2>&1) 2>&1 )"
|
||||
t_aesgcm_e="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i $text_file -o text2cipher.bin > /dev/null 2>&1) 2>&1 )"
|
||||
t_aesgcm_d="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -d 256 -m 1 -k $keyStr -v $ivStr -i text2cipher.bin -o text2cipher2text.bin > /dev/null 2>&1) 2>&1 )"
|
||||
|
||||
diff -s $text_file text2cipher2text.bin > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Passed $t_aesgcm_e $t_aesgcm_d"
|
||||
else
|
||||
echo "Failed"
|
||||
fi
|
||||
|
||||
t_evpgcm_e="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -e 256 -m 2 -k $keyStr -v $ivStr -i $text_file -o text2cipher.evp.bin > /dev/null 2>&1) 2>&1 )"
|
||||
t_evpgcm_d="$( TIMEFORMAT="%R";time (./aesgcm-file-encrypt -d 256 -m 2 -k $keyStr -v $ivStr -i text2cipher.evp.bin -o text2cipher2text.evp.bin > /dev/null 2>&1) 2>&1 )"
|
||||
|
||||
diff -s $text_file text2cipher2text.evp.bin > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Passed $t_evpgcm_e $t_evpgcm_d"
|
||||
else
|
||||
echo "Failed"
|
||||
fi
|
||||
|
||||
echo "$size, $t_aesgcm_e,$t_aesgcm_d,$t_evpgcm_e,$t_evpgcm_d" >> "$output_file"
|
||||
rm text*
|
||||
diff -s $text_file text2cipher2text.bin > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Passed $t_aesgcm_e $t_aesgcm_d"
|
||||
else
|
||||
echo "Failed"
|
||||
fi
|
||||
echo "$size,$b_size,$t_aesgcm_e,$t_aesgcm_d" >> "$output_file"
|
||||
rm text*
|
||||
done
|
||||
done
|
||||
else
|
||||
rm aesgcm-file-encrypt text*
|
||||
make clean
|
||||
make CPPFLAGS="-DMAX_BUFFER_SIZE=4096" aesgcm-file-encrypt
|
||||
# test a smaller file size (default option)
|
||||
dd if=/dev/urandom bs=1024 count=1 | head -c 1022 > text.bin
|
||||
res=$(./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i text.bin -o text2cipher.bin )
|
||||
|
|
@ -78,4 +84,21 @@ else
|
|||
rm text*
|
||||
fi
|
||||
|
||||
if true; then
|
||||
input_file="$output_file"
|
||||
output_file_sorted="data.csv"
|
||||
|
||||
awk -F, 'function to_bytes(x) {
|
||||
split(x, a, /[^0-9.]+/);
|
||||
return a[1] * (index("KMGT", substr(x, length(a[1]) + 1)) * 1024 ^ (index("KMGT", substr(x, length(a[1]) + 1)) - 1));
|
||||
}
|
||||
NR == 1 { gsub(",", " "); print $0; next }
|
||||
{ line = $1; for (i = 2; i <= NF; i++) line = line "," $i; print to_bytes($1) "," line }' "$input_file" |
|
||||
sort -t, -k2,2n -k3,3n | awk -F, 'NR == 1 { print $0 } NR > 1 { $1=""; $0=substr($0, 2); print }' > "$output_file_sorted"
|
||||
|
||||
sed -i 's/1073741824/1G/g' "$output_file_sorted"
|
||||
./plot_data.gp
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/gnuplot
|
||||
|
||||
# Function to get the number of lines in the file
|
||||
filelines(file) = system(sprintf("awk 'END {print NR}' %s", file))
|
||||
|
||||
# Get the number of lines in the data file
|
||||
datafile = "data.csv"
|
||||
nlines = int(filelines(datafile)) - 1
|
||||
# you can adjust the number of rows you want to ply
|
||||
chunk_size = 12
|
||||
|
||||
# Set the terminal type
|
||||
set term png
|
||||
|
||||
# Set the title, style, and key settings
|
||||
set title "wolfSSL"
|
||||
set style fill solid 1.00 border lt -1
|
||||
set style histogram clustered gap 4 title textcolor lt -1
|
||||
set datafile missing '-'
|
||||
set style data histograms
|
||||
|
||||
# Set x-axis settings
|
||||
set xtics border in scale 0,0 nomirror rotate by -45 autojustify
|
||||
set xtics norangelimit
|
||||
set xtics ()
|
||||
set format y '%.0s%c'
|
||||
|
||||
set lmargin at screen 0.15
|
||||
set rmargin at screen 0.90
|
||||
|
||||
#set bmargin at screen 0.10
|
||||
set tmargin at screen 0.90
|
||||
|
||||
# Set legend position
|
||||
#set key outside below
|
||||
set key autotitle columnhead noenhanced
|
||||
|
||||
# Set grid settings
|
||||
set grid mxtics mytics
|
||||
set grid x y
|
||||
|
||||
# Set titles for x and y axes
|
||||
set xlabel "FileSize-BufferSize (Bytes)"
|
||||
set ylabel "Total time (Seconds)"
|
||||
|
||||
# Uncomment and set xrange and yrange if necessary
|
||||
# set xrange [lower:upper]
|
||||
# set yrange [lower:upper]
|
||||
|
||||
# Loop through the data file, plotting 12 rows at a time
|
||||
|
||||
do for [i=0:int((nlines-1)/chunk_size)] {
|
||||
# Set the output file name
|
||||
set output sprintf("output_%03d.png", i + 1)
|
||||
|
||||
# Calculate start and end rows for the current chunk
|
||||
start = 0 + i * chunk_size
|
||||
end = start + chunk_size - 1
|
||||
|
||||
# Plot the data from the CSV file for the current chunk
|
||||
plot for [col=3:*] for [filename in datafile] filename using col:xticlabels(strcol(1)."-".strcol(2)) every ::start::end with linespoints
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue