Openssl ‘EVP_KDF’ was not declared

1k views Asked by At

In openssl, I want to run the following code sample that I got from the HKDF extraction documentation:

  #include <openssl/evp.h>
  #include <openssl/ossl_typ.h>
  #include <openssl/kdf.h>
 
  ...
  EVP_KDF *kdf;
  EVP_KDF_CTX *kctx;
  unsigned char out[10];
  OSSL_PARAM params[5], *p = params;

  kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
  kctx = EVP_KDF_CTX_new(kdf);
  EVP_KDF_free(kdf);

  *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
                                          SN_sha256, strlen(SN_sha256));
  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
                                            "secret", (size_t)6);
  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
                                            "label", (size_t)5);
  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
                                            "salt", (size_t)4);
  *p = OSSL_PARAM_construct_end();
  if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
      error("EVP_KDF_derive");
  }

  EVP_KDF_CTX_free(kctx);

But I don't know if these headers have changed or there is another problem. The problem occurs when I compile as g++ test.cpp -g -lssl -lcrypto.

Output is,

++ test.cpp -g -lssl -lcrypto
test.cpp: In function ‘void hkdf_extract()’:
test.cpp:124:3: error: ‘EVP_KDF’ was not declared in this scope; did you mean ‘EVP_MD’?
  124 |   EVP_KDF *kdf;
      |   ^~~~~~~
      |   EVP_MD
test.cpp:124:12: error: ‘kdf’ was not declared in this scope
  124 |   EVP_KDF *kdf;
      |            ^~~
test.cpp:125:3: error: ‘EVP_KDF_CTX’ was not declared in this scope; did you mean ‘EVP_MD_CTX’?
  125 |   EVP_KDF_CTX *kctx;
 ...

It complies this way and didn't see any of the types, in this compilation unit.

1

There are 1 answers

0
Rajnish On

You need openssl 3.0.0 or greater for this.