summaryrefslogtreecommitdiff
path: root/random
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-12-12 15:13:09 +0100
committerWerner Koch <wk@gnupg.org>2013-12-12 15:28:06 +0100
commit3b30e9840d4b351c4de73b126e561154cb7df4cc (patch)
treeef3d2d1127165ef5866840d33ccde9d35a2dee33 /random
parentcd548ba2dc777b8b27d8d33182ba733c20222120 (diff)
downloadlibgcrypt-3b30e9840d4b351c4de73b126e561154cb7df4cc.tar.gz
Remove macro hacks for internal vs. external functions. Part 2 and last.
* src/visibility.h: Remove remaining define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by replacing them by the x-macros. * src/g10lib.h: Add internal prototypes. (xtrymalloc, xtrycalloc, xtrymalloc_secure, xtrycalloc_secure) (xtryrealloc, xtrystrdup, xmalloc, xcalloc, xmalloc_secure) (xcalloc_secure, xrealloc, xstrdup, xfree): New macros. -- The use of xmalloc/xtrymalloc/xfree is a more common pattern than the gcry_free etc. functions. Those functions behave like those defined by C and thus for better readability we use these macros and not the underscore prefixed functions. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'random')
-rw-r--r--random/random-csprng.c14
-rw-r--r--random/random-fips.c28
-rw-r--r--random/random.c4
-rw-r--r--random/rndegd.c6
-rw-r--r--random/rndw32.c4
5 files changed, 28 insertions, 28 deletions
diff --git a/random/random-csprng.c b/random/random-csprng.c
index b6d7f667..87235d82 100644
--- a/random/random-csprng.c
+++ b/random/random-csprng.c
@@ -322,11 +322,11 @@ initialize(void)
use this extra space (which is allocated in secure memory) as
a temporary hash buffer */
rndpool = (secure_alloc
- ? gcry_xcalloc_secure (1, POOLSIZE + BLOCKLEN)
- : gcry_xcalloc (1, POOLSIZE + BLOCKLEN));
+ ? xcalloc_secure (1, POOLSIZE + BLOCKLEN)
+ : xcalloc (1, POOLSIZE + BLOCKLEN));
keypool = (secure_alloc
- ? gcry_xcalloc_secure (1, POOLSIZE + BLOCKLEN)
- : gcry_xcalloc (1, POOLSIZE + BLOCKLEN));
+ ? xcalloc_secure (1, POOLSIZE + BLOCKLEN)
+ : xcalloc (1, POOLSIZE + BLOCKLEN));
/* Setup the slow entropy gathering function. The code requires
that this function exists. */
@@ -676,7 +676,7 @@ _gcry_rngcsprng_set_seed_file (const char *name)
{
if (seed_file_name)
BUG ();
- seed_file_name = gcry_xstrdup (name);
+ seed_file_name = xstrdup (name);
}
@@ -1312,7 +1312,7 @@ gather_faked (void (*add)(const void*, size_t, enum random_origins),
#endif
}
- p = buffer = gcry_xmalloc( length );
+ p = buffer = xmalloc( length );
n = length;
#ifdef HAVE_RAND
while ( n-- )
@@ -1322,6 +1322,6 @@ gather_faked (void (*add)(const void*, size_t, enum random_origins),
*p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
#endif
add_randomness ( buffer, length, origin );
- gcry_free (buffer);
+ xfree (buffer);
return 0; /* okay */
}
diff --git a/random/random-fips.c b/random/random-fips.c
index 6ee52f10..d00825e2 100644
--- a/random/random-fips.c
+++ b/random/random-fips.c
@@ -555,7 +555,7 @@ get_entropy (size_t nbytes)
int rc;
gcry_assert (!entropy_collect_buffer);
- entropy_collect_buffer = gcry_xmalloc_secure (nbytes);
+ entropy_collect_buffer = xmalloc_secure (nbytes);
entropy_collect_buffer_size = nbytes;
entropy_collect_buffer_len = 0;
@@ -577,7 +577,7 @@ get_entropy (size_t nbytes)
if (rc < 0 || entropy_collect_buffer_len != entropy_collect_buffer_size)
{
- gcry_free (entropy_collect_buffer);
+ xfree (entropy_collect_buffer);
entropy_collect_buffer = NULL;
log_fatal ("error getting entropy data\n");
}
@@ -613,7 +613,7 @@ x931_generate_key (int for_nonce)
/* Get a key from the standard RNG or from the entropy source. */
if (for_nonce)
{
- buffer = gcry_xmalloc (X931_AES_KEYLEN);
+ buffer = xmalloc (X931_AES_KEYLEN);
get_random (buffer, X931_AES_KEYLEN, std_rng_context);
}
else
@@ -625,7 +625,7 @@ x931_generate_key (int for_nonce)
the cipher context. */
rc = _gcry_cipher_setkey (hd, buffer, X931_AES_KEYLEN);
wipememory (buffer, X931_AES_KEYLEN);
- gcry_free (buffer);
+ xfree (buffer);
if (rc)
{
log_error ("error creating key for RNG: %s\n", _gcry_strerror (rc));
@@ -651,7 +651,7 @@ x931_generate_seed (unsigned char *seed_buffer, size_t length)
memcpy (seed_buffer, buffer, X931_AES_KEYLEN);
wipememory (buffer, X931_AES_KEYLEN);
- gcry_free (buffer);
+ xfree (buffer);
}
@@ -753,17 +753,17 @@ _gcry_rngfips_initialize (int full)
if (!tempvalue_for_x931_aes_driver)
{
tempvalue_for_x931_aes_driver
- = gcry_xmalloc_secure (TEMPVALUE_FOR_X931_AES_DRIVER_SIZE);
+ = xmalloc_secure (TEMPVALUE_FOR_X931_AES_DRIVER_SIZE);
/* Allocate the random contexts. Note that we do not need to use
secure memory for the nonce context. */
- nonce_context = gcry_xcalloc (1, sizeof *nonce_context);
+ nonce_context = xcalloc (1, sizeof *nonce_context);
setup_guards (nonce_context);
- std_rng_context = gcry_xcalloc_secure (1, sizeof *std_rng_context);
+ std_rng_context = xcalloc_secure (1, sizeof *std_rng_context);
setup_guards (std_rng_context);
- strong_rng_context = gcry_xcalloc_secure (1, sizeof *strong_rng_context);
+ strong_rng_context = xcalloc_secure (1, sizeof *strong_rng_context);
setup_guards (strong_rng_context);
}
else
@@ -916,7 +916,7 @@ selftest_kat (selftest_report_func_t report)
gcry_assert (tempvalue_for_x931_aes_driver);
- test_ctx = gcry_xcalloc (1, sizeof *test_ctx);
+ test_ctx = xcalloc (1, sizeof *test_ctx);
setup_guards (test_ctx);
lock_rng ();
@@ -992,7 +992,7 @@ selftest_kat (selftest_report_func_t report)
unlock_rng ();
_gcry_cipher_close (test_ctx->cipher_hd);
check_guards (test_ctx);
- gcry_free (test_ctx);
+ xfree (test_ctx);
if (report && errtxt)
report ("random", 0, "KAT", errtxt);
return errtxt? GPG_ERR_SELFTEST_FAILED : 0;
@@ -1046,7 +1046,7 @@ _gcry_rngfips_init_external_test (void **r_context, unsigned int flags,
|| !dt || dtlen != 16 )
return GPG_ERR_INV_ARG;
- test_ctx = gcry_calloc (1, sizeof *test_ctx + dtlen);
+ test_ctx = xtrycalloc (1, sizeof *test_ctx + dtlen);
if (!test_ctx)
return gpg_err_code_from_syserror ();
setup_guards (test_ctx);
@@ -1090,7 +1090,7 @@ _gcry_rngfips_init_external_test (void **r_context, unsigned int flags,
if (rc)
{
_gcry_cipher_close (test_ctx->cipher_hd);
- gcry_free (test_ctx);
+ xfree (test_ctx);
*r_context = NULL;
}
else
@@ -1124,6 +1124,6 @@ _gcry_rngfips_deinit_external_test (void *context)
if (test_ctx)
{
_gcry_cipher_close (test_ctx->cipher_hd);
- gcry_free (test_ctx);
+ xfree (test_ctx);
}
}
diff --git a/random/random.c b/random/random.c
index 97018c42..ff9d6d25 100644
--- a/random/random.c
+++ b/random/random.c
@@ -320,7 +320,7 @@ _gcry_random_bytes (size_t nbytes, enum gcry_random_level level)
{
void *buffer;
- buffer = gcry_xmalloc (nbytes);
+ buffer = xmalloc (nbytes);
do_randomize (buffer, nbytes, level);
return buffer;
}
@@ -337,7 +337,7 @@ _gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
/* Historical note (1.3.0--1.4.1): The buffer was only allocated
in secure memory if the pool in random-csprng.c was also set to
use secure memory. */
- buffer = gcry_xmalloc_secure (nbytes);
+ buffer = xmalloc_secure (nbytes);
do_randomize (buffer, nbytes, level);
return buffer;
}
diff --git a/random/rndegd.c b/random/rndegd.c
index 464edf3d..d43fcbc1 100644
--- a/random/rndegd.c
+++ b/random/rndegd.c
@@ -129,10 +129,10 @@ _gcry_rndegd_set_socket_name (const char *name)
newname = my_make_filename (name, NULL);
if (strlen (newname)+1 >= sizeof addr.sun_path)
{
- gcry_free (newname);
+ xfree (newname);
return gpg_error_from_syserror ();
}
- gcry_free (user_socket_name);
+ xfree (user_socket_name);
user_socket_name = newname;
return 0;
}
@@ -195,7 +195,7 @@ _gcry_rndegd_connect_socket (int nofail)
close (fd);
fd = -1;
}
- gcry_free(name);
+ xfree (name);
if (fd != -1)
egd_socket = fd;
return fd;
diff --git a/random/rndw32.c b/random/rndw32.c
index 5c5d6c68..03dffaf8 100644
--- a/random/rndw32.c
+++ b/random/rndw32.c
@@ -469,7 +469,7 @@ registry_poll (void (*add)(const void*, size_t, enum random_origins),
break;
}
}
- gcry_free (pPerfData);
+ xfree (pPerfData);
}
/* Although this isn't documented in the Win32 API docs, it's necessary
@@ -759,7 +759,7 @@ slow_gatherer ( void (*add)(const void*, size_t, enum random_origins),
}
gcry_assert (i < 100);
}
- gcry_free (buffer);
+ xfree (buffer);
/* We couldn't get enough results from the kernel, fall back to the
somewhat troublesome registry poll. */