예제 #1
0
int init_trng() {
  PRINTF("- initializing random number generator\r\n");
  trng_config_t trngConfig;
  TRNG_GetDefaultConfig(&trngConfig);
  trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
  int r = TRNG_Init(TRNG0, &trngConfig);
  return r == kStatus_Success ? wc_InitRng(&rng) : r;
}
예제 #2
0
파일: trng_api.c 프로젝트: oscarh/mbed-os
void trng_init(trng_t *obj)
{
    trng_config_t trngConfig;

    TRNG_GetDefaultConfig(&trngConfig);
    /* Set sample mode of the TRNG ring oscillator to Von Neumann, for better random data.*/
    trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
    /* Initialize TRNG */
    TRNG_Init(TRNG0, &trngConfig);
}
예제 #3
0
bool uc_init() {
  if (initialized) return true;
  trng_config_t trngConfig;
  TRNG_GetDefaultConfig(&trngConfig);
  trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
  if (TRNG_Init(TRNG0, &trngConfig) != kStatus_Success) return false;
  if (wc_InitRng(&uc_random)) return false;

#if !FSL_FEATURE_SOC_LTC_COUNT
  PRINTF("- no LTC available\r\n");
#else
  LTC_Init(LTC0);
#endif

  initialized = true;
  return true;
}
예제 #4
0
static void hw_rand_init(void)
{
#ifdef FREESCALE_KSDK_BM
    trng_config_t trngConfig;
    TRNG_GetDefaultConfig(&trngConfig);
    /* Set sample mode of the TRNG ring oscillator to Von Neumann, for better random data.*/
    trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
    /* Initialize TRNG */
    TRNG_Init(TRNG0, &trngConfig);
#else
    /* Enable RNG clocks */
    SIM->SCGC6 |= SIM_SCGC6_RNGA_MASK;
    SIM->SCGC3 |= SIM_SCGC3_RNGA_MASK;

    /* Wake up RNG to normal mode (take out of sleep) */
    RNG->CR &= ~RNG_CR_SLP_MASK;

    /* Enable High Assurance mode (Enables notification of security violations via SR[SECV]) */
    RNG->CR |= RNG_CR_HA_MASK;

    /* Enable RNG generation to RANDOUT FIFO */
    RNG->CR |= RNG_CR_GO_MASK;
#endif
}