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

Unified Diff: crypto/p224_spake.cc

Issue 787803004: Update from https://crrev.com/307664 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase. Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/p224_spake.h ('k') | crypto/p224_spake_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/p224_spake.cc
diff --git a/crypto/p224_spake.cc b/crypto/p224_spake.cc
index f20b10c5ec6f0f78cf14f0e55fa52eea8cf8155f..05fe68cd05bd1a385148223996d3434e32141c6e 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
« no previous file with comments | « crypto/p224_spake.h ('k') | crypto/p224_spake_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698