Mailing List Archive

gcry_check_version()
Hello,
Some questions:
Does the gcry_check_version() has to be called before or after
initialization? Are the gcry_set_allocation_handler() and
the gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL,0);
still required to be called?

--
Nikos Mavroyanopoulos
Re: gcry_check_version() [ In reply to ]
On Wed, 13 Aug 2003 11:20:11 +0300, Nikos Mavroyanopoulos said:

> Hello,
> Some questions:
> Does the gcry_check_version() has to be called before or after
> initialization? Are the gcry_set_allocation_handler() and
> the gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL,0);
> still required to be called?

For proper initialization of the library, you must call
gcry_check_version() *before calling any other functions* except for a
these gcry_control operations:
GCRYCTL_SUSPEND_SECMEM_WARN
GCRYCTL_DISABLE_INTERNAL_LOCKING
GCRYCTL_ANY_INITIALIZATION_P
GCRYCTL_INITIALIZATION_FINISHED_P

Better do a GCRYCTL_INITIALIZATION_FINISHED after gcry_check_version
and possible other stuff you want to do like
gcry_set_allocation_handler (). It is not really necessary but it
won't harm and might help in the future.

Becuase you can't know in a library whether another library has
already initialized the library, I suggest to do this:

if (!gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
{ /* No other library has already initialized libgcrypt. */

if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
{
log_fatal (_("libgcrypt is too old (need %s, have %s)\n"),
NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL));
}
gcry_set_allocation_handler (...);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
}

If you need to initialize other libraries, do it after or before that
code block, but never ever in between.



Salam-Shalom,

Werner

--
Werner Koch <wk@gnupg.org>
The GnuPG Experts http://g10code.com
Free Software Foundation Europe http://fsfeurope.org