/* To generate a key to KS SRAM for ECDH.  */
int32_t RNG_ECDH(uint32_t u32KeySize)
/* To generate a key to KS SRAM for ECDH.  */
int32_t RNG_ECDH(uint32_t u32KeySize)
{
    int32_t timeout;
    int32_t i;
    CRPT->PRNG_CTL = (u32KeySize << CRPT_PRNG_CTL_KEYSZ_Pos) | CRPT_PRNG_CTL_START_Msk | PRNG_CTL_SEEDSRC_TRNG;
    timeout = 0x10000;
    i = 0;
    while (CRPT->PRNG_CTL & CRPT_PRNG_CTL_BUSY_Msk)
    {
        if (i++ > timeout)
            return -1;
    }
    if (CRPT->PRNG_KSSTS & CRPT_PRNG_KSSTS_KCTLERR_Msk)
        return -1;
    return (CRPT->PRNG_KSSTS & CRPT_PRNG_KSCTL_NUM_Msk);
}