]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
* examples/rsa-keygen.c (main): Use xalloc for allocation.
authorNiels Möller <nisse@lysator.liu.se>
Sat, 7 Feb 2004 12:32:40 +0000 (13:32 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 7 Feb 2004 12:32:40 +0000 (13:32 +0100)
* 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

examples/rsa-decrypt.c
examples/rsa-encrypt.c
examples/rsa-keygen.c

index 8dfd38f9594b1649fc979befebc1e274f3f46b12..52b8b4c7b5b51fbadccb339cc89d1a10cacd3ad9 100644 (file)
@@ -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;
index 919a756336d7a585314e15677d18b7f9cbdc13b8..cb0e82095349f5d8c333e685285632e0d92adb6e 100644 (file)
@@ -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
index c5022cf39d89b1b416ffcefaa0050b97c71f30c8..675f13f4b5d1b4294deb40e7124076f93f82b565 100644 (file)
@@ -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);