| 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool Curve25519KeyExchange::CalculateSharedKey( | 62 bool Curve25519KeyExchange::CalculateSharedKey( |
| 63 const StringPiece& peer_public_value, | 63 const StringPiece& peer_public_value, |
| 64 string* out_result) const { | 64 string* out_result) const { |
| 65 if (peer_public_value.size() != crypto::curve25519::kBytes) { | 65 if (peer_public_value.size() != crypto::curve25519::kBytes) { |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 uint8 result[crypto::curve25519::kBytes]; | 69 uint8 result[crypto::curve25519::kBytes]; |
| 70 crypto::curve25519::ScalarMult( | 70 if (!crypto::curve25519::ScalarMult( |
| 71 private_key_, | 71 private_key_, |
| 72 reinterpret_cast<const uint8*>(peer_public_value.data()), | 72 reinterpret_cast<const uint8*>(peer_public_value.data()), result)) { |
| 73 result); | 73 return false; |
| 74 } |
| 74 out_result->assign(reinterpret_cast<char*>(result), sizeof(result)); | 75 out_result->assign(reinterpret_cast<char*>(result), sizeof(result)); |
| 75 | 76 |
| 76 return true; | 77 return true; |
| 77 } | 78 } |
| 78 | 79 |
| 79 StringPiece Curve25519KeyExchange::public_value() const { | 80 StringPiece Curve25519KeyExchange::public_value() const { |
| 80 return StringPiece(reinterpret_cast<const char*>(public_key_), | 81 return StringPiece(reinterpret_cast<const char*>(public_key_), |
| 81 sizeof(public_key_)); | 82 sizeof(public_key_)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 QuicTag Curve25519KeyExchange::tag() const { return kC255; } | 85 QuicTag Curve25519KeyExchange::tag() const { return kC255; } |
| 85 | 86 |
| 86 } // namespace net | 87 } // namespace net |
| OLD | NEW |