Topic: the result returned by 'wc_ecc_point_is()' is inconnect
I get the elliptic curve parameters a, b, prime, order, convert the parameters into mp_int format, and then use ‘‘wc_ecc_gen_k()’ to generate a random number num. Use‘ wc_ecc_get_generator()’ to get the generator, ‘use wc_ecc_is_point()’ to judge whether the generator is on the elliptic curve, the returned value is -214 not 0, the generator must be on the curve, why return -214, I use ‘wc_ecc_mulmod ()’ Get the product point_res of num and the generator, judge whether it is on the curve, the return value obtained is also -214, this point should also be on the curve, why return -214, is there something wrong with my code, or the compiler , or something else?
#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
}
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,ECC_SECP256R1);
cout<<"get ecc_point point: "<<ret<<endl;
ret = wc_ecc_is_point(point,&a,&b,&prime);
cout<<"point is on curve: "<<ret<<endl;
ret = wc_ecc_mulmod(&num,point,point_res,&a,&prime,1);
cout<<"get ecc_point point_res: "<<ret<<endl;
ret = wc_ecc_is_point(point_res,&a,&b,&prime);
cout<<"point_res is on curve: "<<ret<<endl;
return 0;
}