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 /* Routines for verifying a file's signature. Useful in testing the core | 6 /* Routines for verifying a file's signature. Useful in testing the core |
7 * RSA verification implementation. | 7 * RSA verification implementation. |
8 */ | 8 */ |
9 | 9 |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <string.h> | 13 #include <string.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include "digest_utility.h" | 18 #include "sha_utility.h" |
19 #include "padding.h" | 19 #include "padding.h" |
20 #include "rsa.h" | 20 #include "rsa.h" |
21 #include "rsa_utility.h" | 21 #include "rsa_utility.h" |
22 #include "verify_data.h" | 22 #include "verify_data.h" |
23 | 23 |
24 RSAPublicKey* read_RSAkey(char* input_file, int len) { | 24 RSAPublicKey* read_RSAkey(char* input_file, int len) { |
25 int key_fd; | 25 int key_fd; |
26 int buf_len; | 26 int buf_len; |
27 struct stat stat_fd; | 27 struct stat stat_fd; |
28 uint8_t* buf = NULL; | 28 uint8_t* buf = NULL; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 fprintf(stderr, "Invalid Algorithm!\n"); | 98 fprintf(stderr, "Invalid Algorithm!\n"); |
99 return 0; | 99 return 0; |
100 } | 100 } |
101 /* Length of the RSA Signature/RSA Key */ | 101 /* Length of the RSA Signature/RSA Key */ |
102 sig_len = siglen_map[algorithm] * sizeof(uint32_t); | 102 sig_len = siglen_map[algorithm] * sizeof(uint32_t); |
103 | 103 |
104 if (!(key = read_RSAkey(argv[2], sig_len))) | 104 if (!(key = read_RSAkey(argv[2], sig_len))) |
105 goto failure; | 105 goto failure; |
106 if (!(signature = read_signature(argv[3], sig_len))) | 106 if (!(signature = read_signature(argv[3], sig_len))) |
107 goto failure; | 107 goto failure; |
108 if (!(digest = calculate_digest(argv[4], algorithm))) | 108 if (!(digest = DigestFile(argv[4], algorithm))) |
109 goto failure; | 109 goto failure; |
110 if(RSA_verify(key, signature, sig_len, algorithm, digest)) | 110 if(RSA_verify(key, signature, sig_len, algorithm, digest)) |
111 fprintf(stderr, "Signature Verification SUCCEEDED.\n"); | 111 fprintf(stderr, "Signature Verification SUCCEEDED.\n"); |
112 else | 112 else |
113 fprintf(stderr, "Signature Verification FAILED!\n"); | 113 fprintf(stderr, "Signature Verification FAILED!\n"); |
114 | 114 |
115 failure: | 115 failure: |
116 free(key); | 116 free(key); |
117 free(signature); | 117 free(signature); |
118 free(digest); | 118 free(digest); |
119 | 119 |
120 return 0; | 120 return 0; |
121 } | 121 } |
OLD | NEW |