mirror of
https://github.com/kmackay/micro-ecc.git
synced 2026-10-09 01:07:35 +00:00
Fixed build for avr.
This commit is contained in:
+34
-20
@@ -2,9 +2,42 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if __AVR__
|
||||
|
||||
int RNG(uint8_t *p_dest, unsigned p_size)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int RNG(uint8_t *p_dest, unsigned p_size)
|
||||
{
|
||||
static int l_randfd = -1;
|
||||
if(l_randfd == -1)
|
||||
{
|
||||
l_randfd = open("/dev/urandom", O_RDONLY);
|
||||
if(l_randfd == -1)
|
||||
{
|
||||
printf("No access to urandom\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(read(l_randfd, p_dest, p_size) != (int)p_size)
|
||||
{
|
||||
printf("Failed to get random bytes.\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* TARGET_ARCH_AVR */
|
||||
|
||||
void vli_print(uint8_t *p_vli, unsigned int p_size)
|
||||
{
|
||||
while(p_size)
|
||||
@@ -14,18 +47,6 @@ void vli_print(uint8_t *p_vli, unsigned int p_size)
|
||||
}
|
||||
}
|
||||
|
||||
int randfd;
|
||||
|
||||
int RNG(uint8_t *p_dest, unsigned p_size)
|
||||
{
|
||||
if(read(randfd, p_dest, p_size) != (int)p_size)
|
||||
{
|
||||
printf("Failed to get random bytes.\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
@@ -38,14 +59,7 @@ int main()
|
||||
|
||||
uint8_t l_secret1[ECC_BYTES];
|
||||
uint8_t l_secret2[ECC_BYTES];
|
||||
|
||||
randfd = open("/dev/urandom", O_RDONLY);
|
||||
if(randfd == -1)
|
||||
{
|
||||
printf("No access to urandom\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ecc_set_rng(&RNG);
|
||||
|
||||
printf("Testing 256 random private key pairs\n");
|
||||
|
||||
Reference in New Issue
Block a user