Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: base/crypto/symmetric_key.h

Issue 4777001: Implements encryptor_openssl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar witesps Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const std::string& salt, 44 const std::string& salt,
45 size_t iterations, 45 size_t iterations,
46 size_t key_size_in_bits); 46 size_t key_size_in_bits);
47 47
48 // Imports a raw key. For this call to be successful, |raw_key| must have been 48 // Imports a raw key. For this call to be successful, |raw_key| must have been
49 // generated by either GenerateRandomKey or DeriveKeyFromPassword, and 49 // generated by either GenerateRandomKey or DeriveKeyFromPassword, and
50 // must have been exported with GetRawKey. The caller owns the returned 50 // must have been exported with GetRawKey. The caller owns the returned
51 // SymmetricKey. 51 // SymmetricKey.
52 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key); 52 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key);
53 53
54 #if defined(USE_NSS) 54 #if defined(USE_OPENSSL)
55 const std::string& key() { return key_; }
56 #elif defined(USE_NSS)
55 PK11SymKey* key() const { return key_.get(); } 57 PK11SymKey* key() const { return key_.get(); }
56 #elif defined(OS_MACOSX) 58 #elif defined(OS_MACOSX)
57 CSSM_DATA cssm_data() const; 59 CSSM_DATA cssm_data() const;
58 #elif defined(OS_WIN) 60 #elif defined(OS_WIN)
59 HCRYPTKEY key() const { return key_.get(); } 61 HCRYPTKEY key() const { return key_.get(); }
60 #endif 62 #endif
61 63
62 // Extracts the raw key from the platform specific data. 64 // Extracts the raw key from the platform specific data.
63 // Warning: |raw_key| holds the raw key as bytes and thus must be handled 65 // Warning: |raw_key| holds the raw key as bytes and thus must be handled
64 // carefully. 66 // carefully.
65 bool GetRawKey(std::string* raw_key); 67 bool GetRawKey(std::string* raw_key);
66 68
67 private: 69 private:
68 #if defined(USE_OPENSSL) 70 #if defined(USE_OPENSSL)
69 // Swaps in the content of the |key|. 71 // Swaps in the content of the |key|.
70 SymmetricKey(std::string* key); 72 SymmetricKey(std::string* key);
wtc 2010/11/10 23:40:32 Nit: add 'explicit'.
joth 2010/11/11 17:35:58 Done.
71 std::string key_; 73 std::string key_;
72 #elif defined(USE_NSS) 74 #elif defined(USE_NSS)
73 explicit SymmetricKey(PK11SymKey* key); 75 explicit SymmetricKey(PK11SymKey* key);
74 ScopedPK11SymKey key_; 76 ScopedPK11SymKey key_;
75 #elif defined(OS_MACOSX) 77 #elif defined(OS_MACOSX)
76 SymmetricKey(const void* key_data, size_t key_size_in_bits); 78 SymmetricKey(const void* key_data, size_t key_size_in_bits);
77 std::string key_; 79 std::string key_;
78 #elif defined(OS_WIN) 80 #elif defined(OS_WIN)
79 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key, 81 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key,
80 const void* key_data, size_t key_size_in_bytes); 82 const void* key_data, size_t key_size_in_bytes);
81 83
82 ScopedHCRYPTPROV provider_; 84 ScopedHCRYPTPROV provider_;
83 ScopedHCRYPTKEY key_; 85 ScopedHCRYPTKEY key_;
84 86
85 // Contains the raw key, if it is known during initialization and when it 87 // Contains the raw key, if it is known during initialization and when it
86 // is likely that the associated |provider_| will be unable to export the 88 // is likely that the associated |provider_| will be unable to export the
87 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes 89 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes
88 // when using the default RSA provider. 90 // when using the default RSA provider.
89 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey 91 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey
90 // fails with NTE_BAD_KEY/NTE_BAD_LEN 92 // fails with NTE_BAD_KEY/NTE_BAD_LEN
91 std::string raw_key_; 93 std::string raw_key_;
92 #endif 94 #endif
93 95
94 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); 96 DISALLOW_COPY_AND_ASSIGN(SymmetricKey);
95 }; 97 };
96 98
97 } // namespace base 99 } // namespace base
98 100
99 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ 101 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_
OLDNEW
« base/crypto/encryptor_openssl.cc ('K') | « base/crypto/encryptor_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698