0

openssl中,我想运行从 HKDF 提取文档中获得的以下代码示例:

  #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);

但我不知道这些标头是否已更改或是否存在其他问题。当我编译为 g++ test.cpp -g -lssl -lcrypto.

输出是,

++ 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;
 ...

它以这种方式遵守,并且在此编译单元中没有看到任何类型。

4

1 回答 1

0

为此,您需要 openssl 3.0.0 或更高版本。

于 2021-10-27T09:04:41.527 回答