Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
Stefan `Sec` Zehl 2011-07-24 01:52:19 +02:00
commit f13a772cca
7 changed files with 40 additions and 18 deletions

View File

@ -5,6 +5,7 @@
#include "lcd/fonts/smallfonts.h" #include "lcd/fonts/smallfonts.h"
#include "lcd/print.h" #include "lcd/print.h"
#include "filesystem/ff.h" #include "filesystem/ff.h"
#include "basic/random.h"
/**************************************************************************/ /**************************************************************************/
@ -92,6 +93,7 @@ int lcdInitConfig(){
void main_default(void) { void main_default(void) {
systickInit(10); systickInit(10);
randomInit();
if(getInputRaw()==BTN_ENTER){ if(getInputRaw()==BTN_ENTER){
ISPandReset(); ISPandReset();

View File

@ -16,6 +16,7 @@ OBJS += menu.o
OBJS += xxtea.o OBJS += xxtea.o
OBJS += ecc.o OBJS += ecc.o
OBJS += byteorder.o OBJS += byteorder.o
OBJS += random.o
LIBNAME=basic LIBNAME=basic

View File

@ -13,29 +13,15 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include "ecc.h" #include "ecc.h"
#include "random.h"
exp_t base_order; exp_t base_order;
elem_t poly; /* the reduction polynomial */ elem_t poly; /* the reduction polynomial */
elem_t coeff_b, base_x, base_y; 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() unsigned char rnd1()
{ {
static int a=123456789; return random() & 0xFF;
a = (xmult(a,xrandb1)+1)%xrandm;
return a & 0xff;
} }

26
firmware/basic/random.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdint.h>
#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<STATE_SIZE; j++){
x = 0;
for(i=0; i<10240; i++){
x ^= (adcRead(1)&1)<<(i%32);
}
state[j] = x;
}
xxtea_encode_words(state, STATE_SIZE, I);
}
uint32_t random(void)
{
xxtea_encode_words(state, STATE_SIZE, I);
return state[0];
}

7
firmware/basic/random.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _RANDOM_H_
#define _RANDOM_H_
void randomInit(void);
uint32_t random(void);
#endif

View File

@ -96,7 +96,7 @@ uint8_t openbeaconSend(void)
status = openbeaconSendPacket(oid, seq, 0xFF, strength++); status = openbeaconSendPacket(oid, seq, 0xFF, strength++);
if( strength == 4 ) if( strength == 4 )
strength = 0; strength = 0;
if( seq++ & OPENBEACON_SAVE == OPENBEACON_SAVE ) if( (seq++ & OPENBEACON_SAVE) == OPENBEACON_SAVE )
openbeaconSaveBlock(); openbeaconSaveBlock();
return status; return status;
} }

View File

@ -12,7 +12,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[1] = size >> 8; buf[1] = size >> 8;
buf[2] = size & 0xFF; buf[2] = size & 0xFF;
uint16_t rand = 5; //random_rand16(); uint16_t rand = random() & 0xFFFF;
buf[3] = rand >> 8; buf[3] = rand >> 8;
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;