|
2 | 2 |
|
3 | 3 | # set -x |
4 | 4 |
|
5 | | -dd if=/dev/urandom bs=1024 count=1 | head -c 1022 > text.bin |
6 | | - |
7 | 5 | echo "aesgcm-file-encrypt tests" |
| 6 | + |
8 | 7 | keyStr=$(cat /dev/urandom | base64 | head -c 32) |
9 | 8 | echo "key = $keyStr" |
10 | 9 |
|
11 | 10 | ivStr=$(cat /dev/urandom | base64 | head -c 16) |
12 | 11 | echo "IV = $ivStr" |
13 | 12 |
|
14 | 13 |
|
15 | | -res=$(./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i text.bin -o text2cipher.bin) |
16 | | -echo $res |
17 | | -res=$(./aesgcm-file-encrypt -d 256 -m 1 -k $keyStr -v $ivStr -i text2cipher.bin -o text2cipher2text.bin ) |
18 | | -echo $res |
| 14 | +if [[ "$1" == "-b" ]] || [[ "$1" == "--bench" ]]; then |
19 | 15 |
|
20 | | -diff -s text.bin text2cipher2text.bin > /dev/null |
21 | | -if [ $? -eq 0 ]; then |
22 | | - echo "Passed" |
23 | | -else |
24 | | - echo "Failed" |
25 | | -fi |
| 16 | + # Define an array of file sizes to test |
| 17 | + file_sizes=("10M" "50M" "100M" "500M" "1G") |
| 18 | + |
| 19 | + # Define the output CSV file and write the header row |
| 20 | + output_file="aesgcm_times.csv" |
| 21 | + |
| 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" |
| 30 | + |
| 31 | + echo "File Size, Encryption, Decryption, Encryption EVP, Decryption EVP" > "$output_file" |
26 | 32 |
|
27 | | -res=$(./aesgcm-file-encrypt -e 256 -m 2 -k $keyStr -v $ivStr -i text.bin -o text2cipher.evp.bin) |
28 | | -echo $res |
29 | | -res=$(./aesgcm-file-encrypt -d 256 -m 2 -k $keyStr -v $ivStr -i text2cipher.evp.bin -o text2cipher2text.evp.bin ) |
30 | | -echo $res |
31 | 33 |
|
32 | | -diff -s text.bin text2cipher2text.evp.bin > /dev/null |
33 | | -if [ $? -eq 0 ]; then |
34 | | - echo "Passed" |
| 34 | + # Loop over each file size and measure performance |
| 35 | + for size in "${file_sizes[@]}" |
| 36 | + 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* |
| 63 | + done |
35 | 64 | else |
36 | | - echo "Failed" |
| 65 | + # test a smaller file size (default option) |
| 66 | + dd if=/dev/urandom bs=1024 count=1 | head -c 1022 > text.bin |
| 67 | + res=$(./aesgcm-file-encrypt -e 256 -m 1 -k $keyStr -v $ivStr -i text.bin -o text2cipher.bin ) |
| 68 | + echo $res |
| 69 | + res=$(./aesgcm-file-encrypt -d 256 -m 1 -k $keyStr -v $ivStr -i text2cipher.bin -o text2cipher2text.bin ) |
| 70 | + echo $res |
| 71 | + |
| 72 | + diff -s text.bin text2cipher2text.bin > /dev/null |
| 73 | + if [ $? -eq 0 ]; then |
| 74 | + echo "Passed" |
| 75 | + else |
| 76 | + echo "Failed" |
| 77 | + fi |
| 78 | + rm text* |
37 | 79 | fi |
| 80 | + |
| 81 | +exit 0 |
0 commit comments