OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2011 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 for to generate a padded hash suitable for generating |
| 6 * PKCS#1.5 signatures. |
| 7 */ |
| 8 |
| 9 |
| 10 #include <stdio.h> |
| 11 #include <stdlib.h> |
| 12 |
| 13 #include "file_keys.h" |
| 14 #include "padding.h" |
| 15 #include "signature_digest.h" |
| 16 #include "utility.h" |
| 17 |
| 18 int main(int argc, char* argv[]) { |
| 19 int algorithm = -1; |
| 20 int error_code = 0; |
| 21 uint8_t* digest = NULL; |
| 22 uint8_t* padded_digest = NULL; |
| 23 uint64_t len; |
| 24 uint32_t padded_digest_len; |
| 25 |
| 26 if (argc != 3) { |
| 27 fprintf(stderr, "Usage: %s <alg_id> <digest_file>", argv[0]); |
| 28 return -1; |
| 29 } |
| 30 algorithm = atoi(argv[1]); |
| 31 if (algorithm < 0 || algorithm >= kNumAlgorithms) { |
| 32 fprintf(stderr, "Invalid Algorithm!\n"); |
| 33 return -1; |
| 34 } |
| 35 |
| 36 digest = BufferFromFile(argv[2], &len); |
| 37 if (!digest) { |
| 38 fprintf(stderr, "Could not read file: %s\n", argv[2]); |
| 39 return -1; |
| 40 } |
| 41 |
| 42 padded_digest = PrependDigestInfo(algorithm, digest); |
| 43 padded_digest_len = (hash_size_map[algorithm] + |
| 44 digestinfo_size_map[algorithm]); |
| 45 |
| 46 if (!padded_digest) |
| 47 error_code = -1; |
| 48 if(padded_digest && |
| 49 1 != fwrite(padded_digest, padded_digest_len, 1, stdout)) |
| 50 error_code = -1; |
| 51 Free(padded_digest); |
| 52 Free(digest); |
| 53 return error_code; |
| 54 } |
OLD | NEW |