From: Tobias Brunner Date: Sat, 19 Jul 2025 10:10:25 +0000 (+0200) Subject: wolfssl: Store RNG on object for curve25519 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=011c346b003572730ce6eb398c0d3d64a813d0cf;p=thirdparty%2Fstrongswan.git wolfssl: Store RNG on object for curve25519 5.8.2 enables blinding for curve25519 by default, so the RNG set when making the key is also used later on. --- diff --git a/src/libstrongswan/plugins/wolfssl/wolfssl_x_diffie_hellman.c b/src/libstrongswan/plugins/wolfssl/wolfssl_x_diffie_hellman.c index 821d590907..8cf824918b 100644 --- a/src/libstrongswan/plugins/wolfssl/wolfssl_x_diffie_hellman.c +++ b/src/libstrongswan/plugins/wolfssl/wolfssl_x_diffie_hellman.c @@ -84,6 +84,11 @@ struct private_diffie_hellman_t { * Shared secret */ chunk_t shared_secret; + + /** + * RNG used for key generation and blinding with curve25519 + */ + WC_RNG rng; }; #ifdef HAVE_CURVE25519 @@ -289,6 +294,7 @@ METHOD(key_exchange_t, destroy, void, #endif } chunk_clear(&this->shared_secret); + wc_FreeRng(&this->rng); free(this); } @@ -298,7 +304,6 @@ METHOD(key_exchange_t, destroy, void, key_exchange_t *wolfssl_x_diffie_hellman_create(key_exchange_method_t group) { private_diffie_hellman_t *this; - WC_RNG rng; int ret = -1; INIT(this, @@ -309,7 +314,7 @@ key_exchange_t *wolfssl_x_diffie_hellman_create(key_exchange_method_t group) .group = group, ); - if (wc_InitRng(&rng) != 0) + if (wc_InitRng(&this->rng) != 0) { DBG1(DBG_LIB, "initializing a random number generator failed"); destroy(this); @@ -325,7 +330,6 @@ key_exchange_t *wolfssl_x_diffie_hellman_create(key_exchange_method_t group) #ifdef TESTABLE_KE this->public.set_seed = _set_seed_25519; #endif - if (wc_curve25519_init(&this->key.key25519) != 0 || wc_curve25519_init(&this->pub.key25519) != 0) { @@ -333,7 +337,7 @@ key_exchange_t *wolfssl_x_diffie_hellman_create(key_exchange_method_t group) destroy(this); return NULL; } - ret = wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, + ret = wc_curve25519_make_key(&this->rng, CURVE25519_KEYSIZE, &this->key.key25519); #endif } @@ -354,13 +358,14 @@ key_exchange_t *wolfssl_x_diffie_hellman_create(key_exchange_method_t group) destroy(this); return NULL; } - ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &this->key.key448); + ret = wc_curve448_make_key(&this->rng, CURVE448_KEY_SIZE, + &this->key.key448); #endif } - wc_FreeRng(&rng); if (ret != 0) { - DBG1(DBG_LIB, "making a key failed"); + DBG1(DBG_LIB, "making %N key failed", key_exchange_method_names, + this->group); destroy(this); return NULL; }