summaryrefslogtreecommitdiff
path: root/utility/signature_digest_utility.c
diff options
context:
space:
mode:
authorGaurav Shah <gauravsh@chromium.org>2010-03-31 13:26:55 -0700
committerGaurav Shah <gauravsh@chromium.org>2010-03-31 13:26:55 -0700
commitfc70d72aaab4d558e39ec43832375267603bfd93 (patch)
tree2b71e90cdb26c079a76ab82607e9bf7a7c97e6ff /utility/signature_digest_utility.c
parent5411c7a9f03f91bf2c1cd1cf852db9d4585a05c9 (diff)
downloadvboot-fc70d72aaab4d558e39ec43832375267603bfd93.tar.gz
VBoot Reference: Refactoring Part 3
Refactor and restructure reference code into individual self-contain modules. I have revamped the way the code is structured to make it easy to determine which parts belong in the firmware and which are used by userland tools. common/ - common utilities and stub functions (Firmware) cryptolib/ - crypto library (Firmware) misclibs/ - miscellaneous userland libraries (Userland) sctips/ - Miscellaenous scripts (Userland) tests/ - Tests (Userland) vfirmware/ - Verified Firmware Implementation vfirmware/firmware_image_fw.c (Firmware) vfirmware/firmware_image.c (Userland) vkernel/ - Verified Kernel Implementation vkernel/kernel_image_fw.c (Firmware) vkernel/kernel_image.c (Userland) Review URL: http://codereview.chromium.org/1581005
Diffstat (limited to 'utility/signature_digest_utility.c')
-rw-r--r--utility/signature_digest_utility.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/utility/signature_digest_utility.c b/utility/signature_digest_utility.c
new file mode 100644
index 00000000..6c8891b9
--- /dev/null
+++ b/utility/signature_digest_utility.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Utility that outputs the cryptographic digest of a contents of a
+ * file in a format that can be directly used to generate PKCS#1 v1.5
+ * signatures via the "openssl" command line utility.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "file_keys.h"
+#include "padding.h"
+#include "signature_digest.h"
+#include "utility.h"
+
+int main(int argc, char* argv[]) {
+ int algorithm = -1;
+ int error_code = 0;
+ uint8_t* buf = NULL;
+ uint8_t* signature_digest = NULL;
+ uint64_t len;
+ uint32_t signature_digest_len;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <algoid> <file>", argv[0]);
+ return -1;
+ }
+ algorithm = atoi(argv[1]);
+ if (algorithm < 0 || algorithm >= kNumAlgorithms) {
+ fprintf(stderr, "Invalid Algorithm!\n");
+ return -1;
+ }
+
+ buf = BufferFromFile(argv[2], &len);
+ if (!buf) {
+ fprintf(stderr, "Could read file: %s\n", argv[2]);
+ return -1;
+ }
+
+ signature_digest = SignatureDigest(buf, len, algorithm);
+ signature_digest_len = (hash_size_map[algorithm] +
+ digestinfo_size_map[algorithm]);
+ if (!signature_digest)
+ error_code = -1;
+ if(signature_digest &&
+ 1 != fwrite(signature_digest, signature_digest_len, 1, stdout))
+ error_code = -1;
+ Free(signature_digest);
+ Free(buf);
+ return error_code;
+}