| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 26 public: | 26 public: |
| 27 // Defines the algorithm that a key will be used with. See also | 27 // Defines the algorithm that a key will be used with. See also |
| 28 // classs Encrptor. | 28 // classs Encrptor. |
| 29 enum Algorithm { | 29 enum Algorithm { |
| 30 AES, | 30 AES, |
| 31 HMAC_SHA1, | 31 HMAC_SHA1, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 virtual ~SymmetricKey(); | 34 virtual ~SymmetricKey(); |
| 35 | 35 |
| 36 // Generates cryptographically strong random bytes. Returns true on success. |
| 37 static bool GenerateRandomBytes(size_t size_in_bits, uint8* out); |
| 38 |
| 36 // Generates a random key suitable to be used with |algorithm| and of | 39 // Generates a random key suitable to be used with |algorithm| and of |
| 37 // |key_size_in_bits| bits. | 40 // |key_size_in_bits| bits. |
| 38 // The caller is responsible for deleting the returned SymmetricKey. | 41 // The caller is responsible for deleting the returned SymmetricKey. |
| 39 static SymmetricKey* GenerateRandomKey(Algorithm algorithm, | 42 static SymmetricKey* GenerateRandomKey(Algorithm algorithm, |
| 40 size_t key_size_in_bits); | 43 size_t key_size_in_bits); |
| 41 | 44 |
| 42 // Derives a key from the supplied password and salt using PBKDF2, suitable | 45 // Derives a key from the supplied password and salt using PBKDF2, suitable |
| 43 // for use with specified |algorithm|. Note |algorithm| is not the algorithm | 46 // for use with specified |algorithm|. Note |algorithm| is not the algorithm |
| 44 // used to derive the key from the password. The caller is responsible for | 47 // used to derive the key from the password. The caller is responsible for |
| 45 // deleting the returned SymmetricKey. | 48 // deleting the returned SymmetricKey. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // fails with NTE_BAD_KEY/NTE_BAD_LEN | 98 // fails with NTE_BAD_KEY/NTE_BAD_LEN |
| 96 std::string raw_key_; | 99 std::string raw_key_; |
| 97 #endif | 100 #endif |
| 98 | 101 |
| 99 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); | 102 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 } // namespace base | 105 } // namespace base |
| 103 | 106 |
| 104 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ | 107 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ |
| OLD | NEW |