Changed to work with: http://redbearlab.com/blenano/
Fork of RNG by
Random.cpp
- Committer:
- feb11
- Date:
- 2013-09-17
- Revision:
- 0:299f3795114b
- Child:
- 1:0536a4ca8d35
File content as of revision 0:299f3795114b:
#include "Random.h" #include "Crypto.h" Random::Random(): f(p20) { AnalogIn a(p15), b(p16), c(p17), d(p18); uint16_t tmp = a.read_u16(); memcpy(pool, &tmp, 2); tmp = b.read_u16(); memcpy(&pool[2], &tmp, 2); tmp = c.read_u16(); memcpy(&pool[4], &tmp, 2); tmp = d.read_u16(); memcpy(&pool[6], &tmp, 2); tmp = a.read_u16(); memcpy(&pool[8], &tmp, 2); tmp = b.read_u16(); memcpy(&pool[10], &tmp, 2); tmp = c.read_u16(); memcpy(&pool[12], &tmp, 2); tmp = d.read_u16(); memcpy(&pool[14], &tmp, 2); } uint8_t Random::getByte() { uint8_t hash[16]; MD5::computeHash(hash, pool, 16); uint8_t tmp = pool[hash[6]%16]; memcpy(pool, hash, 16); return tmp ^ (f.read_u16() & 0xff); } void Random::getBytes(uint8_t *out, uint32_t length) { for(int i = 0; i < length; ++i) out[i] = getByte(); }