1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 09:28:13 +00:00

use /dev/urandom in example

This commit is contained in:
Pavol Rusnak 2013-08-21 20:23:43 +02:00
parent 0f7c3be5dd
commit 4593b3f636
3 changed files with 11 additions and 12 deletions

9
README
View File

@ -10,17 +10,12 @@ Notes
a) the signer only understands secp256k1 elliptic curve a) the signer only understands secp256k1 elliptic curve
b) random generator in rand.c is using stdlib's rand() function. b) there are executables:
you should replace this code with one that uses a hardware random
generator of your microcontroller in production.
(see speed-stm32/rand.c for such example)
c) there are executables:
* test-speed * test-speed
- check signing speed (sign 100x and compute speed from duration) - check signing speed (sign 100x and compute speed from duration)
* test-verify * test-verify
- generate random messages and private keys - generate random messages and private keys
- check signature validity against OpenSSL (call verify method) - check signature validity against OpenSSL (call verify method)
d) directory speed-stm32 contains project for deploying the code c) directory speed-stm32 contains project for deploying the code
on STM32 microcontroller and checking signing speed there on STM32 microcontroller and checking signing speed there

12
rand.c
View File

@ -21,16 +21,18 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdlib.h> #include <stdio.h>
#include <stdint.h>
#include <time.h>
#include "rand.h" #include "rand.h"
static FILE *f;
void init_rand(void) { void init_rand(void) {
srand(time(NULL)); f = fopen("/dev/urandom", "r");
} }
uint32_t random32(void) { uint32_t random32(void) {
return (rand() & 0xFF) + ((rand() & 0xFF) << 8) + ((rand() & 0xFF) << 16) + ((rand() & 0xFF) << 24); uint32_t r;
fread(&r, 1, sizeof(r), f);
return r;
} }

2
rand.h
View File

@ -24,6 +24,8 @@
#ifndef __RAND_H__ #ifndef __RAND_H__
#define __RAND_H__ #define __RAND_H__
#include <stdint.h>
void init_rand(void); void init_rand(void);
uint32_t random32(void); uint32_t random32(void);