gcry_cipher_algo_name before gcry_cipher_open makes gcry_cipher_open fail

Andreas Mattheiss andreas.mattheiss at gmx.de
Wed Sep 8 16:05:24 CEST 2021


I've stumbled accross somethig I don't understand (libgcrypt 1.9.4): the following code

#include <gcrypt.h>
#include <stdio.h>

void main() {

gcry_cipher_hd_t handle;

printf("Error from opening cipher: %i \n",gcry_cipher_open (&handle, algo, mode, 0));
printf("Selected cipher: %s \n",gcry_cipher_algo_name (algo));

produces the expected result:

Error from opening cipher: 0
Selected cipher: SERPENT128

However swap the two printf statements, i.e. call gcry_cipher_algo_name before gcry_cipher_open, and the output is

Selected cipher: ?
Error from opening cipher: 536870924

I'm struggling to grasp as to why opening a cipher should fail after doing a mere query.

The funny thing is that if I select int algo=GCRY_CIPHER_AES128 with query-before-open, everythig does work again:

Selected cipher: AES
Error from opening cipher: 0

Is gcry_cipher_openout failing for query-before-open for non-AES a bug or a feature?


More information about the Gcrypt-devel mailing list