summaryrefslogtreecommitdiff
path: root/tests/gen_test_cases.sh
blob: 540fc2a281ad10e4d6d10f1f672d66e55726ab20 (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
#!/bin/bash

# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Generate test cases for use for the RSA verify benchmark.

# Load common constants and variables.
. "$(dirname "$0")/common.sh"

TEST_FILE=${TESTCASE_DIR}/test_file
TEST_FILE_SIZE=1000000

# Generate public key signatures on an input file for various combinations
# of message digest algorithms and RSA key sizes.
function generate_test_signatures {
  echo "Generating test signatures..."
  algorithmcounter=0
  for keylen in ${key_lengths[@]}
  do
    for hashalgo in ${hash_algos[@]}
    do
      openssl dgst -${hashalgo} -binary ${TEST_FILE} > \
        ${TEST_FILE}.${hashalgo}.digest
      ${BIN_DIR}/signature_digest_utility $algorithmcounter  \
        ${TEST_FILE} | openssl rsautl \
        -sign -pkcs -inkey ${TESTKEY_DIR}/key_rsa${keylen}.pem \
        > ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig
      let algorithmcounter=algorithmcounter+1
    done
  done
}

# Generate a file with random bytes for signature tests.
function generate_test_file {
  echo "Generating test file..."
  if [ -f "${TEST_FILE}" ]; then
    echo "(skipping, file already exists)"
    return
  fi
  dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
}

mkdir -p ${TESTCASE_DIR}
check_test_keys
generate_test_file
generate_test_signatures