Error with gcry_mpi_release with opaque value.

Werner Koch wk at
Thu Jun 28 09:08:55 CEST 2018


On Sun, 24 Jun 2018 10:53, stefbon at said:

> buffer=malloc(len);
> if (buffer) {
>  memcpy(buffer, from somewhere, size);


>  mp->lib.mpi=gcry_mpi_set_opaque(NULL, (void *) buffer, (8 * len));
> }
> And releasing this with gcry_mpi_release program crashes.

Either you free BUFFER which you may not do because gcry_mpi_set_opaque
takes ownership of BUFFER or, more likely, you have not setup memory
allocation functions which map to standard malloc.  Libgcrypt uses its
own allocation functions and uses gcry_free to release them.  The
rationale for the own allocation fucntions is that they allow to
distinguish between standard and secure memory.

Either use

  buffer = gcry_malloc (len);


  mp->lib.mpi = gcry_mpi_set_opaque_copy (NULL, from_somewhere, 8*len);



#  Please read:  Daniel Ellsberg - The Doomsday Machine  #
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <>

More information about the Gcrypt-devel mailing list