GnuTLS cant call hashing functions

198 Views Asked by At

after compiling and testing some functions available in the gnuTLS library I am having problems using the crypto library. When I try to generate a hash using

gnutls_hash_hd_t *dig;
gnutls_hash_init (dig, GNUTLS_DIG_SHA1);

for then calculate a hash using

 gnutls_hash (dig, const void * ptext, size_t ptext_len);

my problen appears when

gnutls_hash_init (dig, GNUTLS_DIG_SHA1);

calls gnutls_malloc() inside crypto-api.c givng me a segfault. I dont know what and doing wrong and gnuTLS API is not very begginer friendly, any kind of suggestions and advices are welcome

1

There are 1 best solutions below

0
On

The function gnutls_hash_init does not allocate the memory for the gnutls_hash_hd_t. Rather, it expects a pointer to an existing allocation.

So the correct usage would be e.g.

  gnutls_hash_hd_t dig = {0}; // zero-initialize
  gnutls_hash_init(&dig, GNUTLS_DIG_SHA1);