]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
botan: Remove unused drbg_t instance when building without testable KE
authorTobias Brunner <tobias@strongswan.org>
Fri, 23 May 2025 09:33:32 +0000 (11:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 27 May 2025 15:38:32 +0000 (17:38 +0200)
src/libstrongswan/plugins/botan/botan_kem.c

index e01dbdfeef8f6cefcaecc743a1c6f6ac5ea8eb50..8a1219dcc19b2fa25f278baf94539512f092ffde 100644 (file)
@@ -76,12 +76,16 @@ struct private_key_exchange_t {
         */
        chunk_t shared_secret;
 
+#ifdef TESTABLE_KE
        /**
         * DRBG for testing.
         */
        drbg_t *drbg;
+#endif
 };
 
+#ifdef TESTABLE_KE
+
 CALLBACK(get_random, int,
        drbg_t *drbg, uint8_t *out, size_t out_len)
 {
@@ -92,17 +96,21 @@ CALLBACK(get_random, int,
        return 0;
 }
 
+#endif /* TESTABLE_KE */
+
 /**
  * Initializes the given RNG, either based on a DRBG during testing or using
  * the plugin's configured RNG.
  */
 static bool get_rng(private_key_exchange_t *this, botan_rng_t *rng)
 {
+#ifdef TESTABLE_KE
        if (this->drbg)
        {
                return !botan_rng_init_custom(rng, "kem-drbg", this->drbg,
                                                                          get_random, NULL, NULL);
        }
+#endif
        return botan_get_rng(rng, RNG_STRONG);
 }
 
@@ -121,6 +129,7 @@ CALLBACK(botan_view_to_chunk, int,
  */
 static bool generate_keypair(private_key_exchange_t *this)
 {
+#ifdef TESTABLE_KE
        if (this->drbg)
        {
                uint8_t random[ML_KEM_SEED_LEN];
@@ -135,6 +144,7 @@ static bool generate_keypair(private_key_exchange_t *this)
                }
        }
        else
+#endif /* TESTABLE_KE */
        {
                botan_rng_t rng = NULL;
 
@@ -313,7 +323,9 @@ METHOD(key_exchange_t, destroy, void,
        chunk_clear(&this->shared_secret);
        chunk_free(&this->ciphertext);
        botan_privkey_destroy(this->kem);
+#ifdef TESTABLE_KE
        DESTROY_IF(this->drbg);
+#endif
        free(this->name);
        free(this);
 }