OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Timing benchmark for verifying a firmware image. | 5 * Timing benchmark for verifying a firmware image. |
6 */ | 6 */ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 uint8_t* firmware_sign_key = NULL; | 42 uint8_t* firmware_sign_key = NULL; |
43 uint8_t* root_key_blob = NULL; | 43 uint8_t* root_key_blob = NULL; |
44 char firmware_sign_key_file[FILE_NAME_SIZE]; | 44 char firmware_sign_key_file[FILE_NAME_SIZE]; |
45 char file_name[FILE_NAME_SIZE]; | 45 char file_name[FILE_NAME_SIZE]; |
46 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ | 46 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ |
47 "sha1", "sha256", "sha512", /* RSA-1024 */ | 47 "sha1", "sha256", "sha512", /* RSA-1024 */ |
48 "sha1", "sha256", "sha512", /* RSA-2048 */ | 48 "sha1", "sha256", "sha512", /* RSA-2048 */ |
49 "sha1", "sha256", "sha512", /* RSA-4096 */ | 49 "sha1", "sha256", "sha512", /* RSA-4096 */ |
50 "sha1", "sha256", "sha512", /* RSA-8192 */ | 50 "sha1", "sha256", "sha512", /* RSA-8192 */ |
51 }; | 51 }; |
| 52 uint8_t* verification_blobs[NUM_SIZES_TO_TEST]; |
52 uint8_t* firmware_blobs[NUM_SIZES_TO_TEST]; | 53 uint8_t* firmware_blobs[NUM_SIZES_TO_TEST]; |
53 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) | 54 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) |
54 firmware_blobs[i] = NULL; | 55 firmware_blobs[i] = NULL; |
55 | 56 |
56 key_size = siglen_map[algorithm] * 8; /* in bits. */ | 57 key_size = siglen_map[algorithm] * 8; /* in bits. */ |
57 snprintf(firmware_sign_key_file, FILE_NAME_SIZE, "testkeys/key_rsa%d.pem", | 58 snprintf(firmware_sign_key_file, FILE_NAME_SIZE, "testkeys/key_rsa%d.pem", |
58 key_size); | 59 key_size); |
59 | 60 |
60 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size); | 61 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size); |
61 firmware_sign_key = BufferFromFile(file_name, &len); | 62 firmware_sign_key = BufferFromFile(file_name, &len); |
62 if (!firmware_sign_key) { | 63 if (!firmware_sign_key) { |
63 debug("Couldn't read pre-processed firmware signing key.\n"); | 64 debug("Couldn't read pre-processed firmware signing key.\n"); |
64 error_code = 1; | 65 error_code = 1; |
65 goto cleanup; | 66 goto cleanup; |
66 } | 67 } |
67 | 68 |
68 /* Generate test images. */ | 69 /* Generate test images. */ |
69 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) { | 70 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) { |
70 firmware_blobs[i] = GenerateTestFirmwareBlob(algorithm, | 71 firmware_blobs[i] = (uint8_t*) Malloc(g_firmware_sizes_to_test[i]); |
71 firmware_sign_key, | 72 Memset(firmware_blobs[i], 'F', g_firmware_sizes_to_test[i]); |
72 1, /* firmware key version. */ | 73 verification_blobs[i] = GenerateTestVerificationBlob( |
73 1, /* firmware version. */ | 74 algorithm, |
74 g_firmware_sizes_to_test[i], | 75 firmware_sign_key, |
75 "testkeys/key_rsa8192.pem", | 76 1, /* firmware key version. */ |
76 firmware_sign_key_file); | 77 1, /* firmware version. */ |
| 78 g_firmware_sizes_to_test[i], |
| 79 "testkeys/key_rsa8192.pem", |
| 80 firmware_sign_key_file); |
77 if (!firmware_blobs[i]) { | 81 if (!firmware_blobs[i]) { |
78 debug("Couldn't generate test firmware images.\n"); | 82 debug("Couldn't generate test firmware images.\n"); |
79 error_code = 1; | 83 error_code = 1; |
80 goto cleanup; | 84 goto cleanup; |
81 } | 85 } |
82 } | 86 } |
83 | 87 |
84 /* Get pre-processed key used for verification. */ | 88 /* Get pre-processed key used for verification. */ |
85 root_key_blob = BufferFromFile("testkeys/key_rsa8192.keyb", &len); | 89 root_key_blob = BufferFromFile("testkeys/key_rsa8192.keyb", &len); |
86 if (!root_key_blob) { | 90 if (!root_key_blob) { |
87 debug("Couldn't read pre-processed rootkey.\n"); | 91 debug("Couldn't read pre-processed rootkey.\n"); |
88 error_code = 1; | 92 error_code = 1; |
89 goto cleanup; | 93 goto cleanup; |
90 } | 94 } |
91 | 95 |
92 /* Now run the timing tests. */ | 96 /* Now run the timing tests. */ |
93 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) { | 97 for (i = 0; i < NUM_SIZES_TO_TEST; ++i) { |
94 StartTimer(&ct); | 98 StartTimer(&ct); |
95 for (j = 0; j < NUM_OPERATIONS; ++j) { | 99 for (j = 0; j < NUM_OPERATIONS; ++j) { |
96 if (VERIFY_FIRMWARE_SUCCESS != | 100 if (VERIFY_FIRMWARE_SUCCESS != |
97 VerifyFirmware(root_key_blob, firmware_blobs[i])) | 101 VerifyFirmware(root_key_blob, |
| 102 verification_blobs[i], |
| 103 firmware_blobs[i])) |
98 debug("Warning: Firmware Verification Failed.\n"); | 104 debug("Warning: Firmware Verification Failed.\n"); |
99 } | 105 } |
100 StopTimer(&ct); | 106 StopTimer(&ct); |
101 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS; | 107 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS; |
102 fprintf(stderr, | 108 fprintf(stderr, |
103 "# Firmware (%s, Algo = %s):" | 109 "# Firmware (%s, Algo = %s):" |
104 "\t%.02f ms/verification\n", | 110 "\t%.02f ms/verification\n", |
105 g_firmware_size_labels[i], | 111 g_firmware_size_labels[i], |
106 algo_strings[algorithm], | 112 algo_strings[algorithm], |
107 msecs); | 113 msecs); |
108 fprintf(stdout, "ms_firmware_%s_rsa%d_%s:%.02f\n", | 114 fprintf(stdout, "ms_firmware_%s_rsa%d_%s:%.02f\n", |
109 g_firmware_size_labels[i], | 115 g_firmware_size_labels[i], |
110 key_size, | 116 key_size, |
111 sha_strings[algorithm], | 117 sha_strings[algorithm], |
112 msecs); | 118 msecs); |
113 } | 119 } |
114 | 120 |
115 cleanup: | 121 cleanup: |
116 for (i = 0; i < NUM_SIZES_TO_TEST; i++) | 122 for (i = 0; i < NUM_SIZES_TO_TEST; i++) { |
117 Free(firmware_blobs[i]); | 123 Free(firmware_blobs[i]); |
| 124 Free(verification_blobs[i]); |
| 125 } |
118 Free(root_key_blob); | 126 Free(root_key_blob); |
119 return error_code; | 127 return error_code; |
120 } | 128 } |
121 | 129 |
122 | 130 |
123 int main(int argc, char* argv[]) { | 131 int main(int argc, char* argv[]) { |
124 int i, error_code = 0; | 132 int i, error_code = 0; |
125 for (i = 0; i < kNumAlgorithms; ++i) { | 133 for (i = 0; i < kNumAlgorithms; ++i) { |
126 if (0 != (error_code = SpeedTestAlgorithm(i))) | 134 if (0 != (error_code = SpeedTestAlgorithm(i))) |
127 return error_code; | 135 return error_code; |
128 } | 136 } |
129 return 0; | 137 return 0; |
130 } | 138 } |
OLD | NEW |