OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Utility functions for file and key handling. | 5 * Utility functions for file and key handling. |
6 */ | 6 */ |
7 | 7 |
8 #include "file_keys.h" | 8 #include "file_keys.h" |
9 | 9 |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <string.h> | 13 #include <string.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include "padding.h" | 18 #include "padding.h" |
19 #include "rsa_utility.h" | 19 #include "rsa_utility.h" |
20 #include "signature_digest.h" | 20 #include "signature_digest.h" |
21 #include "utility.h" | 21 #include "utility.h" |
22 | 22 |
23 uint8_t* BufferFromFile(const char* input_file, uint32_t* len) { | 23 uint8_t* BufferFromFile(const char* input_file, uint64_t* len) { |
24 int fd; | 24 int fd; |
25 struct stat stat_fd; | 25 struct stat stat_fd; |
26 uint8_t* buf = NULL; | 26 uint8_t* buf = NULL; |
27 | 27 |
28 if ((fd = open(input_file, O_RDONLY)) == -1) { | 28 if ((fd = open(input_file, O_RDONLY)) == -1) { |
29 fprintf(stderr, "Couldn't open file.\n"); | 29 fprintf(stderr, "Couldn't open file.\n"); |
30 return NULL; | 30 return NULL; |
31 } | 31 } |
32 | 32 |
33 if (-1 == fstat(fd, &stat_fd)) { | 33 if (-1 == fstat(fd, &stat_fd)) { |
(...skipping 10 matching lines...) Expand all Loading... |
44 if (*len != read(fd, buf, *len)) { | 44 if (*len != read(fd, buf, *len)) { |
45 fprintf(stderr, "Couldn't read key into a buffer.\n"); | 45 fprintf(stderr, "Couldn't read key into a buffer.\n"); |
46 return NULL; | 46 return NULL; |
47 } | 47 } |
48 | 48 |
49 close(fd); | 49 close(fd); |
50 return buf; | 50 return buf; |
51 } | 51 } |
52 | 52 |
53 RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) { | 53 RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) { |
54 uint32_t len; | 54 uint64_t len; |
55 RSAPublicKey* key = NULL; | 55 RSAPublicKey* key = NULL; |
56 uint8_t* buf = BufferFromFile(input_file, &len); | 56 uint8_t* buf = BufferFromFile(input_file, &len); |
57 if (buf) | 57 if (buf) |
58 key = RSAPublicKeyFromBuf(buf, len); | 58 key = RSAPublicKeyFromBuf(buf, len); |
59 Free(buf); | 59 Free(buf); |
60 return key; | 60 return key; |
61 } | 61 } |
62 | 62 |
63 uint8_t* SignatureFile(const char* input_file, const char* key_file, | 63 uint8_t* SignatureFile(const char* input_file, const char* key_file, |
64 int algorithm) { | 64 int algorithm) { |
(...skipping 26 matching lines...) Expand all Loading... |
91 if (fread(signature, signature_size, 1, cmd_out) != 1) { | 91 if (fread(signature, signature_size, 1, cmd_out) != 1) { |
92 fprintf(stderr, "Couldn't read signature.\n"); | 92 fprintf(stderr, "Couldn't read signature.\n"); |
93 pclose(cmd_out); | 93 pclose(cmd_out); |
94 Free(signature); | 94 Free(signature); |
95 return NULL; | 95 return NULL; |
96 } | 96 } |
97 | 97 |
98 pclose(cmd_out); | 98 pclose(cmd_out); |
99 return signature; | 99 return signature; |
100 } | 100 } |
OLD | NEW |