| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include "crypto/symmetric_key.h" | 5 #include "crypto/symmetric_key.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 // TODO(wtc): replace scoped_array by std::vector. | 9 // TODO(wtc): replace scoped_array by std::vector. |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 case 128: | 31 case 128: |
| 32 return CALG_AES_128; | 32 return CALG_AES_128; |
| 33 case 192: | 33 case 192: |
| 34 return CALG_AES_192; | 34 return CALG_AES_192; |
| 35 case 256: | 35 case 256: |
| 36 return CALG_AES_256; | 36 return CALG_AES_256; |
| 37 default: | 37 default: |
| 38 NOTREACHED(); | 38 NOTREACHED(); |
| 39 return 0; | 39 return 0; |
| 40 } | 40 } |
| 41 }; | 41 } |
| 42 | 42 |
| 43 // Imports a raw/plaintext key of |key_size| stored in |*key_data| into a new | 43 // Imports a raw/plaintext key of |key_size| stored in |*key_data| into a new |
| 44 // key created for the specified |provider|. |alg| contains the algorithm of | 44 // key created for the specified |provider|. |alg| contains the algorithm of |
| 45 // the key being imported. | 45 // the key being imported. |
| 46 // If |key_data| is intended to be used as an HMAC key, then |alg| should be | 46 // If |key_data| is intended to be used as an HMAC key, then |alg| should be |
| 47 // CALG_HMAC. | 47 // CALG_HMAC. |
| 48 // If successful, returns true and stores the imported key in |*key|. | 48 // If successful, returns true and stores the imported key in |*key|. |
| 49 // TODO(wtc): use this function in hmac_win.cc. | 49 // TODO(wtc): use this function in hmac_win.cc. |
| 50 bool ImportRawKey(HCRYPTPROV provider, | 50 bool ImportRawKey(HCRYPTPROV provider, |
| 51 ALG_ID alg, | 51 ALG_ID alg, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 76 // RSA Enhanced Provider, as the approved means of using arbitrary HMAC | 76 // RSA Enhanced Provider, as the approved means of using arbitrary HMAC |
| 77 // key material. | 77 // key material. |
| 78 key_header->hdr.aiKeyAlg = CALG_RC2; | 78 key_header->hdr.aiKeyAlg = CALG_RC2; |
| 79 flags |= CRYPT_IPSEC_HMAC_KEY; | 79 flags |= CRYPT_IPSEC_HMAC_KEY; |
| 80 } | 80 } |
| 81 | 81 |
| 82 BOOL ok = | 82 BOOL ok = |
| 83 CryptImportKey(provider, actual_key, actual_size, 0, flags, &unsafe_key); | 83 CryptImportKey(provider, actual_key, actual_size, 0, flags, &unsafe_key); |
| 84 | 84 |
| 85 // Clean up the temporary copy of key, regardless of whether it was imported | 85 // Clean up the temporary copy of key, regardless of whether it was imported |
| 86 // sucessfully or not. | 86 // successfully or not. |
| 87 SecureZeroMemory(actual_key, actual_size); | 87 SecureZeroMemory(actual_key, actual_size); |
| 88 | 88 |
| 89 if (!ok) | 89 if (!ok) |
| 90 return false; | 90 return false; |
| 91 | 91 |
| 92 key->reset(unsafe_key); | 92 key->reset(unsafe_key); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Attempts to generate a random AES key of |key_size_in_bits|. Returns true | 96 // Attempts to generate a random AES key of |key_size_in_bits|. Returns true |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 HCRYPTKEY key, | 527 HCRYPTKEY key, |
| 528 const void* key_data, size_t key_size_in_bytes) | 528 const void* key_data, size_t key_size_in_bytes) |
| 529 : provider_(provider), key_(key) { | 529 : provider_(provider), key_(key) { |
| 530 if (key_data) { | 530 if (key_data) { |
| 531 raw_key_.assign(reinterpret_cast<const char*>(key_data), | 531 raw_key_.assign(reinterpret_cast<const char*>(key_data), |
| 532 key_size_in_bytes); | 532 key_size_in_bytes); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 | 535 |
| 536 } // namespace crypto | 536 } // namespace crypto |
| OLD | NEW |