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

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

Issue 660228: Make crypto benchmark output compatible with autotest. (Closed)
Patch Set: 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/tests/sha_benchmark.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 void SpeedTestAlgorithm(int algorithm) { 18 int SpeedTestAlgorithm(int algorithm) {
19 int i, key_size; 19 int i, key_size;
20 int error_code = 0;
20 double speed, msecs; 21 double speed, msecs;
21 char file_name[FILE_NAME_SIZE]; 22 char file_name[FILE_NAME_SIZE];
22 uint8_t* digest = NULL; 23 uint8_t* digest = NULL;
23 uint8_t* signature = NULL; 24 uint8_t* signature = NULL;
24 int digest_len; 25 int digest_len;
25 int sig_len; 26 int sig_len;
26 RSAPublicKey* key = NULL; 27 RSAPublicKey* key = NULL;
27 ClockTimerState ct; 28 ClockTimerState ct;
28 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ 29 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */
29 "sha1", "sha256", "sha512", /* RSA-1024 */ 30 "sha1", "sha256", "sha512", /* RSA-1024 */
30 "sha1", "sha256", "sha512", /* RSA-2048 */ 31 "sha1", "sha256", "sha512", /* RSA-2048 */
31 "sha1", "sha256", "sha512", /* RSA-4096 */ 32 "sha1", "sha256", "sha512", /* RSA-4096 */
32 "sha1", "sha256", "sha512", /* RSA-8192 */ 33 "sha1", "sha256", "sha512", /* RSA-8192 */
33 }; 34 };
34 35
35 key_size = siglen_map[algorithm] * sizeof(uint32_t) * 8; /* in bits. */ 36 key_size = siglen_map[algorithm] * sizeof(uint32_t) * 8; /* in bits. */
36 /* Get key. */ 37 /* Get key. */
37 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size); 38 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size);
38 key = RSAPublicKeyFromFile(file_name); 39 key = RSAPublicKeyFromFile(file_name);
39 if (!key) { 40 if (!key) {
40 fprintf(stderr, "Couldn't read key from file.\n"); 41 fprintf(stderr, "Couldn't read key from file.\n");
42 error_code = 1;
41 goto failure; 43 goto failure;
42 } 44 }
43 45
44 /* Get expected digest. */ 46 /* Get expected digest. */
45 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest", 47 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest",
46 sha_strings[algorithm]); 48 sha_strings[algorithm]);
47 digest = BufferFromFile(file_name, &digest_len); 49 digest = BufferFromFile(file_name, &digest_len);
48 if (!digest) { 50 if (!digest) {
49 fprintf(stderr, "Couldn't read digest file.\n"); 51 fprintf(stderr, "Couldn't read digest file.\n");
52 error_code = 1;
50 goto failure; 53 goto failure;
51 } 54 }
52 55
53 /* Get signature to verify against. */ 56 /* Get signature to verify against. */
54 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.rsa%d_%s.sig", 57 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.rsa%d_%s.sig",
55 key_size, sha_strings[algorithm]); 58 key_size, sha_strings[algorithm]);
56 signature = BufferFromFile(file_name, &sig_len); 59 signature = BufferFromFile(file_name, &sig_len);
57 if (!signature) { 60 if (!signature) {
58 fprintf(stderr, "Couldn't read signature file.\n"); 61 fprintf(stderr, "Couldn't read signature file.\n");
62 error_code = 1;
59 goto failure; 63 goto failure;
60 } 64 }
61 65
62 StartTimer(&ct); 66 StartTimer(&ct);
63 for (i = 0; i < NUM_OPERATIONS; i++) { 67 for (i = 0; i < NUM_OPERATIONS; i++) {
64 if (!RSA_verify(key, signature, sig_len, algorithm, digest)) 68 if (!RSA_verify(key, signature, sig_len, algorithm, digest))
65 fprintf(stderr, "Warning: Signature Check Failed.\n"); 69 fprintf(stderr, "Warning: Signature Check Failed.\n");
66 } 70 }
67 StopTimer(&ct); 71 StopTimer(&ct);
68 72
69 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS; 73 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS;
70 speed = 1000.0 / msecs ; 74 speed = 1000.0 / msecs ;
71 fprintf(stderr, "rsa%d/%s bits:\tTime taken per verification = %.02f ms," 75 fprintf(stderr, "# rsa%d/%s:\tTime taken per verification = %.02f ms,"
72 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm], 76 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm],
73 msecs, speed); 77 msecs, speed);
78 fprintf(stdout, "rsa%d/%s:%.02f\n", key_size, sha_strings[algorithm], msecs);
74 79
75 failure: 80 failure:
76 Free(signature); 81 Free(signature);
77 Free(digest); 82 Free(digest);
78 Free(key); 83 Free(key);
84 return error_code;
79 } 85 }
80 86
81 int main(int argc, char* argv[]) { 87 int main(int argc, char* argv[]) {
82 int i; 88 int i;
89 int error_code = 0;
83 for (i = 0; i < kNumAlgorithms; ++i) { 90 for (i = 0; i < kNumAlgorithms; ++i) {
84 SpeedTestAlgorithm(i); 91 if(SpeedTestAlgorithm(i))
92 error_code = 1;
85 } 93 }
86 return 0; 94 return error_code;
87 } 95 }
OLDNEW
« no previous file with comments | « no previous file | src/platform/vboot_reference/tests/sha_benchmark.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698