diff options
author | Tobias Brunner <tobias@strongswan.org> | 2008-06-10 09:19:18 +0000 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2008-06-10 09:19:18 +0000 |
commit | a57e0580f6fdf460c1c59a42480a53a9e8647364 (patch) | |
tree | 8895568ec322135a059bbb42b52d6616e06e22c8 /src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c | |
parent | ea0823dffdc7f8ceff27038fc9a98ae833b6d683 (diff) | |
download | strongswan-a57e0580f6fdf460c1c59a42480a53a9e8647364.tar.bz2 strongswan-a57e0580f6fdf460c1c59a42480a53a9e8647364.tar.xz |
refactoring
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c b/src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c index 1b99de7ac..3668a178a 100644 --- a/src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c +++ b/src/libstrongswan/plugins/openssl/openssl_ec_diffie_hellman.c @@ -19,11 +19,10 @@ #include <openssl/objects.h> #include "openssl_ec_diffie_hellman.h" +#include "openssl_util.h" #include <debug.h> -#define COORD_LEN(group) ((EC_GROUP_get_degree(group) + 7) / 8) - typedef struct private_openssl_ec_diffie_hellman_t private_openssl_ec_diffie_hellman_t; /** @@ -74,7 +73,6 @@ static bool chunk2ecp(const EC_GROUP *group, chunk_t chunk, EC_POINT *point) { BN_CTX *ctx; BIGNUM *x, *y; - int coord_len; bool ret = FALSE; ctx = BN_CTX_new(); @@ -91,14 +89,7 @@ static bool chunk2ecp(const EC_GROUP *group, chunk_t chunk, EC_POINT *point) goto error; } - coord_len = COORD_LEN(group); - if (chunk.len != coord_len * 2) - { - goto error; - } - - if (!BN_bin2bn(chunk.ptr, coord_len, x) || - !BN_bin2bn(chunk.ptr + coord_len, coord_len, y)) + if (!openssl_bn_split(chunk, x, y)) { goto error; } @@ -123,7 +114,6 @@ static bool ecp2chunk(const EC_GROUP *group, const EC_POINT *point, chunk_t *chu { BN_CTX *ctx; BIGNUM *x, *y; - int coord_len, offset; bool ret = FALSE; ctx = BN_CTX_new(); @@ -145,22 +135,8 @@ static bool ecp2chunk(const EC_GROUP *group, const EC_POINT *point, chunk_t *chu goto error; } - coord_len = COORD_LEN(group); - chunk->len = coord_len * 2; - chunk->ptr = malloc(chunk->len); - memset(chunk->ptr, 0, chunk->len); - - offset = coord_len - BN_num_bytes(x); - if (!BN_bn2bin(x, chunk->ptr + offset)) - { - chunk_free(chunk); - goto error; - } - - offset = coord_len - BN_num_bytes(y); - if (!BN_bn2bin(y, chunk->ptr + coord_len + offset)) + if (!openssl_bn_cat(EC_FIELD_ELEMENT_LEN(group), x, y, chunk)) { - chunk_free(chunk); goto error; } |