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> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 return key; | 59 return key; |
60 } | 60 } |
61 | 61 |
62 uint8_t* SignatureFile(const char* input_file, const char* key_file, | 62 uint8_t* SignatureFile(const char* input_file, const char* key_file, |
63 int algorithm) { | 63 int algorithm) { |
64 char* sign_utility = "./sign_data.sh"; | 64 char* sign_utility = "./sign_data.sh"; |
65 char* cmd; /* Command line to invoke. */ | 65 char* cmd; /* Command line to invoke. */ |
66 int cmd_len; | 66 int cmd_len; |
67 FILE* cmd_out; /* File descriptor to command output. */ | 67 FILE* cmd_out; /* File descriptor to command output. */ |
68 uint8_t* signature = NULL; | 68 uint8_t* signature = NULL; |
69 int signature_size = siglen_map[algorithm] * sizeof(uint32_t); | 69 int signature_size = siglen_map[algorithm]; |
70 | 70 |
71 /* Build command line: | 71 /* Build command line: |
72 * sign_data.sh <algorithm> <key file> <input file> | 72 * sign_data.sh <algorithm> <key file> <input file> |
73 */ | 73 */ |
74 cmd_len = (strlen(sign_utility) + 1 + /* +1 for space. */ | 74 cmd_len = (strlen(sign_utility) + 1 + /* +1 for space. */ |
75 2 + 1 + /* For [algorithm]. */ | 75 2 + 1 + /* For [algorithm]. */ |
76 strlen(key_file) + 1 + /* +1 for space. */ | 76 strlen(key_file) + 1 + /* +1 for space. */ |
77 strlen(input_file) + | 77 strlen(input_file) + |
78 1); /* For the trailing '\0'. */ | 78 1); /* For the trailing '\0'. */ |
79 cmd = (char*) Malloc(cmd_len); | 79 cmd = (char*) Malloc(cmd_len); |
(...skipping 10 matching lines...) Expand all Loading... |
90 if (fread(signature, signature_size, 1, cmd_out) != 1) { | 90 if (fread(signature, signature_size, 1, cmd_out) != 1) { |
91 fprintf(stderr, "Couldn't read signature.\n"); | 91 fprintf(stderr, "Couldn't read signature.\n"); |
92 pclose(cmd_out); | 92 pclose(cmd_out); |
93 Free(signature); | 93 Free(signature); |
94 return NULL; | 94 return NULL; |
95 } | 95 } |
96 | 96 |
97 pclose(cmd_out); | 97 pclose(cmd_out); |
98 return signature; | 98 return signature; |
99 } | 99 } |
OLD | NEW |