0
#include <iostream>
#include <string>
#include <unistd.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/sp_int.h>
#include <wolfssl/wolfcrypt/integer.h>
#include <wolfssl/wolfcrypt/wolfmath.h>
using namespace std;
int main(){
    ecc_key key;
    WC_RNG rng;
    wc_ecc_init(&key);
    wc_InitGng(&rng);
    int curveId = ECC_SECP521R1;

    const ecc_set_type* ecc_params;
    ecc_params = wc_ecc_get_curve_params(curveId);

    mp_int ord;     //order of ecc
    mp_int priv;    //privatekey 
    int err;
    err = mp_init(&ord);
    cout<<err<<endl;
    err = mp_init(&priv);
    cout<<err<<endl;
    //err = mp_read_radix(&ord,ecc_params->order,MP_RADIX_HEX);   //
    //cout<<err<<endl;
    //err = wc_ecc_gen_k(&rng,120,&priv,&ord)
    return 0 ;
}


enter image description here

i have include <wolfssl/wolfcrypt/sp_int.h>,but it told me undefined reference to 'sp_init',one solution maybe work according tohttps://github.com/wolfSSL/wolfssl/pull/5328,but i don't quite understand .how to solve this problem

zihao wang
  • 17
  • 2
  • Hi zihao, can you include the build settings that were used? I was able to compile and execute the above source by configuring wolfSSL library with the setting `--enable-sp` and by changing wc_InitGng() to wc_InitRng(). – Kaleb Dec 13 '22 at 16:06
  • i reconfigured wolfssl library using commond ./configure --enable-sp && make && sudo make install .and i saw SP implementation all in Features.but when i used commond: g++ file.cpp -o file -l wolfssl , but it told me undefined reference to 'sp_init',thank you very much for answering my question – zihao wang Dec 15 '22 at 03:40
  • Can you try compiling with `g++ file.cpp -o file -I/usr/local/include -L/usr/local/lib -lwolfssl` and let me know if that solves the problem? The library needs to be linked to the app as well :), we tell the compiler where the library is with `-L/usr/local/lib` and then to look for something like`libwolfssl.so` with `-lwolfssl`. This should solve the link-time problem when building your app. Next when you go to run the app please first do `export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib` from the terminal so the shared lib can be found at run time. – Kaleb Dec 15 '22 at 21:48
  • Just checking back to see if the above solved the issue. If so I'll post an official answer. – Kaleb Dec 29 '22 at 15:51
  • thank you very much for answer my question. I do as you say but it didn't work .it told me:/usr/bin/ld: /tmp/ccHlIxke.o :in function 'main':test.cpp:(.text+0x6b8):undefined reference to 'sp_init' collect2:error :ld returned 1 exit status. – zihao wang Dec 31 '22 at 03:56
  • thank you very much for answer my question. I do as you say but it didn't work .it told me:/usr/bin/ld: /tmp/ccHlIxke.o :in function 'main':test.cpp:(.text+0x6b8):undefined reference to 'sp_init' collect2:error :ld returned 1 exit status.i do 2 commond :export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib",the first commond succeed,and second commond g++ test.cpp -o file -I/usr/local/include -L/usr/local/lib - l wolfssl failed – zihao wang Dec 31 '22 at 04:15
  • I am so sorry to hear that. I will hold off on posting an official answer since the suggestion did not resolve the issue. If you want you may open a support line directly to wolfSSL engineers to assist you in working through the issue by emailing support@wolfssl.com, the wolfSSL team offers free pre-sales customer support and can likely assist in resolving the issue. – Kaleb Jan 03 '23 at 15:22
  • I don't know if that is a typo or not but two times now in your comments you put `-l wolfssl` with a space between the -l and the library name wolfssl. This should be all one `-lwolfssl` with no space. Perhaps it is something as simple as that gating you from success? – Kaleb Jan 18 '23 at 15:34
  • i cannot include ,is this normal?it told me undefined reference to 'sp_init' – zihao wang Feb 27 '23 at 01:33
  • No this is not normal, can you send a detailed report of the problem to support wolfssl com (email) so one of our support staff can work with you in a more dedicated way? – Kaleb Feb 27 '23 at 21:27
  • Thanks a lot for the long help, this problem has been solved,it need to configure the library to expose them as public using the configuration define WOLFSSL_PUBLIC_MP,referring to the answer in my another post – zihao wang Feb 28 '23 at 01:43
  • Great to hear! Glad you were able to solve it. Cheers. – Kaleb Feb 28 '23 at 18:45

0 Answers0