Gaurav Shah | 52898d3 | 2010-02-17 16:37:33 -0800 | [diff] [blame] | 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 | KEY_DIR=testkeys |
| 10 | TESTCASE_DIR=testcases |
| 11 | UTIL_DIR=../utils/ |
| 12 | TEST_FILE=test_file |
| 13 | TEST_FILE_SIZE=1000000 |
| 14 | |
| 15 | hash_algos=( sha1 sha256 sha512 ) |
| 16 | key_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. |
| 20 | function 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 | |
| 35 | function 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 | |
| 41 | if [ ! -d "$KEY_DIR" ] |
| 42 | then |
| 43 | echo "You must run gen_test_cases.sh to generate test keys first." |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | if [ ! -d "$TESTCASE_DIR" ] |
| 48 | then |
| 49 | mkdir "$TESTCASE_DIR" |
| 50 | fi |
| 51 | |
| 52 | pre_work |
| 53 | echo "Generating test signatures..." |
| 54 | generate_test_signatures ${TESTCASE_DIR}/$TEST_FILE |