summaryrefslogtreecommitdiffstats
path: root/crypto/p224_spake.cc
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@chromium.org>2014-12-09 23:54:15 -0800
committerVitaly Buka <vitalybuka@chromium.org>2014-12-10 07:55:48 +0000
commitbd85b5694eac20c787820edb1e70915e90283a43 (patch)
tree5d3fad905ec66a2a049cb7a31f190f2e318cf5d9 /crypto/p224_spake.cc
parentef3b866e783a1b5f1adf8f812b6ab240a146c300 (diff)
downloadchromium_src-bd85b5694eac20c787820edb1e70915e90283a43.zip
chromium_src-bd85b5694eac20c787820edb1e70915e90283a43.tar.gz
chromium_src-bd85b5694eac20c787820edb1e70915e90283a43.tar.bz2
Added unittest to make sure future changes in P224EncryptedKeyExchange don't change output.
External implementations already expect this values. BUG=438470 R=agl@chromium.org, gene@chromium.org Review URL: https://codereview.chromium.org/789743002 Cr-Commit-Position: refs/heads/master@{#307654}
Diffstat (limited to 'crypto/p224_spake.cc')
-rw-r--r--crypto/p224_spake.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/crypto/p224_spake.cc b/crypto/p224_spake.cc
index f20b10c..05fe68c 100644
--- a/crypto/p224_spake.cc
+++ b/crypto/p224_spake.cc
@@ -7,6 +7,8 @@
#include <crypto/p224_spake.h>
+#include <algorithm>
+
#include <base/logging.h>
#include <crypto/p224.h>
#include <crypto/random.h>
@@ -105,14 +107,18 @@ P224EncryptedKeyExchange::P224EncryptedKeyExchange(
// x_ is a random scalar.
RandBytes(x_, sizeof(x_));
- // X = g**x_
- p224::Point X;
- p224::ScalarBaseMult(x_, &X);
-
// Calculate |password| hash to get SPAKE password value.
SHA256HashString(std::string(password.data(), password.length()),
pw_, sizeof(pw_));
+ Init();
+}
+
+void P224EncryptedKeyExchange::Init() {
+ // X = g**x_
+ p224::Point X;
+ p224::ScalarBaseMult(x_, &X);
+
// The client masks the Diffie-Hellman value, X, by adding M**pw and the
// server uses N**pw.
p224::Point MNpw;
@@ -253,4 +259,10 @@ const std::string& P224EncryptedKeyExchange::GetUnverifiedKey() const {
return key_;
}
+void P224EncryptedKeyExchange::SetXForTesting(const std::string& x) {
+ memset(&x_, 0, sizeof(x_));
+ memcpy(&x_, x.data(), std::min(x.size(), sizeof(x_)));
+ Init();
+}
+
} // namespace crypto