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

Side by Side Diff: host/lib/host_key.c

Issue 6733018: Use uint64_t and avoid down casting as much as possible. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « firmware/lib/vboot_common.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * Host functions for keys. 5 * Host functions for keys.
6 */ 6 */
7 7
8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */
9 9
10 #define OPENSSL_NO_SHA 10 #define OPENSSL_NO_SHA
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 key->key_size = key_size; 160 key->key_size = key_size;
161 key->key_offset = sizeof(VbPublicKey); 161 key->key_offset = sizeof(VbPublicKey);
162 return key; 162 return key;
163 } 163 }
164 164
165 VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm, 165 VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
166 uint64_t version) { 166 uint64_t version) {
167 VbPublicKey* key; 167 VbPublicKey* key;
168 uint8_t* key_data; 168 uint8_t* key_data;
169 uint64_t key_size; 169 uint64_t key_size;
170 int expected_key_size; 170 uint64_t expected_key_size;
171 171
172 if (algorithm >= kNumAlgorithms) { 172 if (algorithm >= kNumAlgorithms) {
173 VBDEBUG(("PublicKeyReadKeyb() called with invalid algorithm!\n")); 173 VBDEBUG(("PublicKeyReadKeyb() called with invalid algorithm!\n"));
174 return NULL; 174 return NULL;
175 } 175 }
176 if (version > 0xFFFF) { 176 if (version > 0xFFFF) {
177 /* Currently, TPM only supports 16-bit version */ 177 /* Currently, TPM only supports 16-bit version */
178 VBDEBUG(("PublicKeyReadKeyb() called with invalid version!\n")); 178 VBDEBUG(("PublicKeyReadKeyb() called with invalid version!\n"));
179 return NULL; 179 return NULL;
180 } 180 }
(...skipping 17 matching lines...) Expand all
198 Memcpy(GetPublicKeyData(key), key_data, key_size); 198 Memcpy(GetPublicKeyData(key), key_data, key_size);
199 199
200 Free(key_data); 200 Free(key_data);
201 return key; 201 return key;
202 } 202 }
203 203
204 204
205 VbPublicKey* PublicKeyRead(const char* filename) { 205 VbPublicKey* PublicKeyRead(const char* filename) {
206 VbPublicKey* key; 206 VbPublicKey* key;
207 uint64_t file_size; 207 uint64_t file_size;
208 int key_size; 208 uint64_t key_size;
209 209
210 key = (VbPublicKey*)ReadFile(filename, &file_size); 210 key = (VbPublicKey*)ReadFile(filename, &file_size);
211 if (!key) 211 if (!key)
212 return NULL; 212 return NULL;
213 213
214 do { 214 do {
215 /* Sanity-check key data */ 215 /* Sanity-check key data */
216 if (0 != VerifyPublicKeyInside(key, file_size, key)) { 216 if (0 != VerifyPublicKeyInside(key, file_size, key)) {
217 VBDEBUG(("PublicKeyRead() not a VbPublicKey\n")); 217 VBDEBUG(("PublicKeyRead() not a VbPublicKey\n"));
218 break; 218 break;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (0 != PublicKeyCopy(kcopy, key)) { 252 if (0 != PublicKeyCopy(kcopy, key)) {
253 Free(kcopy); 253 Free(kcopy);
254 return 1; 254 return 1;
255 } 255 }
256 256
257 /* Write the copy, then free it */ 257 /* Write the copy, then free it */
258 rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size); 258 rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size);
259 Free(kcopy); 259 Free(kcopy);
260 return rv; 260 return rv;
261 } 261 }
OLDNEW
« no previous file with comments | « firmware/lib/vboot_common.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698