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 * Implementation of RSA utility functions. | 5 * Implementation of RSA utility functions. |
6 */ | 6 */ |
7 | 7 |
8 #include "cryptolib.h" | 8 #include "cryptolib.h" |
9 #include "stateful_util.h" | 9 #include "stateful_util.h" |
10 | 10 |
11 int RSAProcessedKeySize(int algorithm) { | 11 int RSAProcessedKeySize(int algorithm) { |
12 int key_len = siglen_map[algorithm]; /* Key length in | 12 int key_len = siglen_map[algorithm]; /* Key length in |
13 * bytes. */ | 13 * bytes. */ |
14 /* Total size needed by a RSAPublicKey structure is = | 14 /* Total size needed by a RSAPublicKey structure is = |
15 * 2 * key_len bytes for the n and rr arrays | 15 * 2 * key_len bytes for the n and rr arrays |
16 * + sizeof len + sizeof n0inv. | 16 * + sizeof len + sizeof n0inv. |
17 */ | 17 */ |
18 return (2 * key_len + sizeof(int) + sizeof(uint32_t)); | 18 return (2 * key_len + sizeof(uint32_t) + sizeof(uint32_t)); |
19 } | 19 } |
20 | 20 |
21 RSAPublicKey* RSAPublicKeyNew(void) { | 21 RSAPublicKey* RSAPublicKeyNew(void) { |
22 RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey)); | 22 RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey)); |
23 key->n = NULL; | 23 key->n = NULL; |
24 key->rr = NULL; | 24 key->rr = NULL; |
25 return key; | 25 return key; |
26 } | 26 } |
27 | 27 |
28 void RSAPublicKeyFree(RSAPublicKey* key) { | 28 void RSAPublicKeyFree(RSAPublicKey* key) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 verification_key = (RSAPublicKey*) key; /* Supress const warning. */ | 124 verification_key = (RSAPublicKey*) key; /* Supress const warning. */ |
125 else | 125 else |
126 return 0; /* Both can't be NULL or non-NULL. */ | 126 return 0; /* Both can't be NULL or non-NULL. */ |
127 | 127 |
128 success = RSAVerify(verification_key, sig, sig_size, algorithm, digest); | 128 success = RSAVerify(verification_key, sig, sig_size, algorithm, digest); |
129 | 129 |
130 if (!key) | 130 if (!key) |
131 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ | 131 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ |
132 return success; | 132 return success; |
133 } | 133 } |
OLD | NEW |