2021-08-10 07:48 AM
Hi,
We are migrating our code from using the legacy crypto lib to the libSTM32Cryptographic_CM4.a.
2.I am trying to write code that gets the public key from a given private key.
I had it working with the legacy code using the
retval = ECCscalarMul(G, ephermPrivKey, ephermPubKey, &ECparams, &mb);
but now I can not get it to work.
This is my code:
retval = cmox_ecdh(&Ecc_Ctx,
CMOX_ECC_CURVE_SECP256R1,
ephemPrivateKeyMsg.p_buf,
ephemPrivateKeyMsg.length,
ecc_256_FullG,
sizeof(ecc_256_FullG),
fullEphermPubKey,
&fullEphemPubLength);
where ecc_256_FullG is the x and y values of G, first x coordinate, then Y coordinate (that were correct in the legacy code), see below
Any ideas? example code for this?
Thanks!
const uint8_t ecc_256_FullG[]={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,
2023-04-21 10:30 AM
Hello @YCohe.1,
I'm sorry for late answer.
The X-CUBE-CRYPTOLIB provides cmox_ecdsa_keyGen function.
cmox_ecc_retval_t cmox_ecdsa_keyGen(cmox_ecc_handle_t *P_pEccCtx,
const cmox_ecc_impl_t P_CurveParams,
const uint8_t *P_pRandom,
size_t P_RandomLen,
uint8_t *P_pPrivKey,
size_t *P_pPrivKeyLen,
uint8_t *P_pPubKey,
size_t *P_pPubKeyLen);
You provide a random value as input and you get the private and public key.
The function actually modifies the random only in case it does not fit to the curve.
So, if you provide a valid private key as random value in input parameter P_pRandom, you will get back same private key and corresponding public key.
Best regards
Jocelyn
2023-07-04 10:38 PM
2023-07-06 10:12 PM
nvm... i figured out
2023-07-21 05:13 AM
hi can you tell me how did you figured out ??
I am having problem of not getting public key.