This is my test code for ECDSA.
Thank you.
void ECDSA_Verfiy_Msg_2(void) {
const uint8_t ecc_256_a[]={0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc};
const uint8_t ecc_256_b[]={0x5a,0xc6,0x35,0xd8,0xaa,0x3a,0x93,0xe7,0xb3,0xeb,0xbd,0x55,0x76,0x98,0x86,0xbc,0x65,0x1d,0x06,0xb0,0xcc,0x53,0xb0,0xf6,0x3b,0xce,0x3c,0x3e,0x27,0xd2,0x60,0x4b};
const uint8_t ecc_256_p[]={0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
const uint8_t ecc_256_n[]={0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xbc,0xe6,0xfa,0xad,0xa7,0x17,0x9e,0x84,0xf3,0xb9,0xca,0xc2,0xfc,0x63,0x25,0x51};
const uint8_t ecc_256_xG[]={0x6b,0x17,0xd1,0xf2,0xe1,0x2c,0x42,0x47,0xf8,0xbc,0xe6,0xe5,0x63,0xa4,0x40,0xf2,0x77,0x03,0x7d,0x81,0x2d,0xeb,0x33,0xa0,0xf4,0xa1,0x39,0x45,0xd8,0x98,0xc2,0x96};
const uint8_t ecc_256_yG[]={0x4f,0xe3,0x42,0xe2,0xfe,0x1a,0x7f,0x9b,0x8e,0xe7,0xeb,0x4a,0x7c,0x0f,0x9e,0x16,0x2b,0xce,0x33,0x57,0x6b,0x31,0x5e,0xce,0xcb,0xb6,0x40,0x68,0x37,0xbf,0x51,0xf5};
const uint8_t ecc_256_privkey[]={0xa4,0x57,0x77,0x90,0xbd,0xc1,0x5b,0x73,0x12,0x10,0x1a,0x4d,0x1c,0xde,0xba,0xf6,0xac,0x51,0xf1,0x94,0x9e,0x9c,0xdd,0x8c,0x60,0x9f,0x0c,0xe8,0xd7,0x02,0xee,0x67};
const uint8_t ecc_256_pubkey[]={0x1d,0x2b,0x32,0x57,0x29,0xd3,0x42,0x64,0x17,0xa5,0x5b,0xab,0x90,0x9b,0x14,0xc6,0xf6,0x16,0x1e,0xd0,0x30,0xe3,0x98,0xaf,0xc1,0x09,0x7a,0x65,0x3e,0xbd,0x4f,0xf6,0xab,0xd5,0x0a,0x44,0x14,0x14,0x9d,0xfd,0xf1,0xbc,0x82,0x60,0x5e,0xa4,0xd7,0xbe,0xa1,0xee,0xc1,0xe1,0xde,0x5a,0x20,0x20,0x88,0xa5,0xe6,0x61,0x34,0x74,0x01,0xd0};
uint32_t ecc_256_pubkey_x[8] = {};
uint32_t ecc_256_pubkey_y[8] = {};
EC_stt ECparams;
EC_stt* pECparams = &ECparams;
membuf_stt mb;
// Structure that will contain the public key
ECpoint_stt *PubKey = NULL;
// Private Key Structure
ECCprivKey_stt *privKey = NULL;
ECpoint_stt *G = NULL;
int32_t retval;
CANTxFrame errReportTxf, msgTxf;
InitCANtxfmessage(&msgTxf, 0x10dd0000);
InitCANtxfmessage(&errReportTxf, 0x18ff9999);
// Initialize the EC_stt structure with the known values. We also initialize to NULL and zero the unknown parameter
ECparams.mAsize = sizeof(ecc_256_a);
ECparams.pmA = ecc_256_a;
ECparams.mPsize = sizeof(ecc_256_p);
ECparams.pmP = ecc_256_p;
ECparams.pmN = ecc_256_n;
ECparams.mNsize = sizeof(ecc_256_n);
ECparams.pmB = ecc_256_b;
ECparams.mBsize = sizeof(ecc_256_b);
ECparams.pmGx = ecc_256_xG;
ECparams.mGxsize = sizeof(ecc_256_xG);
ECparams.pmGy = ecc_256_yG;
ECparams.mGysize = sizeof(ecc_256_yG);
//Set up the membuf_stt structure to a preallocated (on stack) buffer of 4kB
uint8_t preallocated_buffer[4096];
mb.mSize = sizeof(preallocated_buffer);
mb.mUsed = 0;
mb.pmBuf = preallocated_buffer;
//RNG context
RNGstate_stt RNGstate;
//RNG init structure
RNGinitInput_stt RNGinit_st;
RNGstate_stt* pRNGstate;
pRNGstate = &RNGstate;
uint8_t entropy_data[32] = {
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80
};
uint8_t nonce[8] = { 0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F, 0x7A, 0x8B };
uint8_t AES_iv[16]; //It will be the output of our RNG call
//Let's Instantiate with entropy,nonce and no personalization string.
RNGinit_st.pmEntropyData = entropy_data;
RNGinit_st.mEntropyDataSize = sizeof(entropy_data);
RNGinit_st.pmNonce = nonce;
RNGinit_st.mNonceSize = sizeof(nonce);
RNGinit_st.pmPersData = NULL;
RNGinit_st.mPersDataSize = 0;
//Let's initialize the RNG state/context
retval = RNGinit(&RNGinit_st, C_DRBG_AES128, &RNGstate);
if (retval != RNG_SUCCESS) {
errReportTxf.data8[0] = 1;
}
errReportTxf.data8[0] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
// Call the Elliptic Curve initialization function
retval = ECCinitEC(&ECparams, &mb);
if (retval != 0)
{
errReportTxf.data8[1] = 1;
}
errReportTxf.data8[1] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
//Initialize the point that will contain the generator point
retval = ECCinitPoint(&G, &ECparams, &mb);
if (retval != 0)
{
errReportTxf.data8[2] = 1;
}
errReportTxf.data8[2] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
//Set the coordinates of the generator point inside G
retval = ECCsetPointGenerator(G, &ECparams);
if (retval != 0)
{
errReportTxf.data8[3] = 1;
}
errReportTxf.data8[3] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
//Init PubKey object
retval = ECCinitPoint(&PubKey, pECparams, &mb);
if (retval != 0)
{
errReportTxf.data8[4] = 1;
}
errReportTxf.data8[4] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
//Init Privkey object
retval = ECCinitPrivKey(&privKey, pECparams, &mb);
if (retval != 0)
{
errReportTxf.data8[5] = 1;
}
errReportTxf.data8[5] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
//Call the Key Generation Function
retval = ECCkeyGen(privKey, PubKey, pRNGstate, pECparams, &mb);
if (retval != 0)
{
errReportTxf.data8[6] = 1;
}
errReportTxf.data8[6] = 2;
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
transmitCANMsg32bits(msgTxf, privKey->pmD->pmDigit, 8);
can_lld_transmit(&CAND1, CAN_ANY_TXBUFFER, &errReportTxf);
// SHA256("1234567890")
uint8_t digest[32] = {0xf2,0xd0,0x06,0x23,0x55,0xae,0xa5,0x15,0x1f,0x7c,0x81,0x50,0xd8,0x86,0xe2,0xd4,0x81,0x2e,0xab,0x6f,0xad,0xeb,0xf1,0x7e,0xa1,0x43,0x75,0xcd,0xe9,0xdb,0x52,0xb4};
}