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 <algoid> <digest_file>", argv[0]); | |
Randall Spangler
2011/02/05 03:01:40
alg_id?
algoid sounds like a monster plant... :)
gauravsh
2011/02/07 19:12:30
Done.
| |
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 read file: %s\n", argv[2]); | |
Randall Spangler
2011/02/05 03:01:40
Could *not* read file?
gauravsh
2011/02/07 19:12:30
Done.
| |
39 return -1; | |
40 } | |
41 | |
42 padded_digest = PrependDigestInfo(algorithm, digest); | |
43 padded_digest_len = digestinfo_size_map[algorithm]; | |
44 | |
45 if (!padded_digest) | |
46 error_code = -1; | |
47 if(padded_digest && | |
48 1 != fwrite(padded_digest, padded_digest_len, 1, stdout)) | |
49 error_code = -1; | |
50 Free(padded_digest); | |
51 Free(digest); | |
52 return error_code; | |
53 } | |
OLD | NEW |