| OLD | NEW |
| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "crypto/curve25519.h" | 9 #include "crypto/curve25519.h" |
| 10 #include "net/quic/crypto/quic_random.h" | 10 #include "net/quic/crypto/quic_random.h" |
| 11 | 11 |
| 12 using base::StringPiece; | 12 using base::StringPiece; |
| 13 using std::string; | 13 using std::string; |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 Curve25519KeyExchange::Curve25519KeyExchange() {} | 17 Curve25519KeyExchange::Curve25519KeyExchange() {} |
| 18 | 18 |
| 19 Curve25519KeyExchange::~Curve25519KeyExchange() {} | 19 Curve25519KeyExchange::~Curve25519KeyExchange() {} |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 Curve25519KeyExchange* Curve25519KeyExchange::New( | 22 Curve25519KeyExchange* Curve25519KeyExchange::New( |
| 23 const StringPiece& private_key) { | 23 const StringPiece& private_key) { |
| 24 Curve25519KeyExchange* ka; | 24 Curve25519KeyExchange* ka; |
| 25 // We don't want to #include the NaCl headers in the public header file, so | 25 // We don't want to #include the NaCl headers in the public header file, so |
| 26 // we use literals for the sizes of private_key_ and public_key_. Here we | 26 // we use literals for the sizes of private_key_ and public_key_. Here we |
| 27 // assert that those values are equal to the values from the NaCl header. | 27 // assert that those values are equal to the values from the NaCl header. |
| 28 COMPILE_ASSERT( | 28 static_assert(sizeof(ka->private_key_) == crypto::curve25519::kScalarBytes, |
| 29 sizeof(ka->private_key_) == crypto::curve25519::kScalarBytes, | 29 "header out of sync"); |
| 30 header_out_of_sync); | 30 static_assert(sizeof(ka->public_key_) == crypto::curve25519::kBytes, |
| 31 COMPILE_ASSERT(sizeof(ka->public_key_) == crypto::curve25519::kBytes, | 31 "header out of sync"); |
| 32 header_out_of_sync); | |
| 33 | 32 |
| 34 if (private_key.size() != crypto::curve25519::kScalarBytes) { | 33 if (private_key.size() != crypto::curve25519::kScalarBytes) { |
| 35 return nullptr; | 34 return nullptr; |
| 36 } | 35 } |
| 37 | 36 |
| 38 ka = new Curve25519KeyExchange(); | 37 ka = new Curve25519KeyExchange(); |
| 39 memcpy(ka->private_key_, private_key.data(), | 38 memcpy(ka->private_key_, private_key.data(), |
| 40 crypto::curve25519::kScalarBytes); | 39 crypto::curve25519::kScalarBytes); |
| 41 crypto::curve25519::ScalarBaseMult(ka->private_key_, ka->public_key_); | 40 crypto::curve25519::ScalarBaseMult(ka->private_key_, ka->public_key_); |
| 42 return ka; | 41 return ka; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 77 } |
| 79 | 78 |
| 80 StringPiece Curve25519KeyExchange::public_value() const { | 79 StringPiece Curve25519KeyExchange::public_value() const { |
| 81 return StringPiece(reinterpret_cast<const char*>(public_key_), | 80 return StringPiece(reinterpret_cast<const char*>(public_key_), |
| 82 sizeof(public_key_)); | 81 sizeof(public_key_)); |
| 83 } | 82 } |
| 84 | 83 |
| 85 QuicTag Curve25519KeyExchange::tag() const { return kC255; } | 84 QuicTag Curve25519KeyExchange::tag() const { return kC255; } |
| 86 | 85 |
| 87 } // namespace net | 86 } // namespace net |
| OLD | NEW |