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

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

Issue 1607006: VBoot Reference: Output debug information using debug() instead of fprintf(). (Closed)
Patch Set: Created 10 years, 8 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
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 "cryptolib.h" 9 #include "cryptolib.h"
10 #include "file_keys.h" 10 #include "file_keys.h"
(...skipping 18 matching lines...) Expand all
29 "sha1", "sha256", "sha512", /* RSA-2048 */ 29 "sha1", "sha256", "sha512", /* RSA-2048 */
30 "sha1", "sha256", "sha512", /* RSA-4096 */ 30 "sha1", "sha256", "sha512", /* RSA-4096 */
31 "sha1", "sha256", "sha512", /* RSA-8192 */ 31 "sha1", "sha256", "sha512", /* RSA-8192 */
32 }; 32 };
33 33
34 key_size = siglen_map[algorithm] * 8; /* in bits. */ 34 key_size = siglen_map[algorithm] * 8; /* in bits. */
35 /* Get key. */ 35 /* Get key. */
36 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size); 36 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size);
37 key = RSAPublicKeyFromFile(file_name); 37 key = RSAPublicKeyFromFile(file_name);
38 if (!key) { 38 if (!key) {
39 fprintf(stderr, "Couldn't read RSA Public key from file: %s\n", file_name); 39 debug("Couldn't read RSA Public key from file: %s\n", file_name);
40 error_code = 1; 40 error_code = 1;
41 goto failure; 41 goto failure;
42 } 42 }
43 43
44 /* Get expected digest. */ 44 /* Get expected digest. */
45 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest", 45 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest",
46 sha_strings[algorithm]); 46 sha_strings[algorithm]);
47 digest = BufferFromFile(file_name, &digest_len); 47 digest = BufferFromFile(file_name, &digest_len);
48 if (!digest) { 48 if (!digest) {
49 fprintf(stderr, "Couldn't read digest file.\n"); 49 debug("Couldn't read digest file.\n");
50 error_code = 1; 50 error_code = 1;
51 goto failure; 51 goto failure;
52 } 52 }
53 53
54 /* Get signature to verify against. */ 54 /* Get signature to verify against. */
55 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.rsa%d_%s.sig", 55 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.rsa%d_%s.sig",
56 key_size, sha_strings[algorithm]); 56 key_size, sha_strings[algorithm]);
57 signature = BufferFromFile(file_name, &sig_len); 57 signature = BufferFromFile(file_name, &sig_len);
58 if (!signature) { 58 if (!signature) {
59 fprintf(stderr, "Couldn't read signature file.\n"); 59 debug("Couldn't read signature file.\n");
60 error_code = 1; 60 error_code = 1;
61 goto failure; 61 goto failure;
62 } 62 }
63 63
64 StartTimer(&ct); 64 StartTimer(&ct);
65 for (i = 0; i < NUM_OPERATIONS; i++) { 65 for (i = 0; i < NUM_OPERATIONS; i++) {
66 if (!RSAVerify(key, signature, sig_len, algorithm, digest)) 66 if (!RSAVerify(key, signature, sig_len, algorithm, digest))
67 fprintf(stderr, "Warning: Signature Check Failed.\n"); 67 debug("Warning: Signature Check Failed.\n");
68 } 68 }
69 StopTimer(&ct); 69 StopTimer(&ct);
70 70
71 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS; 71 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS;
72 speed = 1000.0 / msecs ; 72 speed = 1000.0 / msecs ;
73 fprintf(stderr, "# rsa%d/%s:\tTime taken per verification = %.02f ms," 73 fprintf(stderr, "# rsa%d/%s:\tTime taken per verification = %.02f ms,"
74 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm], 74 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm],
75 msecs, speed); 75 msecs, speed);
76 fprintf(stdout, "ms_rsa%d_%s:%.02f\n", key_size, sha_strings[algorithm], 76 fprintf(stdout, "ms_rsa%d_%s:%.02f\n", key_size, sha_strings[algorithm],
77 msecs); 77 msecs);
78 78
79 failure: 79 failure:
80 Free(signature); 80 Free(signature);
81 Free(digest); 81 Free(digest);
82 RSAPublicKeyFree(key); 82 RSAPublicKeyFree(key);
83 return error_code; 83 return error_code;
84 } 84 }
85 85
86 int main(int argc, char* argv[]) { 86 int main(int argc, char* argv[]) {
87 int i; 87 int i;
88 int error_code = 0; 88 int error_code = 0;
89 for (i = 0; i < kNumAlgorithms; ++i) { 89 for (i = 0; i < kNumAlgorithms; ++i) {
90 if(SpeedTestAlgorithm(i)) 90 if(SpeedTestAlgorithm(i))
91 error_code = 1; 91 error_code = 1;
92 } 92 }
93 return error_code; 93 return error_code;
94 } 94 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/tests/rollback_index_mock.c ('k') | src/platform/vboot_reference/tests/test_common.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698