OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This code implements SPAKE2, a variant of EKE: | 5 // This code implements SPAKE2, a variant of EKE: |
6 // http://www.di.ens.fr/~pointche/pub.php?reference=AbPo04 | 6 // http://www.di.ens.fr/~pointche/pub.php?reference=AbPo04 |
7 | 7 |
8 #include <crypto/p224_spake.h> | 8 #include <crypto/p224_spake.h> |
9 | 9 |
10 #include <base/logging.h> | 10 #include <base/logging.h> |
11 #include <base/rand_util.h> | |
12 #include <crypto/p224.h> | 11 #include <crypto/p224.h> |
| 12 #include <crypto/random.h> |
13 #include <crypto/secure_util.h> | 13 #include <crypto/secure_util.h> |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // The following two points (M and N in the protocol) are verifiable random | 17 // The following two points (M and N in the protocol) are verifiable random |
18 // points on the curve and can be generated with the following code: | 18 // points on the curve and can be generated with the following code: |
19 | 19 |
20 // #include <stdint.h> | 20 // #include <stdint.h> |
21 // #include <stdio.h> | 21 // #include <stdio.h> |
22 // #include <string.h> | 22 // #include <string.h> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 namespace crypto { | 96 namespace crypto { |
97 | 97 |
98 P224EncryptedKeyExchange::P224EncryptedKeyExchange( | 98 P224EncryptedKeyExchange::P224EncryptedKeyExchange( |
99 PeerType peer_type, const base::StringPiece& password) | 99 PeerType peer_type, const base::StringPiece& password) |
100 : state_(kStateInitial), | 100 : state_(kStateInitial), |
101 is_server_(peer_type == kPeerTypeServer) { | 101 is_server_(peer_type == kPeerTypeServer) { |
102 memset(&x_, 0, sizeof(x_)); | 102 memset(&x_, 0, sizeof(x_)); |
103 memset(&expected_authenticator_, 0, sizeof(expected_authenticator_)); | 103 memset(&expected_authenticator_, 0, sizeof(expected_authenticator_)); |
104 | 104 |
105 // x_ is a random scalar. | 105 // x_ is a random scalar. |
106 base::RandBytes(x_, sizeof(x_)); | 106 RandBytes(x_, sizeof(x_)); |
107 | 107 |
108 // X = g**x_ | 108 // X = g**x_ |
109 p224::Point X; | 109 p224::Point X; |
110 p224::ScalarBaseMult(x_, &X); | 110 p224::ScalarBaseMult(x_, &X); |
111 | 111 |
112 // Calculate |password| hash to get SPAKE password value. | 112 // Calculate |password| hash to get SPAKE password value. |
113 SHA256HashString(std::string(password.data(), password.length()), | 113 SHA256HashString(std::string(password.data(), password.length()), |
114 pw_, sizeof(pw_)); | 114 pw_, sizeof(pw_)); |
115 | 115 |
116 // The client masks the Diffie-Hellman value, X, by adding M**pw and the | 116 // The client masks the Diffie-Hellman value, X, by adding M**pw and the |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 const std::string& P224EncryptedKeyExchange::error() const { | 239 const std::string& P224EncryptedKeyExchange::error() const { |
240 return error_; | 240 return error_; |
241 } | 241 } |
242 | 242 |
243 const std::string& P224EncryptedKeyExchange::GetKey() { | 243 const std::string& P224EncryptedKeyExchange::GetKey() { |
244 DCHECK_EQ(state_, kStateDone); | 244 DCHECK_EQ(state_, kStateDone); |
245 return key_; | 245 return key_; |
246 } | 246 } |
247 | 247 |
248 } // namespace crypto | 248 } // namespace crypto |
OLD | NEW |