aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/ecdh/ecdh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pubkey/ecdh/ecdh.cpp')
-rw-r--r--src/pubkey/ecdh/ecdh.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/pubkey/ecdh/ecdh.cpp b/src/pubkey/ecdh/ecdh.cpp
index 7ecc40ae4..37dc7c392 100644
--- a/src/pubkey/ecdh/ecdh.cpp
+++ b/src/pubkey/ecdh/ecdh.cpp
@@ -11,6 +11,27 @@
namespace Botan {
+ECDH_KA_Operation::ECDH_KA_Operation(const ECDH_PrivateKey& key)
+ {
+ cofactor = key.domain().get_cofactor();
+
+ curve = key.domain().get_curve();
+
+ l_times_priv = inverse_mod(cofactor, key.domain().get_order()) *
+ key.private_value();
+ }
+
+SecureVector<byte> ECDH_KA_Operation::agree(const byte w[], u32bit w_len) const
+ {
+ PointGFp point = OS2ECP(w, w_len, curve);
+
+ PointGFp S = (cofactor * point) * l_times_priv;
+ S.check_invariants();
+
+ return BigInt::encode_1363(S.get_affine_x(),
+ curve.get_p().bytes());
+ }
+
/**
* Derive a key
*/