Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 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 "rsa_padding_test.h" |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | |
Gaurav Shah | 5411c7a | 2010-03-31 10:56:49 -0700 | [diff] [blame] | 10 | #include "cryptolib.h" |
Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 11 | #include "file_keys.h" |
Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 12 | |
| 13 | int main(int argc, char* argv[]) { |
| 14 | int i; |
| 15 | int error = 0; |
| 16 | RSAPublicKey* key; |
| 17 | if (argc != 2) { |
| 18 | fprintf(stderr, "Usage: %s <test public key>\n", argv[0]); |
| 19 | return 1; |
| 20 | } |
| 21 | key = RSAPublicKeyFromFile(argv[1]); |
| 22 | if (!key) { |
| 23 | fprintf(stderr, "Couldn't read RSA public key for the test.\n"); |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | /* The first test signature is valid. */ |
Gaurav Shah | f5564fa | 2010-03-02 15:40:01 -0800 | [diff] [blame] | 28 | if (!RSAVerify(key, signatures[0], RSA1024NUMBYTES, 0, |
Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 29 | test_message_sha1_hash)) { |
| 30 | fprintf(stderr, "RSA Padding Test vector 0 FAILED!\n"); |
| 31 | error = 255; /* Test failure. */ |
| 32 | } |
| 33 | /* All other signatures should fail verification. */ |
| 34 | for (i = 1; i < sizeof(signatures) / sizeof(signatures[0]); i++) { |
Gaurav Shah | f5564fa | 2010-03-02 15:40:01 -0800 | [diff] [blame] | 35 | if (RSAVerify(key, signatures[i], RSA1024NUMBYTES, 0, |
Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 36 | test_message_sha1_hash)) { |
| 37 | fprintf(stderr, "RSA Padding Test vector %d FAILED!\n", i); |
| 38 | error = 255; /* Test failure. */ |
| 39 | } |
| 40 | } |
| 41 | if (!error) |
| 42 | fprintf(stderr, "RSA Padding Test PASSED for all test vectors."); |
| 43 | |
Gaurav Shah | 259de40 | 2010-03-12 17:42:03 -0800 | [diff] [blame] | 44 | RSAPublicKeyFree(key); |
Gaurav Shah | 7d122e2 | 2010-02-24 16:41:32 -0800 | [diff] [blame] | 45 | return error; |
| 46 | } |