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