aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/dh/dh.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-28 07:54:22 -0400
committerJack Lloyd <[email protected]>2018-03-28 07:54:22 -0400
commit0787c4b05b1bba7276846839a4b372539ee370ec (patch)
treeaa331919e17028f7de15e6228637ecd199750cc9 /src/lib/pubkey/dh/dh.cpp
parent94aab66b934474dc7191f5c17601b9e58f1a7895 (diff)
Minor DH optimization
Saves 30k-170k cycles depending on param size.
Diffstat (limited to 'src/lib/pubkey/dh/dh.cpp')
-rw-r--r--src/lib/pubkey/dh/dh.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/pubkey/dh/dh.cpp b/src/lib/pubkey/dh/dh.cpp
index b8b09ec3f..fc1e6236a 100644
--- a/src/lib/pubkey/dh/dh.cpp
+++ b/src/lib/pubkey/dh/dh.cpp
@@ -105,14 +105,16 @@ class DH_KA_Operation final : public PK_Ops::Key_Agreement_with_KDF
secure_vector<uint8_t> DH_KA_Operation::raw_agree(const uint8_t w[], size_t w_len)
{
- BigInt input = BigInt::decode(w, w_len);
+ BigInt x = BigInt::decode(w, w_len);
- if(input <= 1 || input >= m_p - 1)
+ if(x <= 1 || x >= m_p - 1)
throw Invalid_Argument("DH agreement - invalid key provided");
- BigInt r = m_blinder.unblind(m_powermod_x_p(m_blinder.blind(input)));
+ x = m_blinder.blind(x);
+ x = m_powermod_x_p(x);
+ x = m_blinder.unblind(x);
- return BigInt::encode_1363(r, m_p.bytes());
+ return BigInt::encode_1363(x, m_p.bytes());
}
}