diff options
author | Gaurav Shah <gauravsh@google.com> | 2010-02-12 13:05:03 -0800 |
---|---|---|
committer | Gaurav Shah <gauravsh@google.com> | 2010-02-12 13:05:03 -0800 |
commit | 1a055adf7bb61ef239e554441defc13503eb2b51 (patch) | |
tree | 042e27df5639697e29824fa8534265ad6c50650a /tests/run_rsa_tests.sh | |
parent | cc1dd99ae75549ea58170cb13bcc8636625a46c6 (diff) | |
download | vboot-1a055adf7bb61ef239e554441defc13503eb2b51.tar.gz |
VBoot Reference: Make RSA verification test script return the right error code.
Also rename and modify run_tests.sh to only run the RSA verification tests. The SHA message digest tests must now be invoked separately.
Review URL: http://codereview.chromium.org/596080
Diffstat (limited to 'tests/run_rsa_tests.sh')
-rwxr-xr-x | tests/run_rsa_tests.sh | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/run_rsa_tests.sh b/tests/run_rsa_tests.sh new file mode 100755 index 00000000..3abadb6b --- /dev/null +++ b/tests/run_rsa_tests.sh @@ -0,0 +1,88 @@ +#!/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. + +# Run tests for cryptographic routine implementations - Message digests +# and RSA Signature verification. + +return_code=0 +hash_algos=( sha1 sha256 sha512 ) +key_lengths=( 1024 2048 4096 8192 ) +TEST_FILE=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_signatures { + algorithmcounter=0 + for keylen in ${key_lengths[@]} + do + for hashalgo in ${hash_algos[@]} + do + ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ + -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \ + > $1.rsa${keylen}\_${hashalgo}.sig + let algorithmcounter=algorithmcounter+1 + done + done +} + +function test_signatures { + algorithmcounter=0 + for keylen in ${key_lengths[@]} + do + for hashalgo in ${hash_algos[@]} + do + echo "For RSA-$keylen and $hashalgo:" + ${UTIL_DIR}/verify_data $algorithmcounter \ + ${KEY_DIR}/key_rsa${keylen}.keyb \ + ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig ${TEST_FILE} + if [ $? -ne 0 ] + then + return_code=255 + fi + let algorithmcounter=algorithmcounter+1 + done + done +} + +function pre_work { + # Generate a file with random bytes for signature tests. + echo "Generating test file..." + dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 + echo "Generating signatures..." + generate_signatures $TEST_FILE +} + +function cleanup { + rm ${TEST_FILE} ${TEST_FILE}.*.sig +} + +# Determine script directory. +if [[ $0 == '/'* ]]; +then + SCRIPT_DIR="`dirname $0`" +elif [[ $0 == './'* ]]; +then + SCRIPT_DIR="`pwd`" +else + SCRIPT_DIR="`pwd`"/"`dirname $0`" +fi +UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils +KEY_DIR=${SCRIPT_DIR}/testkeys + +echo "Generating test cases..." +pre_work + +echo +echo "Testing signature verification..." +test_signatures + +echo +echo "Cleaning up..." +cleanup + +exit $return_code + |