xref: /aosp_15_r20/external/vboot_reference/tests/gen_test_cases.sh (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1#!/bin/bash
2
3# Copyright 2010 The ChromiumOS Authors
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      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  if [ -f "${TEST_FILE}" ]; then
39    echo "(skipping, file already exists)"
40    return
41  fi
42  dd if=/dev/urandom of="${TEST_FILE}" bs="${TEST_FILE_SIZE}" count=1
43}
44
45mkdir -p "${TESTCASE_DIR}"
46check_test_keys
47generate_test_file
48generate_test_signatures
49