Ticket #4979: gnutls-3.3.1-gnutls_secure_malloc-1.patch

File gnutls-3.3.1-gnutls_secure_malloc-1.patch, 3.6 KB (added by Fernando de Oliveira, 11 years ago)
  • TabularUnified lib/gnutls_mem.c

    Submitted By: Fernando de Oliveira <famobr at yahoo dot com dot br>
    Date: 2014-04-20
    Initial Package Version: 3.3.1
    Upstream Status: Not submitted
    Origin: self
    Description: Fix error : 'gnutls_secure_malloc' undeclared
    
    old new  
    4343        return ret;
    4444}
    4545
     46svoid *gnutls_secure_calloc(size_t nmemb, size_t size)
     47{
     48        svoid *ret;
     49        size_t n = xtimes(nmemb, size);
     50        ret = (size_in_bounds_p(n) ? gnutls_secure_malloc(n) : NULL);
     51        if (ret != NULL)
     52                memset(ret, 0, size);
     53        return ret;
     54}
     55
    4656/* This realloc will free ptr in case realloc
    4757 * fails.
    4858 */
     
    7282        return ret;
    7383}
    7484
     85void _gnutls_bzero(void *mem, size_t size)
     86{
     87        /* The reason we use that function instead of directly
     88         * calling memset is to prevent the compiler
     89         * optimizing out certain calls that may look
     90         * pointless to him, but needed to erase
     91         * private keys. */
     92        memset(mem, 0, size);
     93}
     94
    7595#if 0
    7696/* don't use them. They are included for documentation.
    7797 */
  • TabularUnified lib/gnutls_mem.h

    old new  
    2323#ifndef GNUTLS_MEM_H
    2424#define GNUTLS_MEM_H
    2525
     26typedef void svoid;             /* for functions that allocate using gnutls_secure_malloc */
     27
     28extern int (*_gnutls_is_secure_memory) (const void *);
     29
    2630/* this realloc function will return ptr if size==0, and
    2731 * will free the ptr if the new allocation failed.
    2832 */
    2933void *gnutls_realloc_fast(void *ptr, size_t size);
    3034
     35svoid *gnutls_secure_calloc(size_t nmemb, size_t size);
     36
    3137void *_gnutls_calloc(size_t nmemb, size_t size);
    3238char *_gnutls_strdup(const char *);
    3339
     40void _gnutls_bzero(void *v, size_t n);
     41
    3442#define zrelease_mpi_key(mpi) if (*mpi!=NULL) { \
    3543                _gnutls_mpi_clear(*mpi); \
    3644                _gnutls_mpi_release(mpi); \
    3745        }
    3846
    39 void _gnutls_safe_memset(void *data, int c, size_t size);
    40 
    41 #define zeroize_key(x, size) _gnutls_safe_memset(x, 0, size)
     47#define zeroize_key(x, size) _gnutls_bzero(x, size)
    4248
    43 #define zeroize_temp_key zeroize_key
    44 #define zrelease_temp_mpi_key zrelease_mpi_key
     49#ifdef ENABLE_FIPS140
     50# define zeroize_temp_key zeroize_key
     51# define zrelease_temp_mpi_key zrelease_mpi_key
     52#else
     53# define zeroize_temp_key(x, size)
     54# define zrelease_temp_mpi_key(mpi) _gnutls_mpi_release(mpi)
     55#endif
    4556
    4657#endif                          /* GNUTLS_MEM_H */
  • TabularUnified lib/auth/rsa_psk.c

    old new  
    148145        gnutls_datum_t premaster_secret;
    149146        premaster_secret.size = GNUTLS_MASTER_SIZE;
    150147        premaster_secret.data =
    151             gnutls_malloc(premaster_secret.size);
     148            gnutls_secure_malloc(premaster_secret.size);
    152149
    153150        if (premaster_secret.data == NULL) {
    154151                gnutls_assert();
  • TabularUnified lib/includes/gnutls/gnutls.h.in

    old new  
    14651465
    14661466/* For use in callbacks */
    14671467extern gnutls_alloc_function gnutls_malloc;
     1468extern gnutls_alloc_function gnutls_secure_malloc;
    14681469extern gnutls_realloc_function gnutls_realloc;
    14691470extern gnutls_calloc_function gnutls_calloc;
    14701471extern gnutls_free_function gnutls_free;
  • TabularUnified lib/libgnutls.map

    old new  
    303303    gnutls_rsa_params_import_pkcs1;
    304304    gnutls_rsa_params_import_raw;
    305305    gnutls_rsa_params_init;
     306    gnutls_secure_calloc;
    306307    gnutls_secure_malloc;
    307308    gnutls_server_name_get;
    308309    gnutls_server_name_set;