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 TEST_DIR=../tests/ |
| 16 |
| 17 # Color code output |
| 18 COL_YELLOW='\E[1;33m' |
| 19 COL_RED='\E[1;31m' |
| 20 COL_GREEN='\E[1;32m' |
| 21 COL_STOP='\E[0m' |
15 | 22 |
16 # Generate RSA test keys of various lengths. | 23 # Generate RSA test keys of various lengths. |
17 function generate_keys { | 24 function generate_keys { |
18 for i in ${key_lengths[@]} | 25 for i in ${key_lengths[@]} |
19 do | 26 do |
20 openssl genrsa -F4 -out key_rsa$i.pem $i | 27 openssl genrsa -F4 -out key_rsa$i.pem $i |
21 # Generate self-signed certificate from key. | 28 # Generate self-signed certificate from key. |
22 openssl req -batch -new -x509 -key key_rsa$i.pem -out key_rsa$i.crt | 29 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. | 30 # Generate pre-processed key for use by RSA signature verification code. |
24 ${UTIL_DIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb | 31 ${UTIL_DIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb |
(...skipping 22 matching lines...) Expand all Loading... |
47 for hashalgo in ${hash_algos[@]} | 54 for hashalgo in ${hash_algos[@]} |
48 do | 55 do |
49 echo "For RSA-$keylen and $hashalgo:" | 56 echo "For RSA-$keylen and $hashalgo:" |
50 ${UTIL_DIR}/verify_data $algorithmcounter key_rsa${keylen}.keyb \ | 57 ${UTIL_DIR}/verify_data $algorithmcounter key_rsa${keylen}.keyb \ |
51 ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} | 58 ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} |
52 let algorithmcounter=algorithmcounter+1 | 59 let algorithmcounter=algorithmcounter+1 |
53 done | 60 done |
54 done | 61 done |
55 } | 62 } |
56 | 63 |
| 64 function test_verification { |
| 65 algorithmcounter=0 |
| 66 for keylen in ${key_lengths[@]} |
| 67 do |
| 68 for hashalgo in ${hash_algos[@]} |
| 69 do |
| 70 echo -e "For ${COL_YELLOW}RSA-$keylen and $hashalgo${COL_STOP}:" |
| 71 cd ${UTIL_DIR} && ${TEST_DIR}/firmware_image_tests $algorithmcounter testk
eys/key_rsa8192.pem \ |
| 72 testkeys/key_rsa8192.keyb testkeys/key_rsa${keylen}.pem \ |
| 73 testkeys/key_rsa${keylen}.keyb |
| 74 let algorithmcounter=algorithmcounter+1 |
| 75 done |
| 76 done |
| 77 } |
| 78 |
57 function pre_work { | 79 function pre_work { |
58 # Generate a file with random bytes for signature tests. | 80 # Generate a file with random bytes for signature tests. |
59 echo "Generating test file..." | 81 echo "Generating test file..." |
60 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 | 82 dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1 |
61 echo "Generating test keys..." | 83 echo "Generating test keys..." |
62 generate_keys | 84 generate_keys |
63 echo "Generating signatures..." | 85 echo "Generating signatures..." |
64 generate_signatures $TEST_FILE | 86 generate_signatures $TEST_FILE |
65 } | 87 } |
66 | 88 |
67 function cleanup { | 89 function cleanup { |
68 rm ${TEST_FILE} ${TEST_FILE}.*.sig key_rsa*.* | 90 rm ${TEST_FILE} ${TEST_FILE}.*.sig key_rsa*.* |
69 } | 91 } |
70 | 92 |
71 echo "Testing message digests..." | 93 echo "Testing message digests..." |
72 ./sha_tests | 94 ./sha_tests |
73 | 95 |
74 echo | 96 echo |
75 echo "Testing signature verification..." | 97 echo "Testing signature verification..." |
76 pre_work | 98 #pre_work |
77 test_signatures | 99 test_signatures |
78 | 100 |
79 echo | 101 echo |
| 102 echo "Testing high-level image verification..." |
| 103 test_verification |
| 104 |
| 105 echo |
80 echo "Cleaning up..." | 106 echo "Cleaning up..." |
81 cleanup | 107 #cleanup |
82 | 108 |
83 | 109 |
OLD | NEW |