|
3 | 3 | # set -x |
4 | 4 |
|
5 | 5 | echo "aesgcm-file-encrypt tests" |
| 6 | +echo "./aesgcm-file-encrypt -b to run benchmark after building wolfSSL with" |
| 7 | +echo "./configure --enable-aesgcm-stream && sudo make install" |
| 8 | + |
| 9 | +# Define the output CSV file |
| 10 | +output_file="aesgcm_times.csv" |
| 11 | +output_file_header="aesgcm_times_header.csv" |
| 12 | +partition="/dev/nvme0n1p8" |
6 | 13 |
|
7 | 14 | keyStr=$(cat /dev/urandom | base64 | head -c 32) |
8 | 15 | echo "key = $keyStr" |
9 | 16 |
|
10 | 17 | ivStr=$(cat /dev/urandom | base64 | head -c 16) |
11 | 18 | echo "IV = $ivStr" |
12 | 19 |
|
13 | | - |
14 | 20 | if [[ "$1" == "-b" ]] || [[ "$1" == "--bench" ]]; then |
| 21 | + cp "$output_file" "$output_file.back" |
| 22 | + echo "File-size,Buffer-size,AES-256-GCM-enc,AES-256-GCM-dec" > "$output_file" |
15 | 23 |
|
16 | | - # Define an array of file sizes to test |
17 | | - file_sizes=("10M" "50M" "100M" "500M" "1G") |
| 24 | + buffer_sizes=("32" "64" "128" "256" "512" "1024" "2048" "4096" "8192" "12288" "20480" "1073741824") |
18 | 25 |
|
19 | | - # Define the output CSV file and write the header row |
20 | | - output_file="aesgcm_times.csv" |
| 26 | + for b_size in "${buffer_sizes[@]}" |
| 27 | + do |
| 28 | + rm aesgcm-file-encrypt text* |
| 29 | + make clean |
| 30 | + make CPPFLAGS="-DMAX_BUFFER_SIZE=$b_size -DMIN_BUFFER_SIZE=32" aesgcm-file-encrypt |
21 | 31 |
|
22 | | - echo "System Information:" > "$output_file" |
23 | | - echo "--------------------" >> "$output_file" |
24 | | - echo "Hostname: $(hostname)" >> "$output_file" |
25 | | - echo "Kernel Version: $(uname -r)" >> "$output_file" |
26 | | - echo "Processor Type: $(uname -m)" >> "$output_file" |
27 | | - echo "Operating System: $(lsb_release -d | awk '{print $2,$3,$4,$5}')" >> "$output_file" |
28 | | - echo "CPU Info: $(lscpu | grep 'Model name' | cut -d':' -f2 | sed 's/^ //')" >> "$output_file" |
29 | | - echo "Memory Info: $(free -h | grep 'Mem' | awk '{print $2}')" >> "$output_file" |
| 32 | + # Define an array of file sizes to test |
30 | 33 |
|
31 | | - echo "File Size, Encryption, Decryption, Encryption EVP, Decryption EVP" > "$output_file" |
| 34 | + file_sizes=("10M" "50M" "100M" "500M" "1G") |
32 | 35 |
|
| 36 | + echo "System Information:" > "$output_file_header" |
| 37 | + echo "--------------------" >> "$output_file_header" |
| 38 | + echo "Hostname: $(hostname)" >> "$output_file_header" |
| 39 | + echo "Kernel Version: $(uname -r)" >> "$output_file_header" |
| 40 | + echo "Processor Type: $(uname -m)" >> "$output_file_header" |
| 41 | + echo "Operating System: $(lsb_release -d | awk '{print $2,$3,$4,$5}')" >> "$output_file_header" |
| 42 | + echo "CPU Info: $(lscpu | grep 'Model name' | cut -d':' -f2 | sed 's/^ //')" >> "$output_file_header" |
| 43 | + echo "Memory Info: $(free -h | grep 'Mem' | awk '{print $2}')" >> "$output_file_header" |
| 44 | + echo "The page size is: $(sudo blockdev --getbsz $partition) bytes." >> "$output_file_header" |
| 45 | + echo "The sector size of the disk is: $(sudo blockdev --getss $partition) bytes." >> "$output_file_header" |
33 | 46 |
|
34 | 47 | # Loop over each file size and measure performance |
35 | 48 | for size in "${file_sizes[@]}" |
36 | 49 | do |
37 | | - # Generate a test file of the given size |
38 | | - text_file=text_"$size".bin |
39 | | - dd if=/dev/urandom of=$text_file bs=$size count=1 conv=fsync |
40 | | - |
41 | | - 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 )" |
42 | | - 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 )" |
43 | | - |
44 | | - diff -s $text_file text2cipher2text.bin > /dev/null |
45 | | - if [ $? -eq 0 ]; then |
46 | | - echo "Passed $t_aesgcm_e $t_aesgcm_d" |
47 | | - else |
48 | | - echo "Failed" |
49 | | - fi |
50 | | - |
51 | | - 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 )" |
52 | | - 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 )" |
53 | | - |
54 | | - diff -s $text_file text2cipher2text.evp.bin > /dev/null |
55 | | - if [ $? -eq 0 ]; then |
56 | | - echo "Passed $t_evpgcm_e $t_evpgcm_d" |
57 | | - else |
58 | | - echo "Failed" |
59 | | - fi |
60 | | - |
61 | | - echo "$size, $t_aesgcm_e,$t_aesgcm_d,$t_evpgcm_e,$t_evpgcm_d" >> "$output_file" |
62 | | - rm text* |
| 50 | + # Generate a test file of the given size |
| 51 | + text_file=text_"$size".bin |
| 52 | + dd if=/dev/urandom of=$text_file bs=$size count=1 conv=fsync |
| 53 | + |
| 54 | + 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 )" |
| 55 | + 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 )" |
| 56 | + |
| 57 | + diff -s $text_file text2cipher2text.bin > /dev/null |
| 58 | + if [ $? -eq 0 ]; then |
| 59 | + echo "Passed $t_aesgcm_e $t_aesgcm_d" |
| 60 | + else |
| 61 | + echo "Failed" |
| 62 | + fi |
| 63 | + echo "$size,$b_size,$t_aesgcm_e,$t_aesgcm_d" >> "$output_file" |
| 64 | + rm text* |
63 | 65 | done |
| 66 | + done |
64 | 67 | else |
| 68 | + rm aesgcm-file-encrypt text* |
| 69 | + make clean |
| 70 | + make CPPFLAGS="-DMAX_BUFFER_SIZE=4096" aesgcm-file-encrypt |
65 | 71 | # test a smaller file size (default option) |
66 | 72 | dd if=/dev/urandom bs=1024 count=1 | head -c 1022 > text.bin |
67 | 73 | res=$(./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i text.bin -o text2cipher.bin ) |
|
78 | 84 | rm text* |
79 | 85 | fi |
80 | 86 |
|
| 87 | +if true; then |
| 88 | + input_file="$output_file" |
| 89 | + output_file_sorted="data.csv" |
| 90 | + |
| 91 | + awk -F, 'function to_bytes(x) { |
| 92 | + split(x, a, /[^0-9.]+/); |
| 93 | + return a[1] * (index("KMGT", substr(x, length(a[1]) + 1)) * 1024 ^ (index("KMGT", substr(x, length(a[1]) + 1)) - 1)); |
| 94 | + } |
| 95 | + NR == 1 { gsub(",", " "); print $0; next } |
| 96 | + { line = $1; for (i = 2; i <= NF; i++) line = line "," $i; print to_bytes($1) "," line }' "$input_file" | |
| 97 | + sort -t, -k2,2n -k3,3n | awk -F, 'NR == 1 { print $0 } NR > 1 { $1=""; $0=substr($0, 2); print }' > "$output_file_sorted" |
| 98 | + |
| 99 | + sed -i 's/1073741824/1G/g' "$output_file_sorted" |
| 100 | + ./plot_data.gp |
| 101 | +fi |
| 102 | + |
| 103 | + |
81 | 104 | exit 0 |
0 commit comments