diff options
author | Moritz Schulte <mo@g10code.com> | 2003-09-30 20:15:16 +0000 |
---|---|---|
committer | Moritz Schulte <mo@g10code.com> | 2003-09-30 20:15:16 +0000 |
commit | 9d2ef4d9d70326bc9b30d678cd55e5d5f70068bd (patch) | |
tree | 0bc1d84153c1c7137d840124351d7feda9e2b250 | |
parent | fdac246a45473f3726ceb7ffa99f71d681125da8 (diff) | |
download | libgcrypt-9d2ef4d9d70326bc9b30d678cd55e5d5f70068bd.tar.gz |
2003-09-29 Moritz Schulte <mo@g10code.com>
* libgcrypt-config.in: Fix --algorithms option.
2003-09-28 Moritz Schulte <mo@g10code.com>
* g10lib.h: Declare: _gcry_malloc.
(GCRY_ALLOC_FLAG_SECURE): New symbol.
* global.c (_gcry_malloc): New function...
(gcry_malloc): ... use it.
(gcry_malloc_secure): Likewise.
-rw-r--r-- | src/g10lib.h | 6 | ||||
-rw-r--r-- | src/global.c | 51 | ||||
-rw-r--r-- | src/libgcrypt-config.in | 6 |
3 files changed, 49 insertions, 14 deletions
diff --git a/src/g10lib.h b/src/g10lib.h index 91520c9d..3250c5b3 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -229,4 +229,10 @@ gcry_err_code_t _gcry_pk_init (void); gcry_err_code_t _gcry_pk_module_lookup (int id, gcry_module_t *module); void _gcry_pk_module_release (gcry_module_t module); +/* Memory management. */ + +gcry_err_code_t _gcry_malloc (size_t n, unsigned int flags, void **mem); + +#define GCRY_ALLOC_FLAG_SECURE (1 << 0) + #endif /* G10LIB_H */ diff --git a/src/global.c b/src/global.c index a4402b91..d7d94187 100644 --- a/src/global.c +++ b/src/global.c @@ -377,28 +377,57 @@ gcry_set_outofcore_handler( int (*f)( void*, size_t, unsigned int ), outofcore_handler_value = value; } +gcry_err_code_t +_gcry_malloc (size_t n, unsigned int flags, void **mem) +{ + gcry_err_code_t err = GPG_ERR_NO_ERROR; + void *m = NULL; + + if (flags & GCRY_ALLOC_FLAG_SECURE) + { + if (alloc_secure_func) + m = (*alloc_secure_func) (n); + else + m = _gcry_private_malloc_secure (n); + } + else + { + if (alloc_func) + m = (*alloc_func) (n); + else + m = _gcry_private_malloc (n); + } + if (! m) + err = gpg_err_code_from_errno (ENOMEM); + else + *mem = m; + return err; +} + void * -gcry_malloc( size_t n ) +gcry_malloc (size_t n) { - if( alloc_func ) - return alloc_func( n ) ; - return _gcry_private_malloc( n ); + void *mem = NULL; + + _gcry_malloc (n, 0, &mem); + + return mem; } void * -gcry_malloc_secure( size_t n ) +gcry_malloc_secure (size_t n) { - if (no_secure_memory) - return gcry_malloc (n); - if (alloc_secure_func) - return alloc_secure_func (n) ; - return _gcry_private_malloc_secure (n); + void *mem = NULL; + + _gcry_malloc (n, GCRY_ALLOC_FLAG_SECURE, &mem); + + return mem; } int -gcry_is_secure( const void *a ) +gcry_is_secure (const void *a) { if (no_secure_memory) return 0; diff --git a/src/libgcrypt-config.in b/src/libgcrypt-config.in index 07713a6e..c11ff874 100644 --- a/src/libgcrypt-config.in +++ b/src/libgcrypt-config.in @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 1999, 2002 Free Software Foundation, Inc. +# Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without @@ -188,7 +188,7 @@ if test "$echo_version" = "yes"; then fi if test "$echo_algorithms" = "yes"; then - echo "Symmetric cipher algorithms: $ciphers" - echo "Public-key cipher algorithms: $pubkey_ciphers" + echo "Symmetric cipher algorithms: $symmetric_ciphers" + echo "Public-key cipher algorithms: $asymmetric_ciphers" echo "Message digest algorithms: $digests" fi |