Topic: 'ecc_mul2add()' cannot be used

I checked the original code and found that FP_ECC needs to be compiled.I have added --enable-ecclshamir and --enable-fpecc when compiling, but it still prompts undefined reference to 'ecc_mul2add()' when compiling.And I did not find an example of 'ecc_mul2add()' in the test file.I'm so sorry to bother you with this stupid question.Here is my compile command:‘./configure --enable-eccshamir --enable-fpecc --enable-opensslextra --enable-ecc --enable-ecccustcurves CFLAGS="-DWOLFSSL_TEST_CERT -DWOLFSSL_DER_TO_PEM -DHAVE_ECC_KOBLITZ -DWOLFSSL_PUBLIC_MP -DUSE_ECC_B_PARAM"&&make&&sudo make install’

#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>
#include <wolfssl/wolfcrypt/sha.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/hash.h>
#include <wolfssl/wolfcrypt/asn.h>
#include <wolfssl/wolfcrypt/aes.h>
//#include <wolfssl/wolfcrypt/sp.h>
using namespace std;
int main(){
 
    ecc_key key;
    int ret;
    WC_RNG rng;
    wc_ecc_init(&key);
    wc_InitRng(&rng);
    int curveId = ECC_SECP256R1;
    int keySize = wc_ecc_get_curve_size_from_id(curveId);
    ret = wc_ecc_make_key_ex(&rng, keySize, &key, curveId);
    if (ret != MP_OKAY) {
    // error handling
    }
 
    //ecc_projective_add_point();
    ecc_point *point_a = wc_ecc_new_point();
    ecc_point *point_b = wc_ecc_new_point();
 
    mp_int num1,num2,num3;
    mp_init(&num1);
    mp_init(&num2);
    mp_init(&num3);
    mp_set_int(&num1,23);
    mp_set_int(&num2,45);
    mp_add(&num1,&num2,&num3);
 
    mp_int a,b,prime,order,num;
    mp_init_multi(&a,&b,&prime,&order,&num,NULL);
    ret = mp_read_radix(&a,key.dp->Af,16);
    cout<<"get mp_int af: "<<ret<<endl;
    ret = mp_read_radix(&b,key.dp->Bf,16);
    cout<<"get mp_int bf: "<<ret<<endl;
    ret = mp_read_radix(&prime,key.dp->prime,16);
    cout<<"get mp_int prime: "<<ret<<endl;
    ret = mp_read_radix(&order,key.dp->order,16);
    cout<<"get mp_int order: "<<ret<<endl;
    ret = wc_ecc_gen_k(&rng,32,&num,&order);
    cout<<"get mp_int num: "<<ret<<endl;
 
    ecc_point* point = wc_ecc_new_point();
    //ecc_point* point_res = wc_ecc_new_point();
    ret = wc_ecc_get_generator(point,wc_ecc_get_curve_idx(ECC_SECP256R1));
    cout<<"get ecc_point point: "<<ret<<endl;
 
    ret = wc_ecc_mulmod(&num1,point,point_a,&a,&prime,1);
    cout<<"num1 * point: "<<ret<<endl;
    ret = wc_ecc_mulmod(&num2,point,point_b,&a,&prime,1);
    cout<<"num2 * point: "<<ret<<endl;
 
    mp_int ka,kb;
    mp_init(&ka);
    mp_init(&kb);
    mp_set_int(&ka,1);
    mp_set_int(&kb,1);
 
    ecc_point* point_c = wc_ecc_new_point();
 
    ret = ecc_mul2add(point_a,&ka,point_b,&kb,point_c,&a,&prime,NULL);
    cout<<"ecc_mul2add: "<<ret<<endl;
 
 
    return 0;
    }

Share

Re: 'ecc_mul2add()' cannot be used

Hi wangzihao,

The --enable-fpecc option enables Fixed Point cache ECC. It is not required to use ecc_mul2add.

You do need to make the function public by adding -DWOLFSSL_PUBLIC_ECC_ADD_DBL to CFLAGS

Please keep these questions coming! We are happy to help others learn!

Thanks,
Eric

Re: 'ecc_mul2add()' cannot be used

Hello Eric,
    It worked, thank you very much for your patient answer, I also want to know which file or document or source code should I check when I encounter the problem of undefined reference to 'xxx' to know what content should be added to compile, I  saw the ifdef 'yyy' in front of the 'xxx' function in the source code before, and then I know that 'yyy' should be added when compiling, but it seems that this method does not always work, so I want to know if you have any way to know  What is added at compile time.

Thanks again,
Wangzihao

Share

Re: 'ecc_mul2add()' cannot be used

A lot of the math functions your are trying to use are gated because they are not typically used by applications. I can't really give you a "guide" to exposing these API. You should review the header files, as they are a pretty good indicator if a function is gated.