Add configure option to disable testing key exchange methods
If this is used, the functionality to set a private key/value/seed for key exchange methods is removed (including from the interface to avoid accidentally forgetting to wrap implementations and uses of set_seed()). The set_seed() method is assigned outside the INIT() macro to avoid potentially undefined behavior (preprocessing directives in macro arguments). The test done by the crypto tester is a simple functionality test.
This commit is contained in:
@@ -180,6 +180,7 @@ METHOD(key_exchange_t, set_public_key, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
|
||||
/**
|
||||
@@ -273,6 +274,7 @@ METHOD(key_exchange_t, set_seed, bool,
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_VERSION_NUMBER */
|
||||
#endif /* TESTABLE_KE */
|
||||
|
||||
METHOD(key_exchange_t, destroy, void,
|
||||
private_openssl_diffie_hellman_t *this)
|
||||
@@ -304,7 +306,6 @@ openssl_diffie_hellman_t *openssl_diffie_hellman_create(
|
||||
.get_shared_secret = _get_shared_secret,
|
||||
.set_public_key = _set_public_key,
|
||||
.get_public_key = _get_public_key,
|
||||
.set_seed = _set_seed,
|
||||
.get_method = _get_method,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
@@ -312,6 +313,10 @@ openssl_diffie_hellman_t *openssl_diffie_hellman_create(
|
||||
.group = group,
|
||||
);
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
this->public.ke.set_seed = _set_seed;
|
||||
#endif
|
||||
|
||||
if (group == MODP_CUSTOM)
|
||||
{
|
||||
chunk_t g_chunk, p_chunk;
|
||||
|
||||
@@ -305,6 +305,8 @@ int openssl_ecdh_group_to_nid(key_exchange_method_t group)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
|
||||
/**
|
||||
* Parse the given private key as BIGNUM and calculate the corresponding public
|
||||
* key as EC_POINT.
|
||||
@@ -429,6 +431,7 @@ error:
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_VERSION_NUMBER */
|
||||
#endif /* TESTABLE_KE */
|
||||
|
||||
METHOD(key_exchange_t, destroy, void,
|
||||
private_openssl_ec_diffie_hellman_t *this)
|
||||
@@ -460,7 +463,6 @@ openssl_ec_diffie_hellman_t *openssl_ec_diffie_hellman_create(key_exchange_metho
|
||||
.get_shared_secret = _get_shared_secret,
|
||||
.set_public_key = _set_public_key,
|
||||
.get_public_key = _get_public_key,
|
||||
.set_seed = _set_seed,
|
||||
.get_method = _get_method,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
@@ -468,6 +470,10 @@ openssl_ec_diffie_hellman_t *openssl_ec_diffie_hellman_create(key_exchange_metho
|
||||
.group = group,
|
||||
);
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
this->public.ke.set_seed = _set_seed;
|
||||
#endif
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
this->ec_group = EC_GROUP_new_by_curve_name(curve);
|
||||
this->key = EVP_EC_gen(OSSL_EC_curve_nid2name(curve));
|
||||
|
||||
@@ -324,6 +324,8 @@ METHOD(key_exchange_t, set_public_key, bool, private_key_exchange_t *this,
|
||||
return openssl_kem_encapsulate(this, value);
|
||||
}
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
|
||||
METHOD(key_exchange_t, set_seed, bool, private_key_exchange_t *this,
|
||||
chunk_t ignore, drbg_t *seed)
|
||||
{
|
||||
@@ -336,6 +338,8 @@ METHOD(key_exchange_t, set_seed, bool, private_key_exchange_t *this,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* TESTABLE_KE */
|
||||
|
||||
METHOD(key_exchange_t, destroy, void, private_key_exchange_t *this)
|
||||
{
|
||||
EVP_PKEY_free(this->pkey);
|
||||
@@ -357,12 +361,16 @@ key_exchange_t *openssl_kem_create(key_exchange_method_t method)
|
||||
.get_shared_secret = _get_shared_secret,
|
||||
.set_public_key = _set_public_key,
|
||||
.get_public_key = _get_public_key,
|
||||
.set_seed = _set_seed,
|
||||
.get_method = _get_method,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.group = method
|
||||
);
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
this->public.set_seed = _set_seed;
|
||||
#endif
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
#endif /* OPENSSL_IS_AWSLC */
|
||||
|
||||
@@ -114,6 +114,8 @@ METHOD(key_exchange_t, get_public_key, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
|
||||
METHOD(key_exchange_t, set_seed, bool,
|
||||
private_key_exchange_t *this, chunk_t value, drbg_t *drbg)
|
||||
{
|
||||
@@ -127,6 +129,8 @@ METHOD(key_exchange_t, set_seed, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* TESTABLE_KE */
|
||||
|
||||
METHOD(key_exchange_t, get_shared_secret, bool,
|
||||
private_key_exchange_t *this, chunk_t *secret)
|
||||
{
|
||||
@@ -193,13 +197,17 @@ key_exchange_t *openssl_x_diffie_hellman_create(key_exchange_method_t ke)
|
||||
.get_shared_secret = _get_shared_secret,
|
||||
.set_public_key = _set_public_key,
|
||||
.get_public_key = _get_public_key,
|
||||
.set_seed = _set_seed,
|
||||
.get_method = _get_method,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.ke = ke,
|
||||
.key = key,
|
||||
);
|
||||
|
||||
#ifdef TESTABLE_KE
|
||||
this->public.set_seed = _set_seed;
|
||||
#endif
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user