cancel
Showing results for 
Search instead for 
Did you mean: 

Where is there example code for getting a public key from a private key in ECC Cube cryptographic library?

YCohe.1
Associate

Hi,

We are migrating our code from using the legacy crypto lib to the libSTM32Cryptographic_CM4.a.

  1. I can not find api document describing the functions etc, is there any thing like there was for the legacy lib (like https://www.st.com/resource/en/user_manual/dm00215061-stm32-crypto-library-stmicroelectronics.pdf)?

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,

4 REPLIES 4
Jocelyn RICARD
ST Employee

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

I am not getting private and public key using cmox_ecdsa_keyGen() function. I am using random number generator as random value input.

nvm... i figured out

hi can you tell me how did you figured out ?? 

I am having problem of not getting public key.