| 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 UTILDIR=../utils/ | 14 UTIL_DIR=../utils/ |
| 15 | 15 |
| 16 # Generate RSA test keys of various lengths. | 16 # Generate RSA test keys of various lengths. |
| 17 function generate_keys { | 17 function generate_keys { |
| 18 for i in ${key_lengths[@]} | 18 for i in ${key_lengths[@]} |
| 19 do | 19 do |
| 20 openssl genrsa -F4 -out key_rsa$i.pem $i | 20 openssl genrsa -F4 -out key_rsa$i.pem $i |
| 21 # Generate self-signed certificate from key. | 21 # Generate self-signed certificate from key. |
| 22 openssl req -batch -new -x509 -key key_rsa$i.pem -out key_rsa$i.crt | 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. | 23 # Generate pre-processed key for use by RSA signature verification code. |
| 24 ${UTILDIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb | 24 ${UTIL_DIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb |
| 25 done | 25 done |
| 26 } | 26 } |
| 27 | 27 |
| 28 # Generate public key signatures on an input file for various combinations | 28 # Generate public key signatures on an input file for various combinations |
| 29 # of message digest algorithms and RSA key sizes. | 29 # of message digest algorithms and RSA key sizes. |
| 30 function generate_signatures { | 30 function generate_signatures { |
| 31 algorithmcounter=0 | 31 algorithmcounter=0 |
| 32 for keylen in ${key_lengths[@]} | 32 for keylen in ${key_lengths[@]} |
| 33 do | 33 do |
| 34 for hashalgo in ${hash_algos[@]} | 34 for hashalgo in ${hash_algos[@]} |
| 35 do | 35 do |
| 36 ./signature_digest $algorithmcounter $1 | openssl rsautl -sign -pkcs \ | 36 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ |
| 37 -inkey key_rsa${keylen}.pem > $1.rsa${keylen}\_${hashalgo}.sig | 37 -pkcs -inkey key_rsa${keylen}.pem > $1.rsa${keylen}\_${hashalgo}.sig |
| 38 let algorithmcounter=algorithmcounter+1 | 38 let algorithmcounter=algorithmcounter+1 |
| 39 done | 39 done |
| 40 done | 40 done |
| 41 } | 41 } |
| 42 | 42 |
| 43 function test_signatures { | 43 function test_signatures { |
| 44 algorithmcounter=0 | 44 algorithmcounter=0 |
| 45 for keylen in ${key_lengths[@]} | 45 for keylen in ${key_lengths[@]} |
| 46 do | 46 do |
| 47 for hashalgo in ${hash_algos[@]} | 47 for hashalgo in ${hash_algos[@]} |
| 48 do | 48 do |
| 49 echo "For RSA-$keylen and $hashalgo:" | 49 echo "For RSA-$keylen and $hashalgo:" |
| 50 ./verify_data $algorithmcounter key_rsa${keylen}.keyb \ | 50 ${UTIL_DIR}/verify_data $algorithmcounter key_rsa${keylen}.keyb \ |
| 51 ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} | 51 ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} |
| 52 let algorithmcounter=algorithmcounter+1 | 52 let algorithmcounter=algorithmcounter+1 |
| 53 done | 53 done |
| 54 done | 54 done |
| 55 } | 55 } |
| 56 | 56 |
| 57 function pre_work { | 57 function pre_work { |
| 58 # Generate a file with random bytes for signature tests. | 58 # Generate a file with random bytes for signature tests. |
| 59 echo "Generating test file..." | 59 echo "Generating test file..." |
| 60 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 | 60 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 echo | 74 echo |
| 75 echo "Testing signature verification..." | 75 echo "Testing signature verification..." |
| 76 pre_work | 76 pre_work |
| 77 test_signatures | 77 test_signatures |
| 78 | 78 |
| 79 echo | 79 echo |
| 80 echo "Cleaning up..." | 80 echo "Cleaning up..." |
| 81 cleanup | 81 cleanup |
| 82 | 82 |
| 83 | 83 |
| OLD | NEW |