From cdaa8f78cabd96a2e27b6fc35ef7c317ad49264c Mon Sep 17 00:00:00 2001 From: schneider Date: Sat, 23 Jul 2011 23:47:42 +0200 Subject: [PATCH] added random number generator based on adc and xxtea --- firmware/applications/default.c | 2 ++ firmware/basic/Makefile | 1 + firmware/basic/ecc.c | 18 ++---------------- firmware/basic/random.c | 26 ++++++++++++++++++++++++++ firmware/basic/random.h | 7 +++++++ firmware/funk/openbeacon.c | 2 +- firmware/funk/rftransfer.c | 2 +- 7 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 firmware/basic/random.c create mode 100644 firmware/basic/random.h diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 2e41ac6..e98a7e2 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -5,6 +5,7 @@ #include "lcd/fonts/smallfonts.h" #include "lcd/print.h" #include "filesystem/ff.h" +#include "basic/random.h" /**************************************************************************/ @@ -92,6 +93,7 @@ int lcdInitConfig(){ void main_default(void) { systickInit(10); + randomInit(); if(getInputRaw()==BTN_ENTER){ ISPandReset(); diff --git a/firmware/basic/Makefile b/firmware/basic/Makefile index 7bbd1bb..c192e24 100644 --- a/firmware/basic/Makefile +++ b/firmware/basic/Makefile @@ -15,6 +15,7 @@ OBJS += menu.o OBJS += xxtea.o OBJS += ecc.o OBJS += byteorder.o +OBJS += random.o LIBNAME=basic diff --git a/firmware/basic/ecc.c b/firmware/basic/ecc.c index 321fa8b..7d99523 100644 --- a/firmware/basic/ecc.c +++ b/firmware/basic/ecc.c @@ -13,29 +13,15 @@ #include #include #include "ecc.h" +#include "random.h" exp_t base_order; elem_t poly; /* the reduction polynomial */ elem_t coeff_b, base_x, base_y; -static int xrandm=100000000; -static int xrandm1=10000; -static int xrandb1=51723621; - -int xmult(int p,int q) -{ -int p1,p0,q1,q0; - -p1=p/xrandm1; p0=p%xrandm1; -q1=q/xrandm1; q0=q%xrandm1; -return (((p0*q1+p1*q0)%xrandm1)*xrandm1+p0*q0)%xrandm; -} - unsigned char rnd1() { -static int a=123456789; -a = (xmult(a,xrandb1)+1)%xrandm; -return a & 0xff; + return random() & 0xFF; } diff --git a/firmware/basic/random.c b/firmware/basic/random.c new file mode 100644 index 0000000..26a9c94 --- /dev/null +++ b/firmware/basic/random.c @@ -0,0 +1,26 @@ +#include +#include "random.h" +#include "xxtea.h" + +#define STATE_SIZE 8 +uint32_t state[STATE_SIZE]; +uint32_t const I[4] = {12,13,14,15}; + +void randomInit(void) +{ + uint32_t i,j,x; + for(j=0; j> 8; buf[2] = size & 0xFF; - uint16_t rand = 5; //random_rand16(); + uint16_t rand = random() & 0xFFFF; buf[3] = rand >> 8; buf[4] = rand & 0xFF;