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

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

Issue 626011: Vboot Reference: Add a RSA verify benchmark. (Closed)
Patch Set: 80 Created 10 years, 10 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
(Empty)
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
3 * found in the LICENSE file.
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include "file_keys.h"
10 #include "padding.h"
11 #include "rsa.h"
12 #include "timer_utils.h"
13 #include "utility.h"
14
15 #define FILE_NAME_SIZE 128
16 #define NUM_OPERATIONS 100 /* Number of signature operations to time. */
17
18 void SpeedTestAlgorithm(int algorithm) {
19 int i, key_size;
20 double speed, msecs;
21 char file_name[FILE_NAME_SIZE];
22 uint8_t* digest = NULL;
23 uint8_t* signature = NULL;
24 int digest_len;
25 int sig_len;
26 RSAPublicKey* key = NULL;
27 ClockTimerState ct;
28 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */
29 "sha1", "sha256", "sha512", /* RSA-1024 */
30 "sha1", "sha256", "sha512", /* RSA-2048 */
31 "sha1", "sha256", "sha512", /* RSA-4096 */
32 "sha1", "sha256", "sha512", /* RSA-8192 */
33 };
34
35 key_size = siglen_map[algorithm] * sizeof(uint32_t) * 8; /* in bits. */
36 /* Get key. */
37 snprintf(file_name, FILE_NAME_SIZE, "testkeys/key_rsa%d.keyb", key_size);
38 key = RSAPublicKeyFromFile(file_name);
39 if (!key) {
40 fprintf(stderr, "Couldn't read key from file.\n");
41 goto failure;
42 }
43
44 /* Get expected digest. */
45 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.%s.digest",
46 sha_strings[algorithm]);
47 digest = BufferFromFile(file_name, &digest_len);
48 if (!digest) {
49 fprintf(stderr, "Couldn't read digest file.\n");
50 goto failure;
51 }
52
53 /* Get signature to verify against. */
54 snprintf(file_name, FILE_NAME_SIZE, "testcases/test_file.rsa%d_%s.sig",
55 key_size, sha_strings[algorithm]);
56 signature = BufferFromFile(file_name, &sig_len);
57 if (!signature) {
58 fprintf(stderr, "Couldn't read signature file.\n");
59 goto failure;
60 }
61
62 StartTimer(&ct);
63 for (i = 0; i < NUM_OPERATIONS; i++) {
64 if (!RSA_verify(key, signature, sig_len, algorithm, digest))
65 fprintf(stderr, "Warning: Signature Check Failed.\n");
66 }
67 StopTimer(&ct);
68
69 msecs = (float) GetDurationMsecs(&ct) / NUM_OPERATIONS;
70 speed = 1000.0 / msecs ;
71 fprintf(stderr, "rsa%d/%s bits:\tTime taken per verification = %.02f ms,"
72 " Speed = %.02f verifications/s\n", key_size, sha_strings[algorithm],
73 msecs, speed);
74
75 failure:
76 Free(signature);
77 Free(digest);
78 Free(key);
79 }
80
81 int main(int argc, char* argv[]) {
82 int i;
83 for (i = 0; i < kNumAlgorithms; ++i) {
84 SpeedTestAlgorithm(i);
85 }
86 return 0;
87 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/tests/gen_test_cases.sh ('k') | src/platform/vboot_reference/tests/run_rsa_tests.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698