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 CRYPTO_SYMMETRIC_KEY_H_ | 5 #ifndef CRYPTO_SYMMETRIC_KEY_H_ |
6 #define CRYPTO_SYMMETRIC_KEY_H_ | 6 #define CRYPTO_SYMMETRIC_KEY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
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 a random key suitable to be used with |algorithm| and of | 37 // Generates a random key suitable to be used with |algorithm| and of |
38 // |key_size_in_bits| bits. | 38 // |key_size_in_bits| bits. |key_size_in_bits| must be a multiple of 8. |
39 // The caller is responsible for deleting the returned SymmetricKey. | 39 // The caller is responsible for deleting the returned SymmetricKey. |
40 static SymmetricKey* GenerateRandomKey(Algorithm algorithm, | 40 static SymmetricKey* GenerateRandomKey(Algorithm algorithm, |
41 size_t key_size_in_bits); | 41 size_t key_size_in_bits); |
42 | 42 |
43 // Derives a key from the supplied password and salt using PBKDF2, suitable | 43 // Derives a key from the supplied password and salt using PBKDF2, suitable |
44 // for use with specified |algorithm|. Note |algorithm| is not the algorithm | 44 // 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 | 45 // used to derive the key from the password. |key_size_in_bits| must be a |
46 // deleting the returned SymmetricKey. | 46 // multiple of 8. The caller is responsible for deleting the returned |
| 47 // SymmetricKey. |
47 static SymmetricKey* DeriveKeyFromPassword(Algorithm algorithm, | 48 static SymmetricKey* DeriveKeyFromPassword(Algorithm algorithm, |
48 const std::string& password, | 49 const std::string& password, |
49 const std::string& salt, | 50 const std::string& salt, |
50 size_t iterations, | 51 size_t iterations, |
51 size_t key_size_in_bits); | 52 size_t key_size_in_bits); |
52 | 53 |
53 // Imports an array of key bytes in |raw_key|. This key may have been | 54 // Imports an array of key bytes in |raw_key|. This key may have been |
54 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with | 55 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with |
55 // GetRawKey, or via another compatible method. The key must be of suitable | 56 // GetRawKey, or via another compatible method. The key must be of suitable |
56 // size for use with |algorithm|. The caller owns the returned SymmetricKey. | 57 // size for use with |algorithm|. The caller owns the returned SymmetricKey. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // fails with NTE_BAD_KEY/NTE_BAD_LEN | 102 // fails with NTE_BAD_KEY/NTE_BAD_LEN |
102 std::string raw_key_; | 103 std::string raw_key_; |
103 #endif | 104 #endif |
104 | 105 |
105 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); | 106 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); |
106 }; | 107 }; |
107 | 108 |
108 } // namespace crypto | 109 } // namespace crypto |
109 | 110 |
110 #endif // CRYPTO_SYMMETRIC_KEY_H_ | 111 #endif // CRYPTO_SYMMETRIC_KEY_H_ |
OLD | NEW |