diff options
author | albertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 19:13:00 +0000 |
---|---|---|
committer | albertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 19:13:00 +0000 |
commit | 39422e3082cc5b3633183b53ff21f93a5c17e5f0 (patch) | |
tree | f7bced4c1c84b34858abafc629aa8da7434d4ffc /base/crypto/symmetric_key.h | |
parent | 91968bc1e60c8ee2a3cab902c7f8246565974850 (diff) | |
download | chromium_src-39422e3082cc5b3633183b53ff21f93a5c17e5f0.zip chromium_src-39422e3082cc5b3633183b53ff21f93a5c17e5f0.tar.gz chromium_src-39422e3082cc5b3633183b53ff21f93a5c17e5f0.tar.bz2 |
Implement random key generation and AES encryption using NSS.
BUG=none
TEST=unit test
Review URL: http://codereview.chromium.org/1142004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/crypto/symmetric_key.h')
-rw-r--r-- | base/crypto/symmetric_key.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/base/crypto/symmetric_key.h b/base/crypto/symmetric_key.h index c298048..1e1aed5 100644 --- a/base/crypto/symmetric_key.h +++ b/base/crypto/symmetric_key.h @@ -19,12 +19,25 @@ namespace base { // scoped_ptr. class SymmetricKey { public: -#if defined(USE_NSS) - explicit SymmetricKey(PK11SymKey* key) : key_(key) {} -#endif // USE_NSS + enum Algorithm { + AES, + HMAC_SHA1, + }; 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); + + // Derives a key from the supplied password and salt using PBKDF2. The caller + // is respnosible 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); + #if defined(USE_NSS) PK11SymKey* key() const { return key_.get(); } #endif // USE_NSS @@ -35,6 +48,7 @@ class SymmetricKey { private: #if defined(USE_NSS) + explicit SymmetricKey(PK11SymKey* key) : key_(key) {} ScopedPK11SymKey key_; #endif // USE_NSS |