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