#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/rsa.h>
int mian(int argc,char *arfv[]){
ecc_key key;
wc_ecc_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
int ret =1;
ret = wc_ecc_make_key(&rng,32,&key);
printf("%d\n",ret);
} 在这里输入图像描述错误:不知道“密钥”的存储大小,我已经包含了ecc.h文件,为什么不知道“密钥”的存储大小?
发布于 2022-11-17 15:36:58
解决方案:确保在任何其他wolfSSL头之前包括库配置设置。wolfSSL可以通过以下任意一种配置:
<wolfssl/options.h> (当使用步骤./configure && make构建wolfSSL时自动生成的文件)<wolfssl/wolfcrypt/settings.h>和用户可以全局定义WOLFSSL_USER_SETTINGS来创建自己的user_settings.h头,以“调优”构建设置。在全局定义user_settings.h时,<wolfssl/wolfcrypt/settings.h>将包含WOLFSSL_USER_SETTINGS头。无论哪种方式,库配置都需要包括在所有其他wolfSSL头之前!
类似的错误再现(编译器版本可能因消息显示而异,我的没有说“密钥的存储大小是未知的”,但我的输出看起来非常类似于您的屏幕快照)。
$ gcc stackoverflow.c -o run -I/Users/kalebhimes/work/testDir/wolf-install-dir-for-testing/include -L/Users/kalebhimes/work/testDir/wolf-install-dir-for-testing/lib -lwolfssl
In file included from stackoverflow.c:4:
In file included from /Users/kalebhimes/work/testDir/wolf-install-dir-for-testing/include/wolfssl/ssl.h:33:
/Users/kalebhimes/work/testDir/wolf-install-dir-for-testing/include/wolfssl/wolfcrypt/settings.h:2348:14: warning: "For timing resistance / side-channel attack prevention consider using harden options" [-W#warnings]
#warning "For timing resistance / side-channel attack prevention consider using harden options"
^
stackoverflow.c:10:9: error: variable has incomplete type 'ecc_key' (aka 'struct ecc_key')
ecc_key key;
^
/Users/kalebhimes/work/testDir/wolf-install-dir-for-testing/include/wolfssl/wolfcrypt/asn_public.h:43:20: note: forward declaration of 'struct ecc_key'
typedef struct ecc_key ecc_key;
^
stackoverflow.c:11:1: error: implicit declaration of function 'wc_ecc_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
wc_ecc_init(&key);
^
stackoverflow.c:15:7: error: implicit declaration of function 'wc_ecc_make_key' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ret = wc_ecc_make_key(&rng,32,&key);
^
1 warning and 3 errors generated.修正了这个补丁:
--- stackoverflow.c.orig 2022-11-17 08:33:50.000000000 -0700
+++ stackoverflow.c 2022-11-17 08:36:04.000000000 -0700
@@ -1,12 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+// Added the library configuration BEFORE including other wolfSSL headers
+// Alternatively include <wolfssl/wolfcrypt/settings.h> if the library was not
+// built with ./configure && make (which auto-generates options.h)
+#include <wolfssl/options.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/rsa.h>
-int mian(int argc,char *arfv[]){
+// main was mis-spelled :-)
+//int mian(int argc,char *arfv[]){
+int main(int argc,char *arfv[]){
ecc_key key;
wc_ecc_init(&key);
WC_RNG rng;现在,应用程序成功运行!干杯。
https://stackoverflow.com/questions/74470843
复制相似问题