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 * Utility that outputs the cryptographic digest of a contents of a | 5 * Utility that outputs the cryptographic digest of a contents of a |
6 * file in a format that can be directly used to generate PKCS#1 v1.5 | 6 * file in a format that can be directly used to generate PKCS#1 v1.5 |
7 * signatures via the "openssl" command line utility. | 7 * signatures via the "openssl" command line utility. |
8 */ | 8 */ |
9 | 9 |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 | 13 |
14 #include "file_keys.h" | 14 #include "file_keys.h" |
15 #include "padding.h" | 15 #include "padding.h" |
16 #include "signature_digest.h" | 16 #include "signature_digest.h" |
17 #include "utility.h" | 17 #include "utility.h" |
18 | 18 |
19 int main(int argc, char* argv[]) { | 19 int main(int argc, char* argv[]) { |
20 int algorithm = -1; | 20 int algorithm = -1; |
21 int error_code = 0; | 21 int error_code = 0; |
22 uint8_t* buf = NULL; | 22 uint8_t* buf = NULL; |
23 uint8_t* signature_digest = NULL; | 23 uint8_t* signature_digest = NULL; |
24 uint64_t len; | 24 uint64_t len; |
25 uint32_t signature_digest_len; | 25 uint32_t signature_digest_len; |
26 | 26 |
27 if (argc != 3) { | 27 if (argc != 3) { |
28 fprintf(stderr, "Usage: %s <algoid> <file>", argv[0]); | 28 fprintf(stderr, "Usage: %s <alg_id> <file>", argv[0]); |
29 return -1; | 29 return -1; |
30 } | 30 } |
31 algorithm = atoi(argv[1]); | 31 algorithm = atoi(argv[1]); |
32 if (algorithm < 0 || algorithm >= kNumAlgorithms) { | 32 if (algorithm < 0 || algorithm >= kNumAlgorithms) { |
33 fprintf(stderr, "Invalid Algorithm!\n"); | 33 fprintf(stderr, "Invalid Algorithm!\n"); |
34 return -1; | 34 return -1; |
35 } | 35 } |
36 | 36 |
37 buf = BufferFromFile(argv[2], &len); | 37 buf = BufferFromFile(argv[2], &len); |
38 if (!buf) { | 38 if (!buf) { |
39 fprintf(stderr, "Could read file: %s\n", argv[2]); | 39 fprintf(stderr, "Could not read file: %s\n", argv[2]); |
40 return -1; | 40 return -1; |
41 } | 41 } |
42 | 42 |
43 signature_digest = SignatureDigest(buf, len, algorithm); | 43 signature_digest = SignatureDigest(buf, len, algorithm); |
44 signature_digest_len = (hash_size_map[algorithm] + | 44 signature_digest_len = (hash_size_map[algorithm] + |
45 digestinfo_size_map[algorithm]); | 45 digestinfo_size_map[algorithm]); |
46 if (!signature_digest) | 46 if (!signature_digest) |
47 error_code = -1; | 47 error_code = -1; |
48 if(signature_digest && | 48 if(signature_digest && |
49 1 != fwrite(signature_digest, signature_digest_len, 1, stdout)) | 49 1 != fwrite(signature_digest, signature_digest_len, 1, stdout)) |
50 error_code = -1; | 50 error_code = -1; |
51 Free(signature_digest); | 51 Free(signature_digest); |
52 Free(buf); | 52 Free(buf); |
53 return error_code; | 53 return error_code; |
54 } | 54 } |
OLD | NEW |