| 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 | 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 void SpeedTestAlgorithm(int algorithm) { |
| 19 int i, key_size; | 19 int i, key_size; |
| 20 double speed, msecs; | 20 double speed, msecs; |
| 21 char file_name[FILE_NAME_SIZE]; | 21 char file_name[FILE_NAME_SIZE]; |
| 22 uint8_t* digest = NULL; | 22 uint8_t* digest = NULL; |
| 23 uint8_t* signature = NULL; | 23 uint8_t* signature = NULL; |
| 24 int digest_len; | 24 uint32_t digest_len, sig_len; |
| 25 int sig_len; | |
| 26 RSAPublicKey* key = NULL; | 25 RSAPublicKey* key = NULL; |
| 27 ClockTimerState ct; | 26 ClockTimerState ct; |
| 28 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ | 27 char* sha_strings[] = { /* Maps algorithm->SHA algorithm. */ |
| 29 "sha1", "sha256", "sha512", /* RSA-1024 */ | 28 "sha1", "sha256", "psha512", /* RSA-1024 */ |
| 30 "sha1", "sha256", "sha512", /* RSA-2048 */ | 29 "sha1", "sha256", "sha512", /* RSA-2048 */ |
| 31 "sha1", "sha256", "sha512", /* RSA-4096 */ | 30 "sha1", "sha256", "sha512", /* RSA-4096 */ |
| 32 "sha1", "sha256", "sha512", /* RSA-8192 */ | 31 "sha1", "sha256", "sha512", /* RSA-8192 */ |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 key_size = siglen_map[algorithm] * sizeof(uint32_t) * 8; /* in bits. */ | 34 key_size = siglen_map[algorithm] * sizeof(uint32_t) * 8; /* in bits. */ |
| 36 /* Get key. */ | 35 /* Get key. */ |
| 37 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); |
| 38 key = RSAPublicKeyFromFile(file_name); | 37 key = RSAPublicKeyFromFile(file_name); |
| 39 if (!key) { | 38 if (!key) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 Free(key); | 77 Free(key); |
| 79 } | 78 } |
| 80 | 79 |
| 81 int main(int argc, char* argv[]) { | 80 int main(int argc, char* argv[]) { |
| 82 int i; | 81 int i; |
| 83 for (i = 0; i < kNumAlgorithms; ++i) { | 82 for (i = 0; i < kNumAlgorithms; ++i) { |
| 84 SpeedTestAlgorithm(i); | 83 SpeedTestAlgorithm(i); |
| 85 } | 84 } |
| 86 return 0; | 85 return 0; |
| 87 } | 86 } |
| OLD | NEW |