Commit e99a1c24 authored by Niels Möller's avatar Niels Möller

* examples/rsa-keygen.c (main): Use xalloc for allocation.

* examples/rsa-encrypt.c (write_bignum): Likewise.
* examples/rsa-decrypt.c (read_bignum): Likewise.

Rev: src/nettle/examples/rsa-decrypt.c:1.4
Rev: src/nettle/examples/rsa-encrypt.c:1.5
Rev: src/nettle/examples/rsa-keygen.c:1.12
parent 05968af0
......@@ -86,11 +86,16 @@ read_bignum(FILE *f, mpz_t x)
if (read_uint32(f, &size)
&& size < 1000)
{
uint8_t *p = alloca(size);
uint8_t *p = xalloc(size);
if (fread(p, 1, size, f) != size)
return 0;
{
free(p);
return 0;
}
nettle_mpz_set_str_256_u(x, size, p);
free(p);
return 1;
}
return 0;
......
......@@ -78,14 +78,17 @@ write_bignum(FILE *f, mpz_t x)
{
unsigned size = nettle_mpz_sizeinbase_256_u(x);
uint8_t *p;
int res;
if (!write_uint32(f, size))
return 0;
p = alloca(size);
p = xalloc(size);
nettle_mpz_get_str_256(size, p, x);
return write_string(f, size, p);
res = write_string(f, size, p);
free(p);
return res;
}
static int
......
......@@ -96,15 +96,8 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
pub_name = malloc(strlen(priv_name) + 5);
if (pub_name)
sprintf(pub_name, "%s.pub", priv_name);
else
{
werror("Memory exhausted.\n");
return EXIT_FAILURE;
}
pub_name = xalloc(strlen(priv_name) + 5);
sprintf(pub_name, "%s.pub", priv_name);
/* NOTE: No sources */
yarrow256_init(&yarrow, 0, NULL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment