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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /* Copyright (c) 2010 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 functions for file and key handling.
6 */
7
8 #include "file_keys.h"
9
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17
18 #include "rsa_utility.h"
19 #include "utility.h"
20
21 uint8_t* BufferFromFile(char* input_file, int* len) {
22 int fd;
23 struct stat stat_fd;
24 uint8_t* buf = NULL;
25
26 if ((fd = open(input_file, O_RDONLY)) == -1) {
27 fprintf(stderr, "Couldn't open file.\n");
28 return NULL;
29 }
30
31 if (-1 == fstat(fd, &stat_fd)) {
32 fprintf(stderr, "Couldn't stat key file\n");
33 return NULL;
34 }
35 *len = stat_fd.st_size;
36
37 /* Read entire key binary blob into a buffer. */
38 buf = (uint8_t*) Malloc(*len);
39 if (!buf)
40 return NULL;
41
42 if (*len != read(fd, buf, *len)) {
43 fprintf(stderr, "Couldn't read key into a buffer.\n");
44 return NULL;
45 }
46
47 close(fd);
48 return buf;
49 }
50
51 RSAPublicKey* RSAPublicKeyFromFile(char* input_file) {
52 int len;
53 uint8_t* buf = BufferFromFile(input_file, &len);
54 RSAPublicKey* key = RSAPublicKeyFromBuf(buf, len);
55 Free(buf);
56 return key;
57 }
OLDNEW
« 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