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> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 fprintf(stderr, "\t%d for %s\n", i, algo_strings[i]); | 67 fprintf(stderr, "\t%d for %s\n", i, algo_strings[i]); |
68 return -1; | 68 return -1; |
69 } | 69 } |
70 | 70 |
71 algorithm = atoi(argv[1]); | 71 algorithm = atoi(argv[1]); |
72 if (algorithm >= kNumAlgorithms) { | 72 if (algorithm >= kNumAlgorithms) { |
73 fprintf(stderr, "Invalid Algorithm!\n"); | 73 fprintf(stderr, "Invalid Algorithm!\n"); |
74 return 0; | 74 return 0; |
75 } | 75 } |
76 /* Length of the RSA Signature/RSA Key */ | 76 /* Length of the RSA Signature/RSA Key */ |
77 sig_len = siglen_map[algorithm] * sizeof(uint32_t); | 77 sig_len = siglen_map[algorithm]; |
78 | |
79 if (!(key = RSAPublicKeyFromFile(argv[2]))) | 78 if (!(key = RSAPublicKeyFromFile(argv[2]))) |
80 goto failure; | 79 goto failure; |
81 if (!(signature = read_signature(argv[3], sig_len))) | 80 if (!(signature = read_signature(argv[3], sig_len))) |
82 goto failure; | 81 goto failure; |
83 if (!(digest = DigestFile(argv[4], algorithm))) | 82 if (!(digest = DigestFile(argv[4], algorithm))) |
84 goto failure; | 83 goto failure; |
85 if(RSA_verify(key, signature, sig_len, algorithm, digest)) { | 84 if(RSA_verify(key, signature, sig_len, algorithm, digest)) { |
86 return_code = 0; | 85 return_code = 0; |
87 fprintf(stderr, "Signature Verification " | 86 fprintf(stderr, "Signature Verification " |
88 COL_GREEN "SUCCEEDED" COL_STOP "\n"); | 87 COL_GREEN "SUCCEEDED" COL_STOP "\n"); |
89 } else { | 88 } else { |
90 fprintf(stderr, "Signature Verification " | 89 fprintf(stderr, "Signature Verification " |
91 COL_RED "FAILED" COL_STOP "\n"); | 90 COL_RED "FAILED" COL_STOP "\n"); |
92 } | 91 } |
93 | 92 |
94 failure: | 93 failure: |
95 free(key); | 94 free(key); |
96 free(signature); | 95 free(signature); |
97 free(digest); | 96 free(digest); |
98 | 97 |
99 return return_code; | 98 return return_code; |
100 } | 99 } |
OLD | NEW |