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

Unified Diff: src/platform/vboot_reference/utils/file_keys.c

Issue 564020: Data structure and interface for manipulating and handing firmware images for verified boot. (Closed)
Patch Set: Fix spaces etc. Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/vboot_reference/utils/Makefile ('k') | src/platform/vboot_reference/utils/firmware_image.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/vboot_reference/utils/file_keys.c
diff --git a/src/platform/vboot_reference/utils/file_keys.c b/src/platform/vboot_reference/utils/file_keys.c
new file mode 100644
index 0000000000000000000000000000000000000000..8a8a2cb2c0f1b605d8236e4ecb98b12f69d147f7
--- /dev/null
+++ b/src/platform/vboot_reference/utils/file_keys.c
@@ -0,0 +1,57 @@
+/* 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 functions for file and key handling.
+ */
+
+#include "file_keys.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "rsa_utility.h"
+#include "utility.h"
+
+uint8_t* BufferFromFile(char* input_file, int* len) {
+ int fd;
+ struct stat stat_fd;
+ uint8_t* buf = NULL;
+
+ if ((fd = open(input_file, O_RDONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file.\n");
+ return NULL;
+ }
+
+ if (-1 == fstat(fd, &stat_fd)) {
+ fprintf(stderr, "Couldn't stat key file\n");
+ return NULL;
+ }
+ *len = stat_fd.st_size;
+
+ /* Read entire key binary blob into a buffer. */
+ buf = (uint8_t*) Malloc(*len);
+ if (!buf)
+ return NULL;
+
+ if (*len != read(fd, buf, *len)) {
+ fprintf(stderr, "Couldn't read key into a buffer.\n");
+ return NULL;
+ }
+
+ close(fd);
+ return buf;
+}
+
+RSAPublicKey* RSAPublicKeyFromFile(char* input_file) {
+ int len;
+ uint8_t* buf = BufferFromFile(input_file, &len);
+ RSAPublicKey* key = RSAPublicKeyFromBuf(buf, len);
+ Free(buf);
+ return key;
+}
« no previous file with comments | « src/platform/vboot_reference/utils/Makefile ('k') | src/platform/vboot_reference/utils/firmware_image.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698