diffie-hellman: Add enum names that match proposal keywords
authorTobias Brunner <tobias@strongswan.org>
Wed, 27 Jan 2021 13:35:37 +0000 (14:35 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 12 Feb 2021 13:35:23 +0000 (14:35 +0100)
src/libstrongswan/crypto/diffie_hellman.c
src/libstrongswan/crypto/diffie_hellman.h
src/libstrongswan/tests/suites/test_proposal.c

index efcfdbc..173882b 100644 (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.
index ce01bb3..f9459e7 100644 (file)
@@ -83,6 +83,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.
  */
 struct diffie_hellman_t {
index c323119..783b2ec 100644 (file)
 
 #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);