Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: src/platform/vboot_reference/tests/rsa_verify_benchmark.c

Issue 660310: Fix a typo in the RSA benchmark. (Closed)
Patch Set: Follow output convention. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/platform/vboot_reference/utils/file_keys.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "file_keys.h" 9 #include "file_keys.h"
10 #include "padding.h" 10 #include "padding.h"
11 #include "rsa.h" 11 #include "rsa.h"
12 #include "timer_utils.h" 12 #include "timer_utils.h"
13 #include "utility.h" 13 #include "utility.h"
14 14
15 #define FILE_NAME_SIZE 128 15 #define FILE_NAME_SIZE 128
16 #define NUM_OPERATIONS 100 /* Number of signature operations to time. */ 16 #define NUM_OPERATIONS 100 /* Number of signature operations to time. */
17 17
18 int SpeedTestAlgorithm(int algorithm) { 18 int SpeedTestAlgorithm(int algorithm) {
19 int i, key_size; 19 int i, key_size;
20 int error_code = 0; 20 int error_code = 0;
21 double speed, msecs; 21 double speed, msecs;
22 char file_name[FILE_NAME_SIZE]; 22 char file_name[FILE_NAME_SIZE];
23 uint8_t* digest = NULL; 23 uint8_t* digest = NULL;
24 uint8_t* signature = NULL; 24 uint8_t* signature = NULL;
25 uint32_t digest_len, sig_len; 25 uint32_t digest_len, sig_len;
26 RSAPublicKey* key = NULL; 26 RSAPublicKey* key = NULL;
27 ClockTimerState ct; 27 ClockTimerState ct;
28 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ 28 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */
29 "sha1", "sha256", "psha512", /* RSA-1024 */ 29 "sha1", "sha256", "sha512", /* RSA-1024 */
30 "sha1", "sha256", "sha512", /* RSA-2048 */ 30 "sha1", "sha256", "sha512", /* RSA-2048 */
31 "sha1", "sha256", "sha512", /* RSA-4096 */ 31 "sha1", "sha256", "sha512", /* RSA-4096 */
32 "sha1", "sha256", "sha512", /* RSA-8192 */ 32 "sha1", "sha256", "sha512", /* RSA-8192 */
33 }; 33 };
34 34
35 key_size = siglen_map[algorithm] * 8; /* in bits. */ 35 key_size = siglen_map[algorithm] * 8; /* in bits. */
36 /* Get key. */ 36 /* Get key. */
37 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size); 37 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size);
38 key = RSAPublicKeyFromFile(file_name); 38 key = RSAPublicKeyFromFile(file_name);
39 if (!key) { 39 if (!key) {
40 fprintf(stderr, "Couldn't read key from file.\n"); 40 fprintf(stderr, "Couldn't read RSA Public key from file: %s\n", file_name);
41 error_code = 1; 41 error_code = 1;
42 goto failure; 42 goto failure;
43 } 43 }
44 44
45 /* Get expected digest. */ 45 /* Get expected digest. */
46 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest", 46 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest",
47 sha_strings[algorithm]); 47 sha_strings[algorithm]);
48 digest = BufferFromFile(file_name, &digest_len); 48 digest = BufferFromFile(file_name, &digest_len);
49 if (!digest) { 49 if (!digest) {
50 fprintf(stderr, "Couldn't read digest file.\n"); 50 fprintf(stderr, "Couldn't read digest file.\n");
(...skipping 16 matching lines...) Expand all
67 if (!RSA_verify(key, signature, sig_len, algorithm, digest)) 67 if (!RSA_verify(key, signature, sig_len, algorithm, digest))
68 fprintf(stderr, "Warning: Signature Check Failed.\n"); 68 fprintf(stderr, "Warning: Signature Check Failed.\n");
69 } 69 }
70 StopTimer(&ct); 70 StopTimer(&ct);
71 71
72 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS; 72 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS;
73 speed = 1000.0 / msecs ; 73 speed = 1000.0 / msecs ;
74 fprintf(stderr, "# rsa%d/%s:\tTime taken per verification = %.02f ms," 74 fprintf(stderr, "# rsa%d/%s:\tTime taken per verification = %.02f ms,"
75 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm], 75 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm],
76 msecs, speed); 76 msecs, speed);
77 fprintf(stdout, "rsa%d/%s:%.02f\n", key_size, sha_strings[algorithm], msecs); 77 fprintf(stdout, "ms_rsa%d_%s:%.02f\n", key_size, sha_strings[algorithm],
78 msecs);
78 79
79 failure: 80 failure:
80 Free(signature); 81 Free(signature);
81 Free(digest); 82 Free(digest);
82 Free(key); 83 Free(key);
83 return error_code; 84 return error_code;
84 } 85 }
85 86
86 int main(int argc, char* argv[]) { 87 int main(int argc, char* argv[]) {
87 int i; 88 int i;
88 int error_code = 0; 89 int error_code = 0;
89 for (i = 0; i < kNumAlgorithms; ++i) { 90 for (i = 0; i < kNumAlgorithms; ++i) {
90 if(SpeedTestAlgorithm(i)) 91 if(SpeedTestAlgorithm(i))
91 error_code = 1; 92 error_code = 1;
92 } 93 }
93 return error_code; 94 return error_code;
94 } 95 }
OLDNEW
« no previous file with comments | « no previous file | src/platform/vboot_reference/utils/file_keys.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698