]> git.ipfire.org Git - thirdparty/strongswan.git/blobdiff - src/libstrongswan/tests/suites/test_proposal.c
proposal: Don't specify key length for ChaCha20/Poly1305
[thirdparty/strongswan.git] / src / libstrongswan / tests / suites / test_proposal.c
index 9f8cc7e1f638b0f46d1c5af70fcd09e46c6289dc..938fa38aa8c2f50e01e6d7c2771132021283f3ce 100644 (file)
@@ -29,6 +29,8 @@ static struct {
        { PROTO_IKE, "aes128", NULL },
        { PROTO_IKE, "aes128-sha256", NULL },
        { PROTO_IKE, "aes128-sha256-modpnone", NULL },
+       { PROTO_IKE, "aes128-prfsha256", NULL },
+       { PROTO_IKE, "aes128-prfsha256-modp2048", NULL },
        { PROTO_IKE, "aes128-sha256-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072" },
        { PROTO_IKE, "aes128-sha256-prfsha384-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_384/MODP_3072" },
        { PROTO_IKE, "aes128gcm16-modp3072", NULL },
@@ -212,6 +214,23 @@ START_TEST(test_unknown_transform_types_print)
 }
 END_TEST
 
+START_TEST(test_unknown_transform_types_equals)
+{
+       proposal_t *self, *other;
+
+       self = proposal_create_from_string(PROTO_IKE, "aes128-sha256-ecp256");
+       other = proposal_create_from_string(PROTO_IKE, "aes128-sha256-ecp256");
+       other->add_algorithm(other, 242, 42, 0);
+       ck_assert(!self->equals(self, other));
+       ck_assert(!other->equals(other, self));
+       self->add_algorithm(self, 242, 42, 0);
+       ck_assert(self->equals(self, other));
+       ck_assert(other->equals(other, self));
+       other->destroy(other);
+       self->destroy(self);
+}
+END_TEST
+
 START_TEST(test_unknown_transform_types_select_fail)
 {
        proposal_t *self, *other, *selected;
@@ -262,6 +281,19 @@ START_TEST(test_unknown_transform_types_select_success)
 }
 END_TEST
 
+START_TEST(test_chacha20_poly1305_key_length)
+{
+       proposal_t *proposal;
+       uint16_t alg, ks;
+
+       proposal = proposal_create_from_string(PROTO_IKE, "chacha20poly1305-prfsha256-ecp256");
+       proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM, &alg, &ks);
+       ck_assert_int_eq(alg, ENCR_CHACHA20_POLY1305);
+       ck_assert_int_eq(ks, 0);
+       assert_proposal_eq(proposal, "IKE:CHACHA20_POLY1305/PRF_HMAC_SHA2_256/ECP_256");
+       proposal->destroy(proposal);
+}
+END_TEST
 
 
 Suite *proposal_suite_create()
@@ -288,10 +320,15 @@ Suite *proposal_suite_create()
 
        tc = tcase_create("unknown transform types");
        tcase_add_test(tc, test_unknown_transform_types_print);
+       tcase_add_test(tc, test_unknown_transform_types_equals);
        tcase_add_test(tc, test_unknown_transform_types_select_fail);
        tcase_add_test(tc, test_unknown_transform_types_select_fail_subtype);
        tcase_add_test(tc, test_unknown_transform_types_select_success);
        suite_add_tcase(s, tc);
 
+       tc = tcase_create("chacha20/poly1305");
+       tcase_add_test(tc, test_chacha20_poly1305_key_length);
+       suite_add_tcase(s, tc);
+
        return s;
 }