diffie-hellman: Add enum names that match proposal keywords

This commit is contained in:
Tobias Brunner
2021-02-12 14:35:23 +01:00
parent 066ac8809c
commit 9514aa2dcc
3 changed files with 74 additions and 0 deletions
+39
View File
@@ -57,6 +57,45 @@ ENUM_NEXT(diffie_hellman_group_names, MODP_CUSTOM, MODP_CUSTOM, NH_128_BIT,
"MODP_CUSTOM");
ENUM_END(diffie_hellman_group_names, MODP_CUSTOM);
ENUM_BEGIN(diffie_hellman_group_names_short, MODP_NONE, MODP_1024_BIT,
"modpnone",
"modp768",
"modp1024");
ENUM_NEXT(diffie_hellman_group_names_short, MODP_1536_BIT, MODP_1536_BIT, MODP_1024_BIT,
"modp1536");
ENUM_NEXT(diffie_hellman_group_names_short, MODP_2048_BIT, ECP_521_BIT, MODP_1536_BIT,
"modp2048",
"modp3072",
"modp4096",
"modp6144",
"modp8192",
"ecp256",
"ecp384",
"ecp521");
ENUM_NEXT(diffie_hellman_group_names_short, MODP_1024_160, CURVE_448, ECP_521_BIT,
"modp1024s160",
"modp2048s224",
"modp2048s256",
"ecp192",
"ecp224",
"ecp224bp",
"ecp256bp",
"ecp384bp",
"ecp512bp",
"curve25519",
"curve448");
ENUM_NEXT(diffie_hellman_group_names_short, MODP_NULL, MODP_NULL, CURVE_448,
"modpnull");
ENUM_NEXT(diffie_hellman_group_names_short, NTRU_112_BIT, NTRU_256_BIT, MODP_NULL,
"ntru112",
"ntru128",
"ntru192",
"ntru256");
ENUM_NEXT(diffie_hellman_group_names_short, NH_128_BIT, NH_128_BIT, NTRU_256_BIT,
"newhope128");
ENUM_NEXT(diffie_hellman_group_names_short, MODP_CUSTOM, MODP_CUSTOM, NH_128_BIT,
"modpcustom");
ENUM_END(diffie_hellman_group_names_short, MODP_CUSTOM);
/**
* List of known diffie hellman group parameters.
@@ -82,6 +82,11 @@ enum diffie_hellman_group_t {
*/
extern enum_name_t *diffie_hellman_group_names;
/**
* enum names for diffie_hellman_group_t (matching proposal keywords).
*/
extern enum_name_t *diffie_hellman_group_names_short;
/**
* Implementation of the Diffie-Hellman algorithm, as in RFC2631.
*/
@@ -17,6 +17,32 @@
#include <crypto/proposal/proposal.h>
START_TEST(test_dh_group_mapping)
{
enum_name_t *e = diffie_hellman_group_names_short;
diffie_hellman_group_t group;
const proposal_token_t *token;
char *name;
do
{
for (group = e->first; group <= e->last; group++)
{
if (group == MODP_CUSTOM)
{ /* can't be configured */
continue;
}
name = e->names[group - e->first];
token = lib->proposal->get_token(lib->proposal, name);
ck_assert_msg(token, "%s can't be mapped", name);
ck_assert_int_eq(token->type, DIFFIE_HELLMAN_GROUP);
ck_assert_int_eq(token->algorithm, group);
}
}
while ((e = e->next));
}
END_TEST
static struct {
protocol_id_t proto;
char *proposal;
@@ -456,6 +482,10 @@ Suite *proposal_suite_create()
s = suite_create("proposal");
tc = tcase_create("proposal keywords");
tcase_add_test(tc, test_dh_group_mapping);
suite_add_tcase(s, tc);
tc = tcase_create("create_from_string");
tcase_add_loop_test(tc, test_create_from_string, 0, countof(create_data));
suite_add_tcase(s, tc);