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

Side by Side Diff: crypto/symmetric_key.h

Issue 689463002: NACL_WIN64 takes precedence over USE_OPENSSL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@net-fix
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const std::string& salt, 50 const std::string& salt,
51 size_t iterations, 51 size_t iterations,
52 size_t key_size_in_bits); 52 size_t key_size_in_bits);
53 53
54 // 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
55 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with 55 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with
56 // 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
57 // size for use with |algorithm|. The caller owns the returned SymmetricKey. 57 // size for use with |algorithm|. The caller owns the returned SymmetricKey.
58 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key); 58 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key);
59 59
60 #if defined(USE_OPENSSL) 60 #if defined(NACL_WIN64)
61 HCRYPTKEY key() const { return key_.get(); }
62 #elif defined(USE_OPENSSL)
61 const std::string& key() { return key_; } 63 const std::string& key() { return key_; }
62 #elif defined(NACL_WIN64)
63 HCRYPTKEY key() const { return key_.get(); }
64 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 64 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
65 PK11SymKey* key() const { return key_.get(); } 65 PK11SymKey* key() const { return key_.get(); }
66 #endif 66 #endif
67 67
68 // Extracts the raw key from the platform specific data. 68 // Extracts the raw key from the platform specific data.
69 // Warning: |raw_key| holds the raw key as bytes and thus must be handled 69 // Warning: |raw_key| holds the raw key as bytes and thus must be handled
70 // carefully. 70 // carefully.
71 bool GetRawKey(std::string* raw_key); 71 bool GetRawKey(std::string* raw_key);
72 72
73 private: 73 private:
74 #if defined(USE_OPENSSL) 74 #if defined(NACL_WIN64)
75 SymmetricKey() {}
76 std::string key_;
77 #elif defined(NACL_WIN64)
78 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key, 75 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key,
79 const void* key_data, size_t key_size_in_bytes); 76 const void* key_data, size_t key_size_in_bytes);
80 77
81 ScopedHCRYPTPROV provider_; 78 ScopedHCRYPTPROV provider_;
82 ScopedHCRYPTKEY key_; 79 ScopedHCRYPTKEY key_;
83 80
84 // Contains the raw key, if it is known during initialization and when it 81 // 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 82 // 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 83 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes
87 // when using the default RSA provider. 84 // when using the default RSA provider.
88 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey 85 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey
89 // fails with NTE_BAD_KEY/NTE_BAD_LEN 86 // fails with NTE_BAD_KEY/NTE_BAD_LEN
90 std::string raw_key_; 87 std::string raw_key_;
88 #elif defined(USE_OPENSSL)
89 SymmetricKey() {}
90 std::string key_;
91 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 91 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
92 explicit SymmetricKey(PK11SymKey* key); 92 explicit SymmetricKey(PK11SymKey* key);
93 ScopedPK11SymKey key_; 93 ScopedPK11SymKey key_;
94 #endif 94 #endif
95 95
96 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); 96 DISALLOW_COPY_AND_ASSIGN(SymmetricKey);
97 }; 97 };
98 98
99 } // namespace crypto 99 } // namespace crypto
100 100
101 #endif // CRYPTO_SYMMETRIC_KEY_H_ 101 #endif // CRYPTO_SYMMETRIC_KEY_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698