aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins')
-rw-r--r--src/libstrongswan/plugins/gcrypt/gcrypt_dh.c15
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c23
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c7
3 files changed, 27 insertions, 18 deletions
diff --git a/src/libstrongswan/plugins/gcrypt/gcrypt_dh.c b/src/libstrongswan/plugins/gcrypt/gcrypt_dh.c
index ca730f9cd..08d6239ad 100644
--- a/src/libstrongswan/plugins/gcrypt/gcrypt_dh.c
+++ b/src/libstrongswan/plugins/gcrypt/gcrypt_dh.c
@@ -203,15 +203,24 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
this->public.dh.destroy = (void (*)(diffie_hellman_t *)) destroy;
this->group = group;
- this->p_len = params->prime_len;
+ this->p_len = params->prime.len;
err = gcry_mpi_scan(&this->p, GCRYMPI_FMT_USG,
- params->prime, params->prime_len, NULL);
+ params->prime.ptr, params->prime.len, NULL);
if (err)
{
DBG1(DBG_LIB, "importing mpi modulus failed: %s", gpg_strerror(err));
free(this);
return NULL;
}
+ err = gcry_mpi_scan(&this->g, GCRYMPI_FMT_USG,
+ params->generator.ptr, params->generator.len, NULL);
+ if (err)
+ {
+ DBG1(DBG_LIB, "importing mpi generator failed: %s", gpg_strerror(err));
+ gcry_mpi_release(this->p);
+ free(this);
+ return NULL;
+ }
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
if (rng)
@@ -225,6 +234,7 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
{
DBG1(DBG_LIB, "importing mpi xa failed: %s", gpg_strerror(err));
gcry_mpi_release(this->p);
+ gcry_mpi_release(this->g);
free(this);
return NULL;
}
@@ -240,7 +250,6 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
gcry_mpi_clear_bit(this->xa, params->exp_len * 8 - 1);
}
- this->g = gcry_mpi_set_ui(NULL, params->generator);
this->ya = gcry_mpi_new(this->p_len * 8);
this->yb = NULL;
this->zz = NULL;
diff --git a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
index 056bdaac5..7b12cf7ba 100644
--- a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
+++ b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
@@ -194,11 +194,19 @@ static void destroy(private_gmp_diffie_hellman_t *this)
*/
gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
{
- private_gmp_diffie_hellman_t *this = malloc_thing(private_gmp_diffie_hellman_t);
+ private_gmp_diffie_hellman_t *this;
diffie_hellman_params_t *params;
rng_t *rng;
chunk_t random;
+ params = diffie_hellman_get_params(group);
+ if (!params)
+ {
+ return NULL;
+ }
+
+ this = malloc_thing(private_gmp_diffie_hellman_t);
+
/* public functions */
this->public.dh.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_shared_secret;
this->public.dh.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
@@ -216,16 +224,9 @@ gmp_diffie_hellman_t *gmp_diffie_hellman_create(diffie_hellman_group_t group)
mpz_init(this->g);
this->computed = FALSE;
-
- params = diffie_hellman_get_params(this->group);
- if (!params)
- {
- destroy(this);
- return NULL;
- }
- mpz_import(this->p, params->prime_len, 1, 1, 1, 0, params->prime);
- this->p_len = params->prime_len;
- mpz_set_ui(this->g, params->generator);
+ this->p_len = params->prime.len;
+ mpz_import(this->p, params->prime.len, 1, 1, 1, 0, params->prime.ptr);
+ mpz_import(this->g, params->generator.len, 1, 1, 1, 0, params->generator.ptr);
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
if (!rng)
diff --git a/src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c b/src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c
index 1520d5783..9a032c54f 100644
--- a/src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c
+++ b/src/libstrongswan/plugins/openssl/openssl_diffie_hellman.c
@@ -128,10 +128,9 @@ static status_t set_modulus(private_openssl_diffie_hellman_t *this)
{
return NOT_FOUND;
}
- this->dh->p = BN_bin2bn(params->prime, params->prime_len, NULL);
- this->dh->g = BN_new();
- BN_set_word(this->dh->g, params->generator);
- if (params->exp_len != params->prime_len)
+ this->dh->p = BN_bin2bn(params->prime.ptr, params->prime.len, NULL);
+ this->dh->g = BN_bin2bn(params->generator.ptr, params->generator.len, NULL);
+ if (params->exp_len != params->prime.len)
{
this->dh->length = params->exp_len * 8;
}