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

Side by Side Diff: net/quic/crypto/curve25519_key_exchange.cc

Issue 1787453002: Switch "const StringPiece&" to just "StringPiece" in QUIC code. No functional change. Not flag prot… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116566297
Patch Set: Remove const StringPiece& from _nss crypto files. Created 4 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/crypto/curve25519_key_exchange.h ('k') | net/quic/crypto/key_exchange.h » ('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 #include "net/quic/crypto/curve25519_key_exchange.h" 5 #include "net/quic/crypto/curve25519_key_exchange.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "crypto/curve25519.h" 8 #include "crypto/curve25519.h"
9 #include "net/quic/crypto/quic_random.h" 9 #include "net/quic/crypto/quic_random.h"
10 10
11 using base::StringPiece; 11 using base::StringPiece;
12 using std::string; 12 using std::string;
13 13
14 namespace net { 14 namespace net {
15 15
16 Curve25519KeyExchange::Curve25519KeyExchange() {} 16 Curve25519KeyExchange::Curve25519KeyExchange() {}
17 17
18 Curve25519KeyExchange::~Curve25519KeyExchange() {} 18 Curve25519KeyExchange::~Curve25519KeyExchange() {}
19 19
20 // static 20 // static
21 Curve25519KeyExchange* Curve25519KeyExchange::New( 21 Curve25519KeyExchange* Curve25519KeyExchange::New(StringPiece private_key) {
22 const StringPiece& private_key) {
23 Curve25519KeyExchange* ka; 22 Curve25519KeyExchange* ka;
24 // We don't want to #include the NaCl headers in the public header file, so 23 // We don't want to #include the NaCl headers in the public header file, so
25 // we use literals for the sizes of private_key_ and public_key_. Here we 24 // we use literals for the sizes of private_key_ and public_key_. Here we
26 // assert that those values are equal to the values from the NaCl header. 25 // assert that those values are equal to the values from the NaCl header.
27 static_assert(sizeof(ka->private_key_) == crypto::curve25519::kScalarBytes, 26 static_assert(sizeof(ka->private_key_) == crypto::curve25519::kScalarBytes,
28 "header out of sync"); 27 "header out of sync");
29 static_assert(sizeof(ka->public_key_) == crypto::curve25519::kBytes, 28 static_assert(sizeof(ka->public_key_) == crypto::curve25519::kBytes,
30 "header out of sync"); 29 "header out of sync");
31 30
32 if (private_key.size() != crypto::curve25519::kScalarBytes) { 31 if (private_key.size() != crypto::curve25519::kScalarBytes) {
(...skipping 18 matching lines...) Expand all
51 private_key[31] &= 127; 50 private_key[31] &= 127;
52 private_key[31] |= 64; 51 private_key[31] |= 64;
53 return string(reinterpret_cast<char*>(private_key), sizeof(private_key)); 52 return string(reinterpret_cast<char*>(private_key), sizeof(private_key));
54 } 53 }
55 54
56 KeyExchange* Curve25519KeyExchange::NewKeyPair(QuicRandom* rand) const { 55 KeyExchange* Curve25519KeyExchange::NewKeyPair(QuicRandom* rand) const {
57 const string private_value = NewPrivateKey(rand); 56 const string private_value = NewPrivateKey(rand);
58 return Curve25519KeyExchange::New(private_value); 57 return Curve25519KeyExchange::New(private_value);
59 } 58 }
60 59
61 bool Curve25519KeyExchange::CalculateSharedKey( 60 bool Curve25519KeyExchange::CalculateSharedKey(StringPiece peer_public_value,
62 const StringPiece& peer_public_value, 61 string* out_result) const {
63 string* out_result) const {
64 if (peer_public_value.size() != crypto::curve25519::kBytes) { 62 if (peer_public_value.size() != crypto::curve25519::kBytes) {
65 return false; 63 return false;
66 } 64 }
67 65
68 uint8_t result[crypto::curve25519::kBytes]; 66 uint8_t result[crypto::curve25519::kBytes];
69 if (!crypto::curve25519::ScalarMult( 67 if (!crypto::curve25519::ScalarMult(
70 private_key_, 68 private_key_,
71 reinterpret_cast<const uint8_t*>(peer_public_value.data()), result)) { 69 reinterpret_cast<const uint8_t*>(peer_public_value.data()), result)) {
72 return false; 70 return false;
73 } 71 }
74 out_result->assign(reinterpret_cast<char*>(result), sizeof(result)); 72 out_result->assign(reinterpret_cast<char*>(result), sizeof(result));
75 73
76 return true; 74 return true;
77 } 75 }
78 76
79 StringPiece Curve25519KeyExchange::public_value() const { 77 StringPiece Curve25519KeyExchange::public_value() const {
80 return StringPiece(reinterpret_cast<const char*>(public_key_), 78 return StringPiece(reinterpret_cast<const char*>(public_key_),
81 sizeof(public_key_)); 79 sizeof(public_key_));
82 } 80 }
83 81
84 QuicTag Curve25519KeyExchange::tag() const { 82 QuicTag Curve25519KeyExchange::tag() const {
85 return kC255; 83 return kC255;
86 } 84 }
87 85
88 } // namespace net 86 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/curve25519_key_exchange.h ('k') | net/quic/crypto/key_exchange.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698