Define MODP_CUSTOM constructors as variadic functions
authorTobias Brunner <tobias@strongswan.org>
Thu, 14 Sep 2017 12:03:08 +0000 (14:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 18 Sep 2017 10:07:26 +0000 (12:07 +0200)
They now match the dh_constructor_t signature.  This is a follow up for
the changes merged with b668bf3f9ec1 and should fix use of MODP_CUSTOM on
Apple's ARM64 platform.

src/libstrongswan/plugins/gcrypt/gcrypt_dh.c
src/libstrongswan/plugins/gcrypt/gcrypt_dh.h
src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
src/libstrongswan/plugins/gmp/gmp_diffie_hellman.h
src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c
src/libstrongswan/plugins/openssl/openssl_diffie_hellman.h
src/libstrongswan/plugins/pkcs11/pkcs11_dh.c
src/libstrongswan/plugins/pkcs11/pkcs11_dh.h

index cee25ea..5519125 100644 (file)
@@ -289,11 +289,13 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
 /*
  * Described in header.
  */
-gcrypt_dh_t *gcrypt_dh_create_custom(diffie_hellman_group_t group,
-                                                                        chunk_t g, chunk_t p)
+gcrypt_dh_t *gcrypt_dh_create_custom(diffie_hellman_group_t group, ...)
 {
        if (group == MODP_CUSTOM)
        {
+               chunk_t g, p;
+
+               VA_ARGS_GET(group, g, p);
                return create_generic(group, p.len, g, p);
        }
        return NULL;
index a70958d..c6259f7 100644 (file)
@@ -48,12 +48,10 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group);
  * Creates a new gcrypt_dh_t object for MODP_CUSTOM.
  *
  * @param group                        MODP_CUSTOM
- * @param g                            generator
- * @param p                            prime
+ * @param ...                  expects generator and prime as chunk_t
  * @return                             gcrypt_dh_t object, NULL if not supported
  */
-gcrypt_dh_t *gcrypt_dh_create_custom(diffie_hellman_group_t group,
-                                                                        chunk_t g, chunk_t p);
+gcrypt_dh_t *gcrypt_dh_create_custom(diffie_hellman_group_t group, ...);
 
 #endif /** GCRYPT_DH_H_ @}*/
 
index b7ee94e..b01adfe 100644 (file)
@@ -272,7 +272,7 @@ static gmp_diffie_hellman_t *create_generic(diffie_hellman_group_t group,
 }
 
 /*
- * Described in header.
+ * Described in header
  */
 gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
 {
@@ -287,12 +287,17 @@ gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
                                                  params->generator, params->prime);
 }
 
-
+/*
+ * Described in header
+ */
 gmp_diffie_hellman_t *gmp_diffie_hellman_create_custom(
-                                                       diffie_hellman_group_t group, chunk_t g, chunk_t p)
+                                                                                       diffie_hellman_group_t group, ...)
 {
        if (group == MODP_CUSTOM)
        {
+               chunk_t g, p;
+
+               VA_ARGS_GET(group, g, p);
                return create_generic(MODP_CUSTOM, p.len, g, p);
        }
        return NULL;
index 6d73c08..a8cde7b 100644 (file)
@@ -49,12 +49,11 @@ gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group);
  * Creates a new gmp_diffie_hellman_t object for MODP_CUSTOM.
  *
  * @param group                        MODP_CUSTOM
- * @param g                            generator
- * @param p                            prime
+ * @param ...                  expects generator and prime as chunk_t
  * @return                             gmp_diffie_hellman_t object, NULL if not supported
  */
 gmp_diffie_hellman_t *gmp_diffie_hellman_create_custom(
-                                                       diffie_hellman_group_t group, chunk_t g, chunk_t p);
+                                                       diffie_hellman_group_t group, ...);
 
 #endif /** GMP_DIFFIE_HELLMAN_H_ @}*/
 
index f08dfff..8e9c118 100644 (file)
@@ -193,7 +193,7 @@ METHOD(diffie_hellman_t, destroy, void,
  * Described in header.
  */
 openssl_diffie_hellman_t *openssl_diffie_hellman_create(
-                                                       diffie_hellman_group_t group, chunk_t g, chunk_t p)
+                                                                                       diffie_hellman_group_t group, ...)
 {
        private_openssl_diffie_hellman_t *this;
        const BIGNUM *privkey;
@@ -225,6 +225,9 @@ openssl_diffie_hellman_t *openssl_diffie_hellman_create(
 
        if (group == MODP_CUSTOM)
        {
+               chunk_t g, p;
+
+               VA_ARGS_GET(group, g, p);
                if (!DH_set0_pqg(this->dh, BN_bin2bn(p.ptr, p.len, NULL), NULL,
                                                 BN_bin2bn(g.ptr, g.len, NULL)))
                {
index 53dc59c..5de5520 100644 (file)
@@ -40,12 +40,11 @@ struct openssl_diffie_hellman_t {
  * Creates a new openssl_diffie_hellman_t object.
  *
  * @param group                        Diffie Hellman group number to use
- * @param g                            custom generator, if MODP_CUSTOM
- * @param p                            custom prime, if MODP_CUSTOM
+ * @param ...                  expects generator and prime as chunk_t if MODP_CUSTOM
  * @return                             openssl_diffie_hellman_t object, NULL if not supported
  */
 openssl_diffie_hellman_t *openssl_diffie_hellman_create(
-                                                       diffie_hellman_group_t group, chunk_t g, chunk_t p);
+                                                                                       diffie_hellman_group_t group, ...);
 
 #endif /** OPENSSL_DIFFIE_HELLMAN_H_ @}*/
 
index c0033bd..b0fa41b 100644 (file)
@@ -415,13 +415,15 @@ static chunk_t ecparams_lookup(diffie_hellman_group_t group)
 /**
  * Described in header.
  */
-pkcs11_dh_t *pkcs11_dh_create(diffie_hellman_group_t group,
-                                                         chunk_t g, chunk_t p)
+pkcs11_dh_t *pkcs11_dh_create(diffie_hellman_group_t group, ...)
 {
        switch (group)
        {
                case MODP_CUSTOM:
                {
+                       chunk_t g, p;
+
+                       VA_ARGS_GET(group, g, p);
                        return create_modp(group, p.len, g, p);
                }
                case ECP_192_BIT:
index 2654130..1ad58e7 100644 (file)
@@ -40,12 +40,10 @@ struct pkcs11_dh_t {
  * Creates a new pkcs11_dh_t object.
  *
  * @param group                        Diffie Hellman group number to use
- * @param g                            generator in case group is MODP_CUSTOM
- * @param p                            prime in case group is MODP_CUSTOM
+ * @param ...                  expects generator and prime as chunk_t if MODP_CUSTOM
  * @return                             pkcs11_dh_t object, NULL if not supported
  */
-pkcs11_dh_t *pkcs11_dh_create(diffie_hellman_group_t group,
-                                                         chunk_t g, chunk_t p);
+pkcs11_dh_t *pkcs11_dh_create(diffie_hellman_group_t group, ...);
 
 #endif /** PKCS11_DH_H_ @}*/