Minor changes: coding style (tabs, ident, etc...).

This commit is contained in:
fbernon 2007-12-02 23:38:45 +00:00
parent e4590b26fb
commit 2fe1254aae
2 changed files with 89 additions and 84 deletions

View File

@ -63,7 +63,8 @@ static long randCount = 0; /* Pseudo-random incrementer */
* real-time clock. We'll accumulate more randomness as soon * real-time clock. We'll accumulate more randomness as soon
* as things start happening. * as things start happening.
*/ */
void avRandomInit() void
avRandomInit()
{ {
avChurnRand(NULL, 0); avChurnRand(NULL, 0);
} }
@ -78,23 +79,23 @@ void avRandomInit()
* *
* Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427 * Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427
*/ */
void avChurnRand(char *randData, u32_t randLen) void
avChurnRand(char *randData, u32_t randLen)
{ {
MD5_CTX md5; MD5_CTX md5;
/* ppp_trace(LOG_INFO, "churnRand: %u@%P\n", randLen, randData); */ /* ppp_trace(LOG_INFO, "churnRand: %u@%P\n", randLen, randData); */
MD5Init(&md5); MD5Init(&md5);
MD5Update(&md5, (u_char *)randPool, sizeof(randPool)); MD5Update(&md5, (u_char *)randPool, sizeof(randPool));
if (randData) if (randData) {
MD5Update(&md5, (u_char *)randData, randLen); MD5Update(&md5, (u_char *)randData, randLen);
else { } else {
struct { struct {
/* INCLUDE fields for any system sources of randomness */ /* INCLUDE fields for any system sources of randomness */
char foobar; char foobar;
} sysData; } sysData;
/* Load sysData fields here. */ /* Load sysData fields here. */
;
MD5Update(&md5, (u_char *)&sysData, sizeof(sysData)); MD5Update(&md5, (u_char *)&sysData, sizeof(sysData));
} }
MD5Final((u_char *)randPool, &md5); MD5Final((u_char *)randPool, &md5);
@ -117,7 +118,8 @@ void avChurnRand(char *randData, u32_t randLen)
* randCount each time? Probably there is a weakness but I wish that * randCount each time? Probably there is a weakness but I wish that
* it was documented. * it was documented.
*/ */
void avGenRand(char *buf, u32_t bufLen) void
avGenRand(char *buf, u32_t bufLen)
{ {
MD5_CTX md5; MD5_CTX md5;
u_char tmp[16]; u_char tmp[16];
@ -139,7 +141,8 @@ void avGenRand(char *buf, u32_t bufLen)
/* /*
* Return a new random number. * Return a new random number.
*/ */
u32_t avRandom() u32_t
avRandom()
{ {
u32_t newRand; u32_t newRand;
@ -150,7 +153,6 @@ u32_t avRandom()
#else /* MD5_SUPPORT */ #else /* MD5_SUPPORT */
/*****************************/ /*****************************/
/*** LOCAL DATA STRUCTURES ***/ /*** LOCAL DATA STRUCTURES ***/
/*****************************/ /*****************************/
@ -175,7 +177,8 @@ static u32_t avRandomSeed = 0; /* Seed used for random number generation. *
* operational. Thus we call it again on the first random * operational. Thus we call it again on the first random
* event. * event.
*/ */
void avRandomInit() void
avRandomInit()
{ {
#if 0 #if 0
/* Get a pointer into the last 4 bytes of clockBuf. */ /* Get a pointer into the last 4 bytes of clockBuf. */
@ -209,7 +212,8 @@ void avRandomInit()
* value but we use the previous value to randomize the other 16 * value but we use the previous value to randomize the other 16
* bits. * bits.
*/ */
void avRandomize(void) void
avRandomize(void)
{ {
static u32_t last_jiffies; static u32_t last_jiffies;
@ -218,7 +222,7 @@ void avRandomize(void)
avRandomInit(); avRandomInit();
/* The initialization function also updates the seed. */ /* The initialization function also updates the seed. */
} else { } else {
/* avRandomSeed += (avRandomSeed << 16) + TM1; */ /* avRandomSeed += (avRandomSeed << 16) + TM1; */
avRandomSeed += (sys_jiffies() - last_jiffies); /* XXX */ avRandomSeed += (sys_jiffies() - last_jiffies); /* XXX */
} }
last_jiffies = sys_jiffies(); last_jiffies = sys_jiffies();
@ -233,7 +237,8 @@ void avRandomize(void)
* operator or network events in which case it will be pseudo random * operator or network events in which case it will be pseudo random
* seeded by the real time clock. * seeded by the real time clock.
*/ */
u32_t avRandom() u32_t
avRandom()
{ {
return ((((u32_t)rand() << 16) + rand()) + avRandomSeed); return ((((u32_t)rand() << 16) + rand()) + avRandomSeed);
} }