1#!/bin/bash
2
3# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Generate test cases for use for the RSA verify benchmark.
8
9# Load common constants and variables.
10. "$(dirname "$0")/common.sh"
11
12TEST_FILE=${TESTCASE_DIR}/test_file
13TEST_FILE_SIZE=1000000
14
15# Generate public key signatures on an input file for various combinations
16# of message digest algorithms and RSA key sizes.
17function generate_test_signatures {
18  echo "Generating test signatures..."
19  algorithmcounter=0
20  for keylen in ${key_lengths[@]}
21  do
22    for hashalgo in ${hash_algos[@]}
23    do
24      openssl dgst -${hashalgo} -binary ${TEST_FILE} > \
25        ${TEST_FILE}.${hashalgo}.digest
26      ${BIN_DIR}/signature_digest_utility $algorithmcounter  \
27        ${TEST_FILE} | openssl rsautl \
28        -sign -pkcs -inkey ${TESTKEY_DIR}/key_rsa${keylen}.pem \
29        > ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig
30      let algorithmcounter=algorithmcounter+1
31    done
32  done
33}
34
35# Generate a file with random bytes for signature tests.
36function generate_test_file {
37  echo "Generating test file..."
38  dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
39}
40
41mkdir -p ${TESTCASE_DIR}
42check_test_keys
43generate_test_file
44generate_test_signatures
45