aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
index 5eb28cb20..b4ea540de 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
@@ -374,9 +374,13 @@ static bool belongs_to(private_gmp_rsa_private_key_t *this, public_key_t *public
chunk_t gmp_mpz_to_asn1(const mpz_t value)
{
chunk_t n;
-
- n.ptr = mpz_export(NULL, &n.len, 1, 1, 1, 0, value);
-
+
+ n.len = 1 + mpz_sizeinbase(value, 2) / 8; /* size in bytes */
+ n.ptr = mpz_export(NULL, NULL, 1, n.len, 1, 0, value);
+ if (n.ptr == NULL)
+ { /* if we have zero in "value", gmp returns NULL */
+ n.len = 0;
+ }
return asn1_wrap(ASN1_INTEGER, "m", n);
}