diff options
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r-- | src/util/crypto_rsa.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 4d3de00bc..f017d1f10 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -310,9 +310,15 @@ GNUNET_CRYPTO_rsa_public_key_encode ( | |||
310 | struct GNUNET_CRYPTO_RsaPublicKeyHeaderP hdr; | 310 | struct GNUNET_CRYPTO_RsaPublicKeyHeaderP hdr; |
311 | int ret; | 311 | int ret; |
312 | 312 | ||
313 | ret = key_from_sexp (ne, key->sexp, "public-key", "ne"); | 313 | ret = key_from_sexp (ne, |
314 | key->sexp, | ||
315 | "public-key", | ||
316 | "ne"); | ||
314 | if (0 != ret) | 317 | if (0 != ret) |
315 | ret = key_from_sexp (ne, key->sexp, "rsa", "ne"); | 318 | ret = key_from_sexp (ne, |
319 | key->sexp, | ||
320 | "rsa", | ||
321 | "ne"); | ||
316 | if (0 != ret) | 322 | if (0 != ret) |
317 | { | 323 | { |
318 | GNUNET_break (0); | 324 | GNUNET_break (0); |
@@ -333,16 +339,25 @@ GNUNET_CRYPTO_rsa_public_key_encode ( | |||
333 | (n_size > UINT16_MAX) ) | 339 | (n_size > UINT16_MAX) ) |
334 | { | 340 | { |
335 | GNUNET_break (0); | 341 | GNUNET_break (0); |
336 | *buffer = NULL; | 342 | if (NULL != buffer) |
343 | *buffer = NULL; | ||
337 | gcry_mpi_release (ne[0]); | 344 | gcry_mpi_release (ne[0]); |
338 | gcry_mpi_release (ne[1]); | 345 | gcry_mpi_release (ne[1]); |
339 | return 0; | 346 | return 0; |
340 | } | 347 | } |
341 | buf_size = n_size + e_size + sizeof (hdr); | 348 | buf_size = n_size + e_size + sizeof (hdr); |
349 | if (NULL == buffer) | ||
350 | { | ||
351 | gcry_mpi_release (ne[0]); | ||
352 | gcry_mpi_release (ne[1]); | ||
353 | return buf_size; | ||
354 | } | ||
342 | buf = GNUNET_malloc (buf_size); | 355 | buf = GNUNET_malloc (buf_size); |
343 | hdr.modulus_length = htons ((uint16_t) n_size); | 356 | hdr.modulus_length = htons ((uint16_t) n_size); |
344 | hdr.public_exponent_length = htons ((uint16_t) e_size); | 357 | hdr.public_exponent_length = htons ((uint16_t) e_size); |
345 | memcpy (buf, &hdr, sizeof (hdr)); | 358 | memcpy (buf, |
359 | &hdr, | ||
360 | sizeof (hdr)); | ||
346 | GNUNET_assert (0 == | 361 | GNUNET_assert (0 == |
347 | gcry_mpi_print (GCRYMPI_FMT_USG, | 362 | gcry_mpi_print (GCRYMPI_FMT_USG, |
348 | (unsigned char *) &buf[sizeof (hdr)], | 363 | (unsigned char *) &buf[sizeof (hdr)], |