在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;
...它以这种方式编译,并且在这个编译单元中看不到任何类型。
发布于 2021-10-27 09:04:42
为此,您需要openssl 3.0.0或更高版本。
https://stackoverflow.com/questions/69304868
复制相似问题