summaryrefslogtreecommitdiff
path: root/automated/linux/openssl/openssl-speed.sh
blob: 431ab976e13c561e9975a3c634c765fc2a07582a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"

usage() {
    echo "Usage: $0 [-s <true|false>]" 1>&2
    exit 1
}

while getopts "s:" o; do
  case "$o" in
    s) SKIP_INSTALL="${OPTARG}" ;;
    *) usage ;;
  esac
done

! check_root && error_msg "You need to be root to run this script."
[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
mkdir -p "${OUTPUT}"

pkgs="openssl"
install_deps "${pkgs}" "${SKIP_INSTALL}"

# Record openssl vesion as it has a big impact on test reuslt.
openssl_version="$(openssl version | awk '{print $2}')"
add_metric "openssl-version" "pass" "${openssl_version}" "version"

# Test run.
cipher_commands="md5 sha1 sha256 sha512 des des-ede3 aes-128-cbc aes-192-cbc \
                aes-256-cbc rsa2048 dsa2048"
for test in ${cipher_commands}; do
    echo
    info_msg "Running openssl speed ${test} test"
    openssl speed "${test}" 2>&1 | tee "${OUTPUT}/${test}-output.txt"

    case "${test}" in
      # Parse asymmetric encryption output.
      rsa2048|dsa2048)
        awk -v test_case_id="${test}" 'match($1$2, test_case_id)
            {printf("%s-sign pass %s sign/s\n", test_case_id, $(NF-1));
            printf("%s-verify pass %s verify/s\n", test_case_id, $NF)}' \
            "${OUTPUT}/${test}-output.txt" | tee -a "${RESULT_FILE}"
        ;;
      # Parse symmetric encryption output.
      des|des-ede3|aes-128-cbc|aes-192-cbc|aes-256-cbc)
        awk -v test_case_id="${test}" \
            '/^Doing/ {printf("%s-%s pass %d bytes/s\n", test_case_id, $7, $7*$10/3)}' \
            "${OUTPUT}/${test}-output.txt" | tee -a "${RESULT_FILE}"
        ;;
      *)
        awk -v test_case_id="${test}" \
            '/^Doing/ {printf("%s-%s pass %d bytes/s\n", test_case_id, $6, $6*$9/3)}' \
            "${OUTPUT}/${test}-output.txt" | tee -a "${RESULT_FILE}"
        ;;
    esac
done