| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Run tests for cryptographic routine implementations - Message digests | 7 # Run tests for cryptographic routine implementations - Message digests |
| 8 # and RSA Signature verification. | 8 # and RSA Signature verification. |
| 9 | 9 |
| 10 hash_algos=( sha1 sha256 sha512 ) | 10 hash_algos=( sha1 sha256 sha512 ) |
| 11 key_lengths=( 1024 2048 4096 8192 ) | 11 key_lengths=( 1024 2048 4096 8192 ) |
| 12 TEST_FILE=test_file | 12 TEST_FILE=test_file |
| 13 TEST_FILE_SIZE=1000000 | 13 TEST_FILE_SIZE=1000000 |
| 14 UTIL_DIR=../utils/ | 14 UTIL_DIR=../utils/ |
| 15 | 15 KEY_DIR=testkeys |
| 16 # Generate RSA test keys of various lengths. | |
| 17 function generate_keys { | |
| 18 for i in ${key_lengths[@]} | |
| 19 do | |
| 20 openssl genrsa -F4 -out key_rsa$i.pem $i | |
| 21 # Generate self-signed certificate from key. | |
| 22 openssl req -batch -new -x509 -key key_rsa$i.pem -out key_rsa$i.crt | |
| 23 # Generate pre-processed key for use by RSA signature verification code. | |
| 24 ${UTIL_DIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb | |
| 25 done | |
| 26 } | |
| 27 | 16 |
| 28 # Generate public key signatures on an input file for various combinations | 17 # Generate public key signatures on an input file for various combinations |
| 29 # of message digest algorithms and RSA key sizes. | 18 # of message digest algorithms and RSA key sizes. |
| 30 function generate_signatures { | 19 function generate_signatures { |
| 31 algorithmcounter=0 | 20 algorithmcounter=0 |
| 32 for keylen in ${key_lengths[@]} | 21 for keylen in ${key_lengths[@]} |
| 33 do | 22 do |
| 34 for hashalgo in ${hash_algos[@]} | 23 for hashalgo in ${hash_algos[@]} |
| 35 do | 24 do |
| 36 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ | 25 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ |
| 37 -pkcs -inkey key_rsa${keylen}.pem > $1.rsa${keylen}\_${hashalgo}.sig | 26 -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \ |
| 27 > $1.rsa${keylen}\_${hashalgo}.sig |
| 38 let algorithmcounter=algorithmcounter+1 | 28 let algorithmcounter=algorithmcounter+1 |
| 39 done | 29 done |
| 40 done | 30 done |
| 41 } | 31 } |
| 42 | 32 |
| 43 function test_signatures { | 33 function test_signatures { |
| 44 algorithmcounter=0 | 34 algorithmcounter=0 |
| 45 for keylen in ${key_lengths[@]} | 35 for keylen in ${key_lengths[@]} |
| 46 do | 36 do |
| 47 for hashalgo in ${hash_algos[@]} | 37 for hashalgo in ${hash_algos[@]} |
| 48 do | 38 do |
| 49 echo "For RSA-$keylen and $hashalgo:" | 39 echo "For RSA-$keylen and $hashalgo:" |
| 50 ${UTIL_DIR}/verify_data $algorithmcounter key_rsa${keylen}.keyb \ | 40 ${UTIL_DIR}/verify_data $algorithmcounter \ |
| 51 ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} | 41 ${KEY_DIR}/key_rsa${keylen}.keyb \ |
| 42 ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig ${TEST_FILE} |
| 52 let algorithmcounter=algorithmcounter+1 | 43 let algorithmcounter=algorithmcounter+1 |
| 53 done | 44 done |
| 54 done | 45 done |
| 55 } | 46 } |
| 56 | 47 |
| 57 function pre_work { | 48 function pre_work { |
| 58 # Generate a file with random bytes for signature tests. | 49 # Generate a file with random bytes for signature tests. |
| 59 echo "Generating test file..." | 50 echo "Generating test file..." |
| 60 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 | 51 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 |
| 61 echo "Generating test keys..." | |
| 62 generate_keys | |
| 63 echo "Generating signatures..." | 52 echo "Generating signatures..." |
| 64 generate_signatures $TEST_FILE | 53 generate_signatures $TEST_FILE |
| 65 } | 54 } |
| 66 | 55 |
| 67 function cleanup { | 56 function cleanup { |
| 68 rm ${TEST_FILE} ${TEST_FILE}.*.sig key_rsa*.* | 57 rm ${TEST_FILE} ${TEST_FILE}.*.sig |
| 69 } | 58 } |
| 70 | 59 |
| 71 echo "Testing message digests..." | 60 echo "Testing message digests..." |
| 72 ./sha_tests | 61 ./sha_tests |
| 73 | 62 |
| 74 echo | 63 echo |
| 75 echo "Testing signature verification..." | 64 echo "Testing signature verification..." |
| 76 pre_work | 65 pre_work |
| 77 test_signatures | 66 test_signatures |
| 78 | 67 |
| 79 echo | 68 echo |
| 80 echo "Cleaning up..." | 69 echo "Cleaning up..." |
| 81 cleanup | 70 cleanup |
| 82 | 71 |
| 83 | 72 |
| OLD | NEW |