mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-28 14:54:05 +00:00
PPP, magic, MD5 random pool size cannot be anything else than MD5 hash size, code cleaning to make it clear
This commit is contained in:
parent
311644f39b
commit
ced7bef274
@ -86,19 +86,10 @@
|
|||||||
#include "polarssl/md5.h"
|
#include "polarssl/md5.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAGIC_RANDPOOLSIZE 16 /* Bytes stored in the pool of randomness. */
|
#define MD5_HASH_SIZE 16
|
||||||
|
static char magic_randpool[MD5_HASH_SIZE]; /* Pool of randomness. */
|
||||||
/*****************************/
|
|
||||||
/*** LOCAL DATA STRUCTURES ***/
|
|
||||||
/*****************************/
|
|
||||||
static char magic_randpool[MAGIC_RANDPOOLSIZE]; /* Pool of randomness. */
|
|
||||||
static long magic_randcount = 0; /* Pseudo-random incrementer */
|
static long magic_randcount = 0; /* Pseudo-random incrementer */
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
|
||||||
/***********************************/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Churn the randomness pool on a random event. Call this early and often
|
* Churn the randomness pool on a random event. Call this early and often
|
||||||
* on random and semi-random system events to build randomness in time for
|
* on random and semi-random system events to build randomness in time for
|
||||||
@ -164,16 +155,16 @@ void magic_randomize(void) {
|
|||||||
*/
|
*/
|
||||||
void random_bytes(unsigned char *buf, u32_t buf_len) {
|
void random_bytes(unsigned char *buf, u32_t buf_len) {
|
||||||
md5_context md5;
|
md5_context md5;
|
||||||
u_char tmp[16];
|
u_char tmp[MD5_HASH_SIZE];
|
||||||
u32_t n;
|
u32_t n;
|
||||||
|
|
||||||
while (buf_len > 0) {
|
while (buf_len > 0) {
|
||||||
n = LWIP_MIN(buf_len, MAGIC_RANDPOOLSIZE);
|
|
||||||
md5_starts(&md5);
|
md5_starts(&md5);
|
||||||
md5_update(&md5, (u_char *)magic_randpool, sizeof(magic_randpool));
|
md5_update(&md5, (u_char *)magic_randpool, sizeof(magic_randpool));
|
||||||
md5_update(&md5, (u_char *)&magic_randcount, sizeof(magic_randcount));
|
md5_update(&md5, (u_char *)&magic_randcount, sizeof(magic_randcount));
|
||||||
md5_finish(&md5, tmp);
|
md5_finish(&md5, tmp);
|
||||||
magic_randcount++;
|
magic_randcount++;
|
||||||
|
n = LWIP_MIN(buf_len, MD5_HASH_SIZE);
|
||||||
MEMCPY(buf, tmp, n);
|
MEMCPY(buf, tmp, n);
|
||||||
buf += n;
|
buf += n;
|
||||||
buf_len -= n;
|
buf_len -= n;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user