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

Side by Side Diff: net/quic/core/crypto/p256_key_exchange.h

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 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 | « net/quic/core/crypto/null_encrypter_test.cc ('k') | net/quic/core/crypto/p256_key_exchange.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_ 5 #ifndef NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_
6 #define NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_ 6 #define NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_
7 7
8 #include <cstdint> 8 #include <cstdint>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/string_piece.h"
13 #include "net/quic/core/crypto/key_exchange.h" 12 #include "net/quic/core/crypto/key_exchange.h"
14 #include "net/quic/platform/api/quic_export.h" 13 #include "net/quic/platform/api/quic_export.h"
14 #include "net/quic/platform/api/quic_string_piece.h"
15 #include "third_party/boringssl/src/include/openssl/base.h" 15 #include "third_party/boringssl/src/include/openssl/base.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 // P256KeyExchange implements a KeyExchange using elliptic-curve 19 // P256KeyExchange implements a KeyExchange using elliptic-curve
20 // Diffie-Hellman on NIST P-256. 20 // Diffie-Hellman on NIST P-256.
21 class QUIC_EXPORT_PRIVATE P256KeyExchange : public KeyExchange { 21 class QUIC_EXPORT_PRIVATE P256KeyExchange : public KeyExchange {
22 public: 22 public:
23 ~P256KeyExchange() override; 23 ~P256KeyExchange() override;
24 24
25 // New creates a new key exchange object from a private key. If 25 // New creates a new key exchange object from a private key. If
26 // |private_key| is invalid, nullptr is returned. 26 // |private_key| is invalid, nullptr is returned.
27 static P256KeyExchange* New(base::StringPiece private_key); 27 static P256KeyExchange* New(QuicStringPiece private_key);
28 28
29 // |NewPrivateKey| returns a private key, suitable for passing to |New|. 29 // |NewPrivateKey| returns a private key, suitable for passing to |New|.
30 // If |NewPrivateKey| can't generate a private key, it returns an empty 30 // If |NewPrivateKey| can't generate a private key, it returns an empty
31 // string. 31 // string.
32 static std::string NewPrivateKey(); 32 static std::string NewPrivateKey();
33 33
34 // KeyExchange interface. 34 // KeyExchange interface.
35 KeyExchange* NewKeyPair(QuicRandom* rand) const override; 35 KeyExchange* NewKeyPair(QuicRandom* rand) const override;
36 bool CalculateSharedKey(base::StringPiece peer_public_value, 36 bool CalculateSharedKey(QuicStringPiece peer_public_value,
37 std::string* shared_key) const override; 37 std::string* shared_key) const override;
38 base::StringPiece public_value() const override; 38 QuicStringPiece public_value() const override;
39 QuicTag tag() const override; 39 QuicTag tag() const override;
40 40
41 private: 41 private:
42 enum { 42 enum {
43 // A P-256 field element consists of 32 bytes. 43 // A P-256 field element consists of 32 bytes.
44 kP256FieldBytes = 32, 44 kP256FieldBytes = 32,
45 // A P-256 point in uncompressed form consists of 0x04 (to denote 45 // A P-256 point in uncompressed form consists of 0x04 (to denote
46 // that the point is uncompressed) followed by two, 32-byte field 46 // that the point is uncompressed) followed by two, 32-byte field
47 // elements. 47 // elements.
48 kUncompressedP256PointBytes = 1 + 2 * kP256FieldBytes, 48 kUncompressedP256PointBytes = 1 + 2 * kP256FieldBytes,
49 // The first byte in an uncompressed P-256 point. 49 // The first byte in an uncompressed P-256 point.
50 kUncompressedECPointForm = 0x04, 50 kUncompressedECPointForm = 0x04,
51 }; 51 };
52 52
53 // P256KeyExchange wraps |private_key|, and expects |public_key| consists of 53 // P256KeyExchange wraps |private_key|, and expects |public_key| consists of
54 // |kUncompressedP256PointBytes| bytes. 54 // |kUncompressedP256PointBytes| bytes.
55 P256KeyExchange(bssl::UniquePtr<EC_KEY> private_key, 55 P256KeyExchange(bssl::UniquePtr<EC_KEY> private_key,
56 const uint8_t* public_key); 56 const uint8_t* public_key);
57 57
58 bssl::UniquePtr<EC_KEY> private_key_; 58 bssl::UniquePtr<EC_KEY> private_key_;
59 // The public key stored as an uncompressed P-256 point. 59 // The public key stored as an uncompressed P-256 point.
60 uint8_t public_key_[kUncompressedP256PointBytes]; 60 uint8_t public_key_[kUncompressedP256PointBytes];
61 61
62 DISALLOW_COPY_AND_ASSIGN(P256KeyExchange); 62 DISALLOW_COPY_AND_ASSIGN(P256KeyExchange);
63 }; 63 };
64 64
65 } // namespace net 65 } // namespace net
66 66
67 #endif // NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_ 67 #endif // NET_QUIC_CORE_CRYPTO_P256_KEY_EXCHANGE_H_
OLDNEW
« no previous file with comments | « net/quic/core/crypto/null_encrypter_test.cc ('k') | net/quic/core/crypto/p256_key_exchange.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698