0
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);

trying to crypt a word dictionary to find key

Keep getting segmentation faults or storage error

dbush
  • 205,898
  • 23
  • 218
  • 273
  • 1
    This means the definition of the structure is not found. You may want to include the proper header file(s) – Jib Dec 01 '22 at 17:56
  • Sometimes, APIs do not share context structure as is. You are expected to call an init function to get a pointer to a new one which is created by the API itself. Then you pass that pointer to subsequent calls to the API – Jib Dec 01 '22 at 17:58
  • 1
    Pretty sure I had this same issue once. IIRC, Openssl used to make this struct definition public but then made it private. – Shawn Dec 01 '22 at 18:02
  • There are multiple related questions on this topic with newer versions of OpenSSL starting with 1.1.x ([example here](https://stackoverflow.com/questions/47518843/error-field-ctx-has-incomplete-type-evp-cipher-ctx)). – WhozCraig Dec 01 '22 at 18:05

1 Answers1

4

Starting with version 1.1 of OpenSSL, EVP_CIPHER_CTX became an opaque structure, and EVP_CIPHER_CTX_init is now an alias for EVP_CIPHER_CTX_reset which clears an existing structure.

You need to instead use EVP_CIPHER_CTX_new to allocate space for one.

EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
...
EVP_CIPHER_CTX_free(ctx); 
dbush
  • 205,898
  • 23
  • 218
  • 273