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 message digest of the contents of a file in a | 5 * Utility that outputs the message digest of the contents of a file in a |
6 * format that can be used as input to OpenSSL for an RSA signature. | 6 * format that can be used as input to OpenSSL for an RSA signature. |
7 * Needed until the stable OpenSSL release supports SHA-256/512 digests for | 7 * Needed until the stable OpenSSL release supports SHA-256/512 digests for |
8 * RSA signatures. | 8 * RSA signatures. |
9 * Outputs DigestInfo || Digest where DigestInfo is the OID depending on the | 9 * Outputs DigestInfo || Digest where DigestInfo is the OID depending on the |
10 * choice of the hash algorithm (see padding.c). | 10 * choice of the hash algorithm (see padding.c). |
11 * | 11 * |
12 */ | 12 */ |
13 | 13 |
14 #include "signature_digest.h" | 14 #include "signature_digest.h" |
15 | 15 |
16 #include <stdio.h> | 16 #include <stdio.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 #include <unistd.h> | 18 #include <unistd.h> |
19 | 19 |
20 #include "digest_utility.h" | |
21 #include "padding.h" | 20 #include "padding.h" |
22 #include "sha.h" | 21 #include "sha.h" |
| 22 #include "sha_utility.h" |
23 | 23 |
24 uint8_t* prepend_digestinfo(int algorithm, uint8_t* digest) { | 24 uint8_t* prepend_digestinfo(int algorithm, uint8_t* digest) { |
25 const int digest_size = hash_size_map[algorithm]; | 25 const int digest_size = hash_size_map[algorithm]; |
26 const int digestinfo_size = digestinfo_size_map[algorithm]; | 26 const int digestinfo_size = digestinfo_size_map[algorithm]; |
27 const uint8_t* digestinfo = hash_digestinfo_map[algorithm]; | 27 const uint8_t* digestinfo = hash_digestinfo_map[algorithm]; |
28 uint8_t* p = malloc(digestinfo_size + digest_size); | 28 uint8_t* p = malloc(digestinfo_size + digest_size); |
29 memcpy(p, digestinfo, digestinfo_size); | 29 memcpy(p, digestinfo, digestinfo_size); |
30 memcpy(p + digestinfo_size, digest, digest_size); | 30 memcpy(p + digestinfo_size, digest, digest_size); |
31 return p; | 31 return p; |
32 } | 32 } |
(...skipping 12 matching lines...) Expand all Loading... |
45 fprintf(stderr, "\t%d for %s\n", i, algo_strings[i]); | 45 fprintf(stderr, "\t%d for %s\n", i, algo_strings[i]); |
46 return -1; | 46 return -1; |
47 } | 47 } |
48 | 48 |
49 algorithm = atoi(argv[1]); | 49 algorithm = atoi(argv[1]); |
50 if (algorithm >= kNumAlgorithms) { | 50 if (algorithm >= kNumAlgorithms) { |
51 fprintf(stderr, "Invalid Algorithm!\n"); | 51 fprintf(stderr, "Invalid Algorithm!\n"); |
52 goto failure; | 52 goto failure; |
53 } | 53 } |
54 | 54 |
55 if (!(digest = calculate_digest(argv[2], algorithm))) | 55 if (!(digest = DigestFile(argv[2], algorithm))) |
56 goto failure; | 56 goto failure; |
57 | 57 |
58 info_digest = prepend_digestinfo(algorithm, digest); | 58 info_digest = prepend_digestinfo(algorithm, digest); |
59 write(1, info_digest, hash_size_map[algorithm] + | 59 write(1, info_digest, hash_size_map[algorithm] + |
60 digestinfo_size_map[algorithm]); | 60 digestinfo_size_map[algorithm]); |
61 | 61 |
62 failure: | 62 failure: |
63 free(digest); | 63 free(digest); |
64 free(info_digest); | 64 free(info_digest); |
65 free(signature); | 65 free(signature); |
66 | 66 |
67 return 0; | 67 return 0; |
68 } | 68 } |
OLD | NEW |