blob: b15921d61e00ce0045ea747a4b4c6081dba518a5 [file] [log] [blame]
Gaurav Shah52898d32010-02-17 16:37:33 -08001#!/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
9KEY_DIR=testkeys
10TESTCASE_DIR=testcases
11UTIL_DIR=../utils/
12TEST_FILE=test_file
13TEST_FILE_SIZE=1000000
14
15hash_algos=( sha1 sha256 sha512 )
16key_lengths=( 1024 2048 4096 8192 )
17
18# Generate public key signatures and digest on an input file for
19# various combinations of message digest algorithms and RSA key sizes.
20function generate_test_signatures {
21 algorithmcounter=0
22 for keylen in ${key_lengths[@]}
23 do
24 for hashalgo in ${hash_algos[@]}
25 do
26 openssl dgst -${hashalgo} -binary -out $1.${hashalgo}.digest $1
27 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \
28 -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \
29 > $1.rsa${keylen}_${hashalgo}.sig
30 let algorithmcounter=algorithmcounter+1
31 done
32 done
33}
34
35function pre_work {
36 # Generate a file with random bytes for signature tests.
37 echo "Generating test file..."
38 dd if=/dev/urandom of=${TESTCASE_DIR}/${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
39}
40
41if [ ! -d "$KEY_DIR" ]
42then
43 echo "You must run gen_test_cases.sh to generate test keys first."
44 exit 1
45fi
46
47if [ ! -d "$TESTCASE_DIR" ]
48then
49 mkdir "$TESTCASE_DIR"
50fi
51
52pre_work
53echo "Generating test signatures..."
54generate_test_signatures ${TESTCASE_DIR}/$TEST_FILE