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

Side by Side Diff: crypto/symmetric_key.h

Issue 1924093006: Removing crypto/third_party/nss/ and removing crypto _win files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused sources. Created 4 years, 7 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
« no previous file with comments | « crypto/hmac_win.cc ('k') | crypto/symmetric_key.cc » ('j') | 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 <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)
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.
19 #include "crypto/scoped_capi_types.h"
20 #endif
21
22 namespace crypto { 16 namespace crypto {
23 17
24 // Wraps a platform-specific symmetric key and allows it to be held in a 18 // Wraps a platform-specific symmetric key and allows it to be held in a
25 // scoped_ptr. 19 // scoped_ptr.
26 class CRYPTO_EXPORT SymmetricKey { 20 class CRYPTO_EXPORT SymmetricKey {
27 public: 21 public:
28 // Defines the algorithm that a key will be used with. See also 22 // Defines the algorithm that a key will be used with. See also
29 // classs Encrptor. 23 // classs Encrptor.
30 enum Algorithm { 24 enum Algorithm {
31 AES, 25 AES,
(...skipping 18 matching lines...) Expand all
50 const std::string& salt, 44 const std::string& salt,
51 size_t iterations, 45 size_t iterations,
52 size_t key_size_in_bits); 46 size_t key_size_in_bits);
53 47
54 // Imports an array of key bytes in |raw_key|. This key may have been 48 // Imports an array of key bytes in |raw_key|. This key may have been
55 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with 49 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with
56 // GetRawKey, or via another compatible method. The key must be of suitable 50 // GetRawKey, or via another compatible method. The key must be of suitable
57 // size for use with |algorithm|. The caller owns the returned SymmetricKey. 51 // size for use with |algorithm|. The caller owns the returned SymmetricKey.
58 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key); 52 static SymmetricKey* Import(Algorithm algorithm, const std::string& raw_key);
59 53
60 #if defined(NACL_WIN64)
61 HCRYPTKEY key() const { return key_.get(); }
62 #else
63 const std::string& key() { return key_; } 54 const std::string& key() { return key_; }
64 #endif
65 55
66 // Extracts the raw key from the platform specific data. 56 // Extracts the raw key from the platform specific data.
67 // Warning: |raw_key| holds the raw key as bytes and thus must be handled 57 // Warning: |raw_key| holds the raw key as bytes and thus must be handled
68 // carefully. 58 // carefully.
69 bool GetRawKey(std::string* raw_key); 59 bool GetRawKey(std::string* raw_key);
70 60
71 private: 61 private:
72 #if defined(NACL_WIN64)
73 SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key,
74 const void* key_data, size_t key_size_in_bytes);
75
76 ScopedHCRYPTPROV provider_;
77 ScopedHCRYPTKEY key_;
78
79 // Contains the raw key, if it is known during initialization and when it
80 // is likely that the associated |provider_| will be unable to export the
81 // |key_|. This is the case of HMAC keys when the key size exceeds 16 bytes
82 // when using the default RSA provider.
83 // TODO(rsleevi): See if KP_EFFECTIVE_KEYLEN is the reason why CryptExportKey
84 // fails with NTE_BAD_KEY/NTE_BAD_LEN
85 std::string raw_key_;
86 #else
87 SymmetricKey() {} 62 SymmetricKey() {}
88 std::string key_; 63 std::string key_;
89 #endif
90 64
91 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); 65 DISALLOW_COPY_AND_ASSIGN(SymmetricKey);
92 }; 66 };
93 67
94 } // namespace crypto 68 } // namespace crypto
95 69
96 #endif // CRYPTO_SYMMETRIC_KEY_H_ 70 #endif // CRYPTO_SYMMETRIC_KEY_H_
OLDNEW
« no previous file with comments | « crypto/hmac_win.cc ('k') | crypto/symmetric_key.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698