| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef BASE_CRYPTO_SYMMETRIC_KEY_H_ | 5 #ifndef BASE_CRYPTO_SYMMETRIC_KEY_H_ |
| 6 #define BASE_CRYPTO_SYMMETRIC_KEY_H_ | 6 #define BASE_CRYPTO_SYMMETRIC_KEY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 HCRYPTKEY key() const { return key_.get(); } | 59 HCRYPTKEY key() const { return key_.get(); } |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 // Extracts the raw key from the platform specific data. | 62 // Extracts the raw key from the platform specific data. |
| 63 // Warning: |raw_key| holds the raw key as bytes and thus must be handled | 63 // Warning: |raw_key| holds the raw key as bytes and thus must be handled |
| 64 // carefully. | 64 // carefully. |
| 65 bool GetRawKey(std::string* raw_key); | 65 bool GetRawKey(std::string* raw_key); |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 #if defined(USE_OPENSSL) | 68 #if defined(USE_OPENSSL) |
| 69 // TODO(joth): Add a constructor that accepts OpenSSL symmetric key data, and | 69 // Swaps in the content of the |key|. |
| 70 // the appropriate data members to store it in. | 70 explicit SymmetricKey(std::string* key); |
| 71 std::string key_; |
| 71 #elif defined(USE_NSS) | 72 #elif defined(USE_NSS) |
| 72 explicit SymmetricKey(PK11SymKey* key); | 73 explicit SymmetricKey(PK11SymKey* key); |
| 73 ScopedPK11SymKey key_; | 74 ScopedPK11SymKey key_; |
| 74 #elif defined(OS_MACOSX) | 75 #elif defined(OS_MACOSX) |
| 75 SymmetricKey(const void* key_data, size_t key_size_in_bits); | 76 SymmetricKey(const void* key_data, size_t key_size_in_bits); |
| 76 std::string key_; | 77 std::string key_; |
| 77 #elif defined(OS_WIN) | 78 #elif defined(OS_WIN) |
| 78 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key, | 79 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key, |
| 79 const void* key_data, size_t key_size_in_bytes); | 80 const void* key_data, size_t key_size_in_bytes); |
| 80 | 81 |
| 81 ScopedHCRYPTPROV provider_; | 82 ScopedHCRYPTPROV provider_; |
| 82 ScopedHCRYPTKEY key_; | 83 ScopedHCRYPTKEY key_; |
| 83 | 84 |
| 84 // Contains the raw key, if it is known during initialization and when it | 85 // Contains the raw key, if it is known during initialization and when it |
| 85 // is likely that the associated |provider_| will be unable to export the | 86 // is likely that the associated |provider_| will be unable to export the |
| 86 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes | 87 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes |
| 87 // when using the default RSA provider. | 88 // when using the default RSA provider. |
| 88 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey | 89 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey |
| 89 // fails with NTE_BAD_KEY/NTE_BAD_LEN | 90 // fails with NTE_BAD_KEY/NTE_BAD_LEN |
| 90 std::string raw_key_; | 91 std::string raw_key_; |
| 91 #endif | 92 #endif |
| 92 | 93 |
| 93 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); | 94 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 } // namespace base | 97 } // namespace base |
| 97 | 98 |
| 98 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ | 99 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ |
| OLD | NEW |