aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crypto_ecc.c35
-rw-r--r--src/util/strings.c2
2 files changed, 35 insertions, 2 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 019dbe94e..ef52d9588 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -388,6 +388,39 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (
388 388
389 389
390/** 390/**
391 * Convert a string representing a private key to a private key.
392 *
393 * @param enc encoded private key
394 * @param enclen number of bytes in @a enc (without 0-terminator)
395 * @param priv where to store the private key
396 * @return #GNUNET_OK on success
397 */
398int
399GNUNET_CRYPTO_ecdsa_private_key_from_string (
400 const char *enc,
401 size_t enclen,
402 struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
403{
404 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
405
406 if (keylen % 5 > 0)
407 keylen += 5 - keylen % 5;
408 keylen /= 5;
409 if (enclen != keylen)
410 return GNUNET_SYSERR;
411
412 if (GNUNET_OK !=
413 GNUNET_STRINGS_string_to_data (enc,
414 enclen,
415 priv,
416 sizeof(
417 struct GNUNET_CRYPTO_EcdsaPrivateKey)))
418 return GNUNET_SYSERR;
419 return GNUNET_OK;
420}
421
422
423/**
391 * Convert a string representing a public key to a public key. 424 * Convert a string representing a public key to a public key.
392 * 425 *
393 * @param enc encoded public key 426 * @param enc encoded public key
@@ -423,7 +456,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (
423/** 456/**
424 * Convert a string representing a private key to a private key. 457 * Convert a string representing a private key to a private key.
425 * 458 *
426 * @param enc encoded public key 459 * @param enc encoded private key
427 * @param enclen number of bytes in @a enc (without 0-terminator) 460 * @param enclen number of bytes in @a enc (without 0-terminator)
428 * @param priv where to store the private key 461 * @param priv where to store the private key
429 * @return #GNUNET_OK on success 462 * @return #GNUNET_OK on success
diff --git a/src/util/strings.c b/src/util/strings.c
index 9d6f4039e..014302c01 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -2148,7 +2148,7 @@ GNUNET_STRINGS_urlencode (const char *data, size_t len, char **out)
2148 struct GNUNET_Buffer buf = { 0 }; 2148 struct GNUNET_Buffer buf = { 0 };
2149 const uint8_t *i8 = (uint8_t *) data; 2149 const uint8_t *i8 = (uint8_t *) data;
2150 2150
2151 while (0 != *i8) 2151 while ((i8 - (uint8_t *) data) < len && 0 != *i8)
2152 { 2152 {
2153 if (0 == (0x80 & *i8)) 2153 if (0 == (0x80 & *i8))
2154 { 2154 {