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

Side by Side Diff: src/platform/vboot_reference/crypto/rsa_utility.c

Issue 1519008: VBoot Reference: 18 Exabytes ought to be enough for everybody (Closed)
Patch Set: Use symbolic constants. Created 10 years, 8 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
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 message digest functions. 5 * Utility functions for message digest functions.
6 */ 6 */
7 7
8 #include "padding.h" 8 #include "padding.h"
9 #include "rsa_utility.h" 9 #include "rsa_utility.h"
10 #include "sha_utility.h" 10 #include "sha_utility.h"
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 } 36 }
37 37
38 RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, int len) { 38 RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, int len) {
39 RSAPublicKey* key = RSAPublicKeyNew(); 39 RSAPublicKey* key = RSAPublicKeyNew();
40 MemcpyState st; 40 MemcpyState st;
41 int key_len; 41 int key_len;
42 42
43 st.remaining_buf = (uint8_t*) buf; 43 st.remaining_buf = (uint8_t*) buf;
44 st.remaining_len = len; 44 st.remaining_len = len;
45 st.overrun = 0;
46
45 StatefulMemcpy(&st, &key->len, sizeof(key->len)); 47 StatefulMemcpy(&st, &key->len, sizeof(key->len));
46 key_len = key->len * sizeof(uint32_t); /* key length in bytes. */ 48 key_len = key->len * sizeof(uint32_t); /* key length in bytes. */
47 49
48 /* Sanity Check the key length. */ 50 /* Sanity Check the key length. */
49 if (RSA1024NUMBYTES != key_len && 51 if (RSA1024NUMBYTES != key_len &&
50 RSA2048NUMBYTES != key_len && 52 RSA2048NUMBYTES != key_len &&
51 RSA4096NUMBYTES != key_len && 53 RSA4096NUMBYTES != key_len &&
52 RSA8192NUMBYTES != key_len) { 54 RSA8192NUMBYTES != key_len) {
53 RSAPublicKeyFree(key); 55 RSAPublicKeyFree(key);
54 return NULL; 56 return NULL;
55 } 57 }
56 58
57 key->n = (uint32_t*) Malloc(key_len); 59 key->n = (uint32_t*) Malloc(key_len);
58 key->rr = (uint32_t*) Malloc(key_len); 60 key->rr = (uint32_t*) Malloc(key_len);
59 61
60 StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv)); 62 StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
61 StatefulMemcpy(&st, key->n, key_len); 63 StatefulMemcpy(&st, key->n, key_len);
62 StatefulMemcpy(&st, key->rr, key_len); 64 StatefulMemcpy(&st, key->rr, key_len);
63 if (st.remaining_len != 0) { /* Underrun or overrun. */ 65 if (st.overrun || st.remaining_len != 0) { /* Underrun or overrun. */
64 RSAPublicKeyFree(key); 66 RSAPublicKeyFree(key);
65 return NULL; 67 return NULL;
66 } 68 }
67 69
68 return key; 70 return key;
69 } 71 }
70 72
71 int RSAVerifyBinary_f(const uint8_t* key_blob, 73 int RSAVerifyBinary_f(const uint8_t* key_blob,
72 const RSAPublicKey* key, 74 const RSAPublicKey* key,
73 const uint8_t* buf, 75 const uint8_t* buf,
74 int len, 76 uint64_t len,
75 const uint8_t* sig, 77 const uint8_t* sig,
76 int algorithm) { 78 int algorithm) {
77 RSAPublicKey* verification_key = NULL; 79 RSAPublicKey* verification_key = NULL;
78 uint8_t* digest = NULL; 80 uint8_t* digest = NULL;
79 int key_size; 81 int key_size;
80 int sig_size; 82 int sig_size;
81 int success; 83 int success;
82 84
83 if (algorithm >= kNumAlgorithms) 85 if (algorithm >= kNumAlgorithms)
84 return 0; /* Invalid algorithm. */ 86 return 0; /* Invalid algorithm. */
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 verification_key = (RSAPublicKey*) key; /* Supress const warning. */ 126 verification_key = (RSAPublicKey*) key; /* Supress const warning. */
125 else 127 else
126 return 0; /* Both can't be NULL or non-NULL. */ 128 return 0; /* Both can't be NULL or non-NULL. */
127 129
128 success = RSAVerify(verification_key, sig, sig_size, algorithm, digest); 130 success = RSAVerify(verification_key, sig, sig_size, algorithm, digest);
129 131
130 if (!key) 132 if (!key)
131 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ 133 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
132 return success; 134 return success;
133 } 135 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/common/utility_stub.c ('k') | src/platform/vboot_reference/include/firmware_image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698