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

Side by Side Diff: crypto/symmetric_key.h

Issue 1882433002: Removing NSS files and USE_OPENSSL flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing header ordering. Created 4 years, 8 months 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
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "crypto/crypto_export.h" 14 #include "crypto/crypto_export.h"
15 15
16 #if defined(NACL_WIN64) 16 #if defined(NACL_WIN64)
17 // See comments for crypto_nacl_win64 in crypto.gyp. 17 // See comments for crypto_nacl_win64 in crypto.gyp.
18 // Must test for NACL_WIN64 before OS_WIN since former is a subset of latter. 18 // Must test for NACL_WIN64 before OS_WIN since former is a subset of latter.
19 #include "crypto/scoped_capi_types.h" 19 #include "crypto/scoped_capi_types.h"
20 #elif defined(USE_NSS_CERTS) || \ 20 #elif defined(USE_NSS_CERTS)
davidben 2016/04/18 19:36:45 This looks like I messed up from doing the chimera
svaldez 2016/04/18 20:21:39 Done.
21 (!defined(USE_OPENSSL) && (defined(OS_WIN) || defined(OS_MACOSX)))
22 #include "crypto/scoped_nss_types.h" 21 #include "crypto/scoped_nss_types.h"
23 #endif 22 #endif
24 23
25 namespace crypto { 24 namespace crypto {
26 25
27 // Wraps a platform-specific symmetric key and allows it to be held in a 26 // Wraps a platform-specific symmetric key and allows it to be held in a
28 // scoped_ptr. 27 // scoped_ptr.
29 class CRYPTO_EXPORT SymmetricKey { 28 class CRYPTO_EXPORT SymmetricKey {
30 public: 29 public:
31 // Defines the algorithm that a key will be used with. See also 30 // Defines the algorithm that a key will be used with. See also
(...skipping 23 matching lines...) Expand all
55 size_t key_size_in_bits); 54 size_t key_size_in_bits);
56 55
57 // Imports an array of key bytes in |raw_key|. This key may have been 56 // Imports an array of key bytes in |raw_key|. This key may have been
58 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with 57 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with
59 // GetRawKey, or via another compatible method. The key must be of suitable 58 // GetRawKey, or via another compatible method. The key must be of suitable
60 // size for use with |algorithm|. The caller owns the returned SymmetricKey. 59 // size for use with |algorithm|. The caller owns the returned SymmetricKey.
61 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key); 60 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key);
62 61
63 #if defined(NACL_WIN64) 62 #if defined(NACL_WIN64)
64 HCRYPTKEY key() const { return key_.get(); } 63 HCRYPTKEY key() const { return key_.get(); }
65 #elif defined(USE_OPENSSL) 64 #else
66 const std::string& key() { return key_; } 65 const std::string& key() { return key_; }
67 #elif defined(USE_NSS_CERTS) || defined(OS_WIN) || defined(OS_MACOSX)
68 PK11SymKey* key() const { return key_.get(); }
69 #endif 66 #endif
70 67
71 // Extracts the raw key from the platform specific data. 68 // Extracts the raw key from the platform specific data.
72 // 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
73 // carefully. 70 // carefully.
74 bool GetRawKey(std::string* raw_key); 71 bool GetRawKey(std::string* raw_key);
75 72
76 private: 73 private:
77 #if defined(NACL_WIN64) 74 #if 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_;
91 #elif defined(USE_OPENSSL) 88 #else
92 SymmetricKey() {} 89 SymmetricKey() {}
93 std::string key_; 90 std::string key_;
94 #elif defined(USE_NSS_CERTS) || defined(OS_WIN) || defined(OS_MACOSX)
95 explicit SymmetricKey(PK11SymKey* key);
96 ScopedPK11SymKey key_;
97 #endif 91 #endif
98 92
99 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); 93 DISALLOW_COPY_AND_ASSIGN(SymmetricKey);
100 }; 94 };
101 95
102 } // namespace crypto 96 } // namespace crypto
103 97
104 #endif // CRYPTO_SYMMETRIC_KEY_H_ 98 #endif // CRYPTO_SYMMETRIC_KEY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698