| 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 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" |
| 11 #include "utility.h" | 11 #include "utility.h" |
| 12 | 12 |
| 13 int RSAProcessedKeySize(int algorithm) { | 13 int RSAProcessedKeySize(int algorithm) { |
| 14 int key_len = siglen_map[algorithm] * sizeof(uint32_t); /* Key length in | 14 int key_len = siglen_map[algorithm]; /* Key length in |
| 15 * bytes. */ | 15 * bytes. */ |
| 16 /* Total size needed by a RSAPublicKey structure is = | 16 /* Total size needed by a RSAPublicKey structure is = |
| 17 * 2 * key_len bytes for the n and rr arrays | 17 * 2 * key_len bytes for the n and rr arrays |
| 18 * + sizeof len + sizeof n0inv. | 18 * + sizeof len + sizeof n0inv. |
| 19 */ | 19 */ |
| 20 return (2 * key_len + sizeof(int) + sizeof(uint32_t)); | 20 return (2 * key_len + sizeof(int) + sizeof(uint32_t)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void RSAPublicKeyFree(RSAPublicKey* key) { | 23 void RSAPublicKeyFree(RSAPublicKey* key) { |
| 24 if (key) { | 24 if (key) { |
| 25 Free(key->n); | 25 Free(key->n); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 int algorithm) { | 62 int algorithm) { |
| 63 RSAPublicKey* verification_key = NULL; | 63 RSAPublicKey* verification_key = NULL; |
| 64 uint8_t* digest = NULL; | 64 uint8_t* digest = NULL; |
| 65 int key_size; | 65 int key_size; |
| 66 int sig_size; | 66 int sig_size; |
| 67 int success; | 67 int success; |
| 68 | 68 |
| 69 if (algorithm >= kNumAlgorithms) | 69 if (algorithm >= kNumAlgorithms) |
| 70 return 0; /* Invalid algorithm. */ | 70 return 0; /* Invalid algorithm. */ |
| 71 key_size = RSAProcessedKeySize(algorithm); | 71 key_size = RSAProcessedKeySize(algorithm); |
| 72 sig_size = siglen_map[algorithm] * sizeof(uint32_t); | 72 sig_size = siglen_map[algorithm]; |
| 73 | 73 |
| 74 if (key_blob && !key) | 74 if (key_blob && !key) |
| 75 verification_key = RSAPublicKeyFromBuf(key_blob, key_size); | 75 verification_key = RSAPublicKeyFromBuf(key_blob, key_size); |
| 76 else if (!key_blob && key) | 76 else if (!key_blob && key) |
| 77 verification_key = (RSAPublicKey*) key; /* Supress const warning. */ | 77 verification_key = (RSAPublicKey*) key; /* Supress const warning. */ |
| 78 else | 78 else |
| 79 return 0; /* Both can't be NULL or non-NULL. */ | 79 return 0; /* Both can't be NULL or non-NULL. */ |
| 80 | 80 |
| 81 digest = DigestBuf(buf, len, algorithm); | 81 digest = DigestBuf(buf, len, algorithm); |
| 82 success = RSA_verify(verification_key, sig, sig_size, algorithm, digest); | 82 success = RSA_verify(verification_key, sig, sig_size, algorithm, digest); |
| 83 | 83 |
| 84 Free(digest); | 84 Free(digest); |
| 85 if (!key) | 85 if (!key) |
| 86 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ | 86 RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ |
| 87 return success; | 87 return success; |
| 88 } | 88 } |
| OLD | NEW |