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

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

Issue 4691003: Implement symmetric key for openssl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows build 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 HCRYPTKEY key() const { return key_.get(); } 59 HCRYPTKEY key() const { return key_.get(); }
60 #endif 60 #endif
61 61
62 // Extracts the raw key from the platform specific data. 62 // Extracts the raw key from the platform specific data.
63 // Warning: |raw_key| holds the raw key as bytes and thus must be handled 63 // Warning: |raw_key| holds the raw key as bytes and thus must be handled
64 // carefully. 64 // carefully.
65 bool GetRawKey(std::string* raw_key); 65 bool GetRawKey(std::string* raw_key);
66 66
67 private: 67 private:
68 #if defined(USE_OPENSSL) 68 #if defined(USE_OPENSSL)
69 // TODO(joth): Add a constructor that accepts OpenSSL symmetric key data, and 69 // Swaps in the content of the |key|.
wtc 2010/11/11 23:39:15 Just copy the key (it is <= 32 bytes), and use thi
joth 2010/11/12 12:15:53 Done. As mentioned to rsleevi, the swap() was int
wtc 2010/11/12 15:01:50 Ah, I see. It was not obvious that's the purpose
70 // the appropriate data members to store it in. 70 explicit SymmetricKey(std::string* key);
71 std::string key_;
71 #elif defined(USE_NSS) 72 #elif defined(USE_NSS)
72 explicit SymmetricKey(PK11SymKey* key); 73 explicit SymmetricKey(PK11SymKey* key);
73 ScopedPK11SymKey key_; 74 ScopedPK11SymKey key_;
74 #elif defined(OS_MACOSX) 75 #elif defined(OS_MACOSX)
75 SymmetricKey(const void* key_data, size_t key_size_in_bits); 76 SymmetricKey(const void* key_data, size_t key_size_in_bits);
76 std::string key_; 77 std::string key_;
77 #elif defined(OS_WIN) 78 #elif defined(OS_WIN)
78 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key, 79 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key,
79 const void* key_data, size_t key_size_in_bytes); 80 const void* key_data, size_t key_size_in_bytes);
80 81
81 ScopedHCRYPTPROV provider_; 82 ScopedHCRYPTPROV provider_;
82 ScopedHCRYPTKEY key_; 83 ScopedHCRYPTKEY key_;
83 84
84 // Contains the raw key, if it is known during initialization and when it 85 // Contains the raw key, if it is known during initialization and when it
85 // is likely that the associated |provider_| will be unable to export the 86 // is likely that the associated |provider_| will be unable to export the
86 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes 87 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes
87 // when using the default RSA provider. 88 // when using the default RSA provider.
88 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey 89 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey
89 // fails with NTE_BAD_KEY/NTE_BAD_LEN 90 // fails with NTE_BAD_KEY/NTE_BAD_LEN
90 std::string raw_key_; 91 std::string raw_key_;
91 #endif 92 #endif
92 93
93 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); 94 DISALLOW_COPY_AND_ASSIGN(SymmetricKey);
94 }; 95 };
95 96
96 } // namespace base 97 } // namespace base
97 98
98 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_ 99 #endif // BASE_CRYPTO_SYMMETRIC_KEY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698