From 10811823389d6dd702212008a8e9f3901b804641 Mon Sep 17 00:00:00 2001 From: "snej@chromium.org" Date: Mon, 29 Mar 2010 18:22:24 +0000 Subject: Add Mac implementations of new SymmetricKey and Encryptor classes. BUG=none TEST=EncryptorTest, SymmetricKeyTest Review URL: http://codereview.chromium.org/1347002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42964 0039d316-1c4b-4281-b951-d872f2087c98 --- base/crypto/symmetric_key.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'base/crypto/symmetric_key.h') diff --git a/base/crypto/symmetric_key.h b/base/crypto/symmetric_key.h index 1e1aed5..f528213 100644 --- a/base/crypto/symmetric_key.h +++ b/base/crypto/symmetric_key.h @@ -11,7 +11,9 @@ #if defined(USE_NSS) #include "base/crypto/scoped_nss_types.h" -#endif // USE_NSS +#elif defined(OS_MACOSX) +#include +#endif namespace base { @@ -26,21 +28,25 @@ class SymmetricKey { virtual ~SymmetricKey() {} - // Generates a random key suitable to be used with |cipher| and of |key_size| - // bytes. The caller is responsible for deleting the returned SymmetricKey. - static SymmetricKey* GenerateRandomKey(Algorithm algorithm, size_t key_size); + // Generates a random key suitable to be used with |cipher| and of + // |key_size_in_bits| bits. + // The caller is responsible for deleting the returned SymmetricKey. + static SymmetricKey* GenerateRandomKey(Algorithm algorithm, + size_t key_size_in_bits); // Derives a key from the supplied password and salt using PBKDF2. The caller - // is respnosible for deleting the returned SymmetricKey. + // is responsible for deleting the returned SymmetricKey. static SymmetricKey* DeriveKeyFromPassword(Algorithm algorithm, const std::string& password, const std::string& salt, size_t iterations, - size_t key_size); + size_t key_size_in_bits); #if defined(USE_NSS) PK11SymKey* key() const { return key_.get(); } -#endif // USE_NSS +#elif defined(OS_MACOSX) + CSSM_DATA cssm_data() const; +#endif // Extracts the raw key from the platform specific data. This should only be // done in unit tests to verify that keys are generated correctly. @@ -50,7 +56,10 @@ class SymmetricKey { #if defined(USE_NSS) explicit SymmetricKey(PK11SymKey* key) : key_(key) {} ScopedPK11SymKey key_; -#endif // USE_NSS +#elif defined(OS_MACOSX) + SymmetricKey(const void* key_data, size_t key_size_in_bits); + std::string key_; +#endif DISALLOW_COPY_AND_ASSIGN(SymmetricKey); }; -- cgit v1.1