]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
curve25519: Move shared secret calculation to get_shared_secret()
authorTobias Brunner <tobias@strongswan.org>
Fri, 23 Jul 2021 13:38:27 +0000 (15:38 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 29 Jun 2022 08:28:50 +0000 (10:28 +0200)
src/libstrongswan/plugins/curve25519/curve25519_dh.c

index f5deb21361bab0b74427b933229b6b45eaa0ff80..5d489d413cc82d2ffe463e2de477efa33f7dc4f0 100644 (file)
@@ -42,6 +42,11 @@ struct private_curve25519_dh_t {
         */
        bool computed;
 
+       /**
+        * Public key provided by peer
+        */
+       u_char pubkey[CURVE25519_KEY_SIZE];
+
        /**
         * Curve25519 backend
         */
@@ -78,11 +83,8 @@ METHOD(key_exchange_t, set_public_key, bool,
 {
        if (value.len == CURVE25519_KEY_SIZE)
        {
-               if (this->drv->curve25519(this->drv, value.ptr, this->shared))
-               {
-                       this->computed = TRUE;
-                       return TRUE;
-               }
+               memcpy(this->pubkey, value.ptr, value.len);
+               return TRUE;
        }
        return FALSE;
 }
@@ -114,10 +116,12 @@ METHOD(key_exchange_t, set_private_key, bool,
 METHOD(key_exchange_t, get_shared_secret, bool,
        private_curve25519_dh_t *this, chunk_t *secret)
 {
-       if (!this->computed)
+       if (!this->computed &&
+               !this->drv->curve25519(this->drv, this->pubkey, this->shared))
        {
                return FALSE;
        }
+       this->computed = TRUE;
        *secret = chunk_clone(chunk_from_thing(this->shared));
        return TRUE;
 }