int main(void) { uint32_t err_code; uint32_t time0, time1; LOG("Starting LFCLK"); err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); nrf_drv_clock_lfclk_request(NULL); LOG("Starting RTC"); err_code = nrf_drv_rtc_init(&rtc, NULL, &rtc_handler); APP_ERROR_CHECK(err_code); nrf_drv_rtc_tick_enable(&rtc, false); nrf_drv_rtc_enable(&rtc); LOG("Starting RNG"); err_code = nrf_drv_rng_init(NULL); APP_ERROR_CHECK(err_code); while (1) { /* get a random key */ time0 = nrf_drv_rtc_counter_get(&rtc); uECC_make_key(public_key, private_key); time1 = nrf_drv_rtc_counter_get(&rtc); LOG("Key time was %u ", time1 - time0); /* use the key to sign the hash */ time0 = nrf_drv_rtc_counter_get(&rtc); uECC_sign(private_key, hash, signature); time1 = nrf_drv_rtc_counter_get(&rtc); LOG("Sig Time was %u ", time1 - time0); /* verify the signature */ time0 = nrf_drv_rtc_counter_get(&rtc); uECC_verify(public_key, hash, signature); time1 = nrf_drv_rtc_counter_get(&rtc); LOG("Verify Time was %u ", time1 - time0); time0 = nrf_drv_rtc_counter_get(&rtc); uECC_shared_secret(public_key, private_key, secret); time1 = nrf_drv_rtc_counter_get(&rtc); LOG("SS Time was %u ", time1 - time0); time0 = nrf_drv_rtc_counter_get(&rtc); sha256_init(&context); sha256_update(&context, message, 20); sha256_final(&context, shahash); time1 = nrf_drv_rtc_counter_get(&rtc); LOG("SHA Time was %u ", time1 - time0); } return 0; }
/** @brief Function for main application entry. */ int main(void) { uint32_t err_code; const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud115200 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); #ifdef SOFTDEVICE_PRESENT nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); #endif // SOFTDEVICE_PRESENT err_code = nrf_drv_rng_init(NULL); APP_ERROR_CHECK(err_code); while (true) { uint8_t p_buff[RANDOM_BUFF_SIZE]; uint8_t length = random_vector_generate(p_buff,RANDOM_BUFF_SIZE); printf("Random Vector:"); for(uint8_t i = 0; i < length; i++) { printf(" %3d",(int)p_buff[i]); } printf("\n\r"); nrf_delay_ms(100); } }