/* Release all resources associated with the cipher handle H. H may be NULL in which case this is a no-operation. */ void gcry_cipher_close (gcry_cipher_hd_t h) { if (! h) return; if ((h->magic != CTX_MAGIC_SECURE) && (h->magic != CTX_MAGIC_NORMAL)) _gcry_fatal_error(GPG_ERR_INTERNAL, "gcry_cipher_close: already closed/invalid handle"); else h->magic = 0; /* Release module. */ ath_mutex_lock (&ciphers_registered_lock); _gcry_module_release (h->module); ath_mutex_unlock (&ciphers_registered_lock); /* We always want to wipe out the memory even when the context has been allocated in secure memory. The user might have disabled secure memory or is using his own implementation which does not do the wiping. To accomplish this we need to keep track of the actual size of this structure because we have no way to known how large the allocated area was when using a standard malloc. */ wipememory (h, h->actual_handle_size); gcry_free (h); }
/* Release all resources associated with the cipher handle H. H may be NULL in which case this is a no-operation. */ void _gcry_cipher_close (gcry_cipher_hd_t h) { size_t off; if (!h) return; if ((h->magic != CTX_MAGIC_SECURE) && (h->magic != CTX_MAGIC_NORMAL)) _gcry_fatal_error(GPG_ERR_INTERNAL, "gcry_cipher_close: already closed/invalid handle"); else h->magic = 0; /* We always want to wipe out the memory even when the context has been allocated in secure memory. The user might have disabled secure memory or is using his own implementation which does not do the wiping. To accomplish this we need to keep track of the actual size of this structure because we have no way to known how large the allocated area was when using a standard malloc. */ off = h->handle_offset; wipememory (h, h->actual_handle_size); xfree ((char*)h - off); }
void * gcry_xmalloc( size_t n ) { void *p; while ( !(p = gcry_malloc( n )) ) { if( !outofcore_handler || !outofcore_handler( outofcore_handler_value, n, 0 ) ) { _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL ); } } return p; }
void * gcry_xmalloc_secure( size_t n ) { void *p; while ( !(p = gcry_malloc_secure( n )) ) { if( !outofcore_handler || !outofcore_handler( outofcore_handler_value, n, 1 ) ) { _gcry_fatal_error(gpg_err_code_from_errno (errno), _("out of core in secure memory")); } } return p; }
void * gcry_xrealloc( void *a, size_t n ) { void *p; while ( !(p = gcry_realloc( a, n )) ) { if( !outofcore_handler || !outofcore_handler( outofcore_handler_value, n, gcry_is_secure(a)? 3:2 ) ) { _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL ); } } return p; }
void * gcry_xcalloc_secure( size_t n, size_t m ) { size_t nbytes; void *p; nbytes = n * m; if (m && nbytes / m != n) { errno = ENOMEM; _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL ); } p = gcry_xmalloc_secure ( nbytes ); memset ( p, 0, nbytes ); return p; }
char * gcry_xstrdup (const char *string) { char *p; while ( !(p = gcry_strdup (string)) ) { size_t n = strlen (string); int is_sec = !!gcry_is_secure (string); if (!outofcore_handler || !outofcore_handler (outofcore_handler_value, n, is_sec) ) { _gcry_fatal_error (gpg_err_code_from_errno (errno), is_sec? _("out of core in secure memory"):NULL); } } return p; }