diff options
author | Martin Willi <martin@revosec.ch> | 2010-04-08 15:08:35 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2010-04-08 15:08:35 +0200 |
commit | b34b93dbf7e799d24bb381b3e15ef0d98f4adebb (patch) | |
tree | c7beafa14ae750f4865784969c76afa4a8acd19a /src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c | |
parent | 6c1dc87551e10fe9f497a32314d3dd663eb2105e (diff) | |
download | strongswan-b34b93dbf7e799d24bb381b3e15ef0d98f4adebb.tar.bz2 strongswan-b34b93dbf7e799d24bb381b3e15ef0d98f4adebb.tar.xz |
Store DH generator in a chunk, hide non-public data in a private struct
Diffstat (limited to 'src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c')
-rw-r--r-- | src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c | 23 |
1 files changed, 12 insertions, 11 deletions
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) |