Solution: Be sure to include the library configuration settings before any other wolfSSL header. wolfSSL can be configured with either:
<wolfssl/options.h>
(a file that is auto-generated when wolfSSL is built with the steps ./configure && make
)
<wolfssl/wolfcrypt/settings.h>
and users can define
WOLFSSL_USER_SETTINGS
globally to create their own
user_settings.h
header to "tune" the build settings. The user_settings.h
header will get included by
<wolfssl/wolfcrypt/settings.h>
anytime WOLFSSL_USER_SETTINGS
is defined globally.
Either way, the library configuration
needs to be included before all other wolfSSL headers!
Similar Error reproduced (compiler versions may vary by message displayed, mine did not say the "storage size of 'key' is not known" but my output looks very similar to your screen-shot)
$ 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.
Fixed with this patch:
--- 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;
Now the app runs successfully! Cheers.