summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/gmp
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
commit8b80ab5a6950ce6515f477624794defd7531642a (patch)
treeaa8303f3806c5615fbeafc4dc82febe3cd7c24dc /src/libstrongswan/plugins/gmp
parentdb67c87db3c9089ea8d2e14f617bf3d9e2af261f (diff)
downloadvyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.tar.gz
vyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.8)
Diffstat (limited to 'src/libstrongswan/plugins/gmp')
-rw-r--r--src/libstrongswan/plugins/gmp/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c26
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_plugin.c12
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c55
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c47
5 files changed, 85 insertions, 57 deletions
diff --git a/src/libstrongswan/plugins/gmp/Makefile.in b/src/libstrongswan/plugins/gmp/Makefile.in
index 1d9bfb88e..56642b7c9 100644
--- a/src/libstrongswan/plugins/gmp/Makefile.in
+++ b/src/libstrongswan/plugins/gmp/Makefile.in
@@ -188,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
index 3d9856b63..40e83fc4c 100644
--- a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
+++ b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
@@ -15,7 +15,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_diffie_hellman.c 3806 2008-04-15 05:56:35Z martin $
+ * $Id: gmp_diffie_hellman.c 4346 2008-09-17 09:02:30Z martin $
*/
#include <gmp.h>
@@ -343,7 +343,7 @@ struct private_gmp_diffie_hellman_t {
* Generator value.
*/
mpz_t g;
-
+
/**
* My private value.
*/
@@ -353,7 +353,7 @@ struct private_gmp_diffie_hellman_t {
* My public value.
*/
mpz_t ya;
-
+
/**
* Other public value.
*/
@@ -373,7 +373,7 @@ struct private_gmp_diffie_hellman_t {
* Modulus length.
*/
size_t p_len;
-
+
/**
* True if shared secret is computed and stored in my_public_value.
*/
@@ -395,7 +395,7 @@ static void set_other_public_value(private_gmp_diffie_hellman_t *this, chunk_t v
/* check public value:
* 1. 0 or 1 is invalid as 0^a = 0 and 1^a = 1
* 2. a public value larger or equal the modulus is invalid */
- if (mpz_cmp_ui(this->yb, 1) > 0 ||
+ if (mpz_cmp_ui(this->yb, 1) > 0 &&
mpz_cmp(this->yb, p_min_1) < 0)
{
#ifdef EXTENDED_DH_TEST
@@ -440,7 +440,11 @@ static status_t get_other_public_value(private_gmp_diffie_hellman_t *this,
return FAILED;
}
value->len = this->p_len;
- value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb);
+ value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb);
+ if (value->ptr == NULL)
+ {
+ return FAILED;
+ }
return SUCCESS;
}
@@ -451,6 +455,10 @@ static void get_my_public_value(private_gmp_diffie_hellman_t *this,chunk_t *valu
{
value->len = this->p_len;
value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->ya);
+ if (value->ptr == NULL)
+ {
+ value->len = 0;
+ }
}
/**
@@ -463,7 +471,11 @@ static status_t get_shared_secret(private_gmp_diffie_hellman_t *this, chunk_t *s
return FAILED;
}
secret->len = this->p_len;
- secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz);
+ secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz);
+ if (secret->ptr == NULL)
+ {
+ return FAILED;
+ }
return SUCCESS;
}
diff --git a/src/libstrongswan/plugins/gmp/gmp_plugin.c b/src/libstrongswan/plugins/gmp/gmp_plugin.c
index 56fb0ddd8..7711b6d34 100644
--- a/src/libstrongswan/plugins/gmp/gmp_plugin.c
+++ b/src/libstrongswan/plugins/gmp/gmp_plugin.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_plugin.c 3962 2008-05-15 12:39:35Z tobias $
+ * $Id: gmp_plugin.c 4309 2008-08-28 11:07:57Z martin $
*/
#include "gmp_plugin.h"
@@ -58,14 +58,10 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
- lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
- (dh_constructor_t)gmp_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
- (dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
@@ -74,6 +70,10 @@ plugin_t *plugin_create()
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ (dh_constructor_t)gmp_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
+ (dh_constructor_t)gmp_diffie_hellman_create);
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
(builder_constructor_t)gmp_rsa_private_key_builder);
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
index cd951f0e4..e445dd670 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_rsa_private_key.c 4014 2008-05-23 19:23:04Z andreas $
+ * $Id: gmp_rsa_private_key.c 4345 2008-09-17 08:10:48Z martin $
*/
#include <gmp.h>
@@ -191,6 +191,10 @@ static chunk_t rsadp(private_gmp_rsa_private_key_t *this, chunk_t data)
decrypted.len = this->k;
decrypted.ptr = mpz_export(NULL, NULL, 1, decrypted.len, 1, 0, t1);
+ if (decrypted.ptr == NULL)
+ {
+ decrypted.len = 0;
+ }
mpz_clear_randomized(t1);
mpz_clear_randomized(t2);
@@ -789,34 +793,37 @@ static gmp_rsa_private_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
- }
- case BUILD_KEY_SIZE:
- {
- va_start(args, part);
- this->key = generate(va_arg(args, u_int));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ case BUILD_KEY_SIZE:
+ {
+ va_start(args, part);
+ this->key = generate(va_arg(args, u_int));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_gmp_rsa_private_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
index e4f898ecc..8a89849cd 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_rsa_public_key.c 3988 2008-05-21 13:01:58Z martin $
+ * $Id: gmp_rsa_public_key.c 4345 2008-09-17 08:10:48Z martin $
*/
#include <gmp.h>
@@ -93,11 +93,15 @@ static chunk_t rsaep(private_gmp_rsa_public_key_t *this, chunk_t data)
mpz_powm(c, m, this->e, this->n);
- encrypted.len = this->k;
- encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c);
+ encrypted.len = this->k;
+ encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c);
+ if (encrypted.ptr == NULL)
+ {
+ encrypted.len = 0;
+ }
mpz_clear(c);
- mpz_clear(m);
+ mpz_clear(m);
return encrypted;
}
@@ -541,27 +545,30 @@ static gmp_rsa_public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_gmp_rsa_public_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**