Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: utility/pad_digest_utility.c

Issue 6334133: Add utility to pad a given hash for PKCS1.5 signatures (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: fix messages Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utility/Makefile ('k') | utility/signature_digest_utility.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « utility/Makefile ('k') | utility/signature_digest_utility.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698