| 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 return_code=0 | 10 return_code=0 |
| 11 hash_algos=( sha1 sha256 sha512 ) | 11 hash_algos=( sha1 sha256 sha512 ) |
| 12 key_lengths=( 1024 2048 4096 8192 ) | 12 key_lengths=( 1024 2048 4096 8192 ) |
| 13 TEST_FILE=test_file | 13 TEST_FILE=test_file |
| 14 TEST_FILE_SIZE=1000000 | 14 TEST_FILE_SIZE=1000000 |
| 15 | 15 |
| 16 COL_RED='\E[31;1m' |
| 17 COL_GREEN='\E[32;1m' |
| 18 COL_YELLOW='\E[33;1m' |
| 19 COL_BLUE='\E[34;1m' |
| 20 COL_STOP='\E[0;m' |
| 21 |
| 16 # Generate public key signatures on an input file for various combinations | 22 # Generate public key signatures on an input file for various combinations |
| 17 # of message digest algorithms and RSA key sizes. | 23 # of message digest algorithms and RSA key sizes. |
| 18 function generate_signatures { | 24 function generate_signatures { |
| 19 algorithmcounter=0 | 25 algorithmcounter=0 |
| 20 for keylen in ${key_lengths[@]} | 26 for keylen in ${key_lengths[@]} |
| 21 do | 27 do |
| 22 for hashalgo in ${hash_algos[@]} | 28 for hashalgo in ${hash_algos[@]} |
| 23 do | 29 do |
| 24 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ | 30 ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ |
| 25 -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \ | 31 -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \ |
| 26 > $1.rsa${keylen}\_${hashalgo}.sig | 32 > $1.rsa${keylen}\_${hashalgo}.sig |
| 27 let algorithmcounter=algorithmcounter+1 | 33 let algorithmcounter=algorithmcounter+1 |
| 28 done | 34 done |
| 29 done | 35 done |
| 30 } | 36 } |
| 31 | 37 |
| 32 function test_signatures { | 38 function test_signatures { |
| 33 algorithmcounter=0 | 39 algorithmcounter=0 |
| 34 for keylen in ${key_lengths[@]} | 40 for keylen in ${key_lengths[@]} |
| 35 do | 41 do |
| 36 for hashalgo in ${hash_algos[@]} | 42 for hashalgo in ${hash_algos[@]} |
| 37 do | 43 do |
| 38 echo "For RSA-$keylen and $hashalgo:" | 44 echo -e "For ${COL_YELLOW}RSA-$keylen and $hashalgo${COL_STOP}:" |
| 39 ${UTIL_DIR}/verify_data $algorithmcounter \ | 45 ${UTIL_DIR}/verify_data $algorithmcounter \ |
| 40 ${KEY_DIR}/key_rsa${keylen}.keyb \ | 46 ${KEY_DIR}/key_rsa${keylen}.keyb \ |
| 41 ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig ${TEST_FILE} | 47 ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig ${TEST_FILE} |
| 42 if [ $? -ne 0 ] | 48 if [ $? -ne 0 ] |
| 43 then | 49 then |
| 44 return_code=255 | 50 return_code=255 |
| 45 fi | 51 fi |
| 46 let algorithmcounter=algorithmcounter+1 | 52 let algorithmcounter=algorithmcounter+1 |
| 47 done | 53 done |
| 48 done | 54 done |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 echo | 107 echo |
| 102 echo "Testing high-level image verification..." | 108 echo "Testing high-level image verification..." |
| 103 test_verification | 109 test_verification |
| 104 | 110 |
| 105 echo | 111 echo |
| 106 echo "Cleaning up..." | 112 echo "Cleaning up..." |
| 107 cleanup | 113 cleanup |
| 108 | 114 |
| 109 exit $return_code | 115 exit $return_code |
| 110 | 116 |
| OLD | NEW |