Skip to content

Commit

Permalink
Added RNG for nRF52 series. Fixed infinite for loop because of int - …
Browse files Browse the repository at this point in the history
…wordcount_t mismatch
  • Loading branch information
jaroban committed Oct 27, 2020
1 parent 4b1709c commit 71563d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions platform-specific.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ static int default_RNG(uint8_t *dest, unsigned size) {
}
#define default_RNG_defined 1

#elif defined(NRF52_SERIES)

#include "app_error.h"
#include "nrf_crypto_rng.h"

static int default_RNG(uint8_t *dest, unsigned size)
{
// make sure to call nrf_crypto_init and nrf_crypto_rng_init first
ret_code_t ret_code = nrf_crypto_rng_vector_generate(dest, size);
return (ret_code == NRF_SUCCESS) ? 1 : 0;
}
#define default_RNG_defined 1

#endif /* platform */

#endif /* _UECC_PLATFORM_SPECIFIC_H_ */
4 changes: 2 additions & 2 deletions uECC.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ uECC_VLI_API void uECC_vli_bytesToNative(uint8_t *native,
uECC_VLI_API void uECC_vli_nativeToBytes(uint8_t *bytes,
int num_bytes,
const uECC_word_t *native) {
wordcount_t i;
int i;
for (i = 0; i < num_bytes; ++i) {
unsigned b = num_bytes - 1 - i;
bytes[i] = native[b / uECC_WORD_SIZE] >> (8 * (b % uECC_WORD_SIZE));
Expand All @@ -1004,7 +1004,7 @@ uECC_VLI_API void uECC_vli_nativeToBytes(uint8_t *bytes,
uECC_VLI_API void uECC_vli_bytesToNative(uECC_word_t *native,
const uint8_t *bytes,
int num_bytes) {
wordcount_t i;
int i;
uECC_vli_clear(native, (num_bytes + (uECC_WORD_SIZE - 1)) / uECC_WORD_SIZE);
for (i = 0; i < num_bytes; ++i) {
unsigned b = num_bytes - 1 - i;
Expand Down

0 comments on commit 71563d8

Please sign in to comment.