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

Side by Side Diff: firmware/lib/cryptolib/rsa.c

Issue 3127013: RSAVerify() - fail on malloc() failure. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: Created 10 years, 4 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 | « no previous file | 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 5
6 /* Implementation of RSA signature verification which uses a pre-processed 6 /* Implementation of RSA signature verification which uses a pre-processed
7 * key for computation. The code extends Android's RSA verification code to 7 * key for computation. The code extends Android's RSA verification code to
8 * support multiple RSA key lengths and hash digest algorithms. 8 * support multiple RSA key lengths and hash digest algorithms.
9 */ 9 */
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 VBDEBUG(("Invalid signature type!\n")); 143 VBDEBUG(("Invalid signature type!\n"));
144 return 0; 144 return 0;
145 } 145 }
146 146
147 if (key->len != siglen_map[sig_type] / sizeof(uint32_t)) { 147 if (key->len != siglen_map[sig_type] / sizeof(uint32_t)) {
148 VBDEBUG(("Wrong key passed in!\n")); 148 VBDEBUG(("Wrong key passed in!\n"));
149 return 0; 149 return 0;
150 } 150 }
151 151
152 buf = (uint8_t*) Malloc(sig_len); 152 buf = (uint8_t*) Malloc(sig_len);
153 if (!buf)
154 return 0;
153 Memcpy(buf, sig, sig_len); 155 Memcpy(buf, sig, sig_len);
154 156
155 modpowF4(key, buf); 157 modpowF4(key, buf);
156 158
157 /* Determine padding to use depending on the signature type. */ 159 /* Determine padding to use depending on the signature type. */
158 padding = padding_map[sig_type]; 160 padding = padding_map[sig_type];
159 161
160 /* Check pkcs1.5 padding bytes. */ 162 /* Check pkcs1.5 padding bytes. */
161 for (i = 0; i < padding_size_map[sig_type]; ++i) { 163 for (i = 0; i < padding_size_map[sig_type]; ++i) {
162 if (buf[i] != padding[i]) { 164 if (buf[i] != padding[i]) {
163 #ifndef NDEBUG 165 #ifndef NDEBUG
164 /* TODO(gauravsh): Replace with a macro call for logging. */
165 VBDEBUG(("Padding: Expecting = %02x Got = %02x\n", padding[i], buf[i])); 166 VBDEBUG(("Padding: Expecting = %02x Got = %02x\n", padding[i], buf[i]));
166 #endif 167 #endif
167 success = 0; 168 success = 0;
168 } 169 }
169 } 170 }
170 171
171 /* Check if digest matches. */ 172 /* Check if digest matches. */
172 for (; i < (int)sig_len; ++i) { 173 for (; i < (int)sig_len; ++i) {
173 if (buf[i] != *hash++) { 174 if (buf[i] != *hash++) {
174 #ifndef NDEBUG 175 #ifndef NDEBUG
175 /* TODO(gauravsh): Replace with a macro call for logging. */
176 VBDEBUG(("Digest: Expecting = %02x Got = %02x\n", padding[i], buf[i])); 176 VBDEBUG(("Digest: Expecting = %02x Got = %02x\n", padding[i], buf[i]));
177 #endif 177 #endif
178 success = 0; 178 success = 0;
179 } 179 }
180 } 180 }
181 181
182 Free(buf); 182 Free(buf);
183 183
184 return success; 184 return success;
185 } 185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698