Commit 475ed4a6 authored by Matt Mackall's avatar Matt Mackall Committed by Linus Torvalds

[PATCH] random: whitespace cleanups

Whitespace cleanups
trailing whitespace removal
superfluous brace removal
Signed-off-by: default avatarMatt Mackall <mpm@selenic.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c078bd9e
...@@ -428,7 +428,6 @@ static void sysctl_init_random(struct entropy_store *random_state); ...@@ -428,7 +428,6 @@ static void sysctl_init_random(struct entropy_store *random_state);
static inline __u32 rotate_left(int i, __u32 word) static inline __u32 rotate_left(int i, __u32 word)
{ {
return (word << i) | (word >> (32 - i)); return (word << i) | (word >> (32 - i));
} }
#else #else
static inline __u32 rotate_left(int i, __u32 word) static inline __u32 rotate_left(int i, __u32 word)
...@@ -554,6 +553,7 @@ static void clear_entropy_store(struct entropy_store *r) ...@@ -554,6 +553,7 @@ static void clear_entropy_store(struct entropy_store *r)
r->input_rotate = 0; r->input_rotate = 0;
memset(r->pool, 0, r->poolinfo.POOLBYTES); memset(r->pool, 0, r->poolinfo.POOLBYTES);
} }
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static void free_entropy_store(struct entropy_store *r) static void free_entropy_store(struct entropy_store *r)
{ {
...@@ -576,7 +576,7 @@ static void __add_entropy_words(struct entropy_store *r, const __u32 *in, ...@@ -576,7 +576,7 @@ static void __add_entropy_words(struct entropy_store *r, const __u32 *in,
int nwords, __u32 out[16]) int nwords, __u32 out[16])
{ {
static __u32 const twist_table[8] = { static __u32 const twist_table[8] = {
0, 0x3b6e20c8, 0x76dc4190, 0x4db26158, 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158,
0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 };
unsigned long i, add_ptr, tap1, tap2, tap3, tap4, tap5; unsigned long i, add_ptr, tap1, tap2, tap3, tap4, tap5;
int new_rotate, input_rotate; int new_rotate, input_rotate;
...@@ -642,7 +642,6 @@ static inline void add_entropy_words(struct entropy_store *r, const __u32 *in, ...@@ -642,7 +642,6 @@ static inline void add_entropy_words(struct entropy_store *r, const __u32 *in,
__add_entropy_words(r, in, nwords, NULL); __add_entropy_words(r, in, nwords, NULL);
} }
/* /*
* Credit (or debit) the entropy store with n bits of entropy * Credit (or debit) the entropy store with n bits of entropy
*/ */
...@@ -726,19 +725,14 @@ static void batch_entropy_store(u32 a, u32 b, int num) ...@@ -726,19 +725,14 @@ static void batch_entropy_store(u32 a, u32 b, int num)
batch_entropy_pool[batch_head].data[1] = b; batch_entropy_pool[batch_head].data[1] = b;
batch_entropy_pool[batch_head].credit = num; batch_entropy_pool[batch_head].credit = num;
if (((batch_head - batch_tail) & (batch_max-1)) >= (batch_max / 2)) { if (((batch_head - batch_tail) & (batch_max - 1)) >= (batch_max / 2))
/*
* Schedule it for the next timer tick:
*/
schedule_delayed_work(&batch_work, 1); schedule_delayed_work(&batch_work, 1);
}
new = (batch_head+1) & (batch_max-1); new = (batch_head + 1) & (batch_max - 1);
if (new == batch_tail) { if (new == batch_tail)
DEBUG_ENT("batch entropy buffer full\n"); DEBUG_ENT("batch entropy buffer full\n");
} else { else
batch_head = new; batch_head = new;
}
spin_unlock_irqrestore(&batch_lock, flags); spin_unlock_irqrestore(&batch_lock, flags);
} }
...@@ -762,7 +756,7 @@ static void batch_entropy_process(void *private_) ...@@ -762,7 +756,7 @@ static void batch_entropy_process(void *private_)
spin_lock_irq(&batch_lock); spin_lock_irq(&batch_lock);
memcpy(batch_entropy_copy, batch_entropy_pool, memcpy(batch_entropy_copy, batch_entropy_pool,
batch_max*sizeof(struct sample)); batch_max * sizeof(struct sample));
head = batch_head; head = batch_head;
tail = batch_tail; tail = batch_tail;
...@@ -779,7 +773,7 @@ static void batch_entropy_process(void *private_) ...@@ -779,7 +773,7 @@ static void batch_entropy_process(void *private_)
} }
add_entropy_words(r, batch_entropy_copy[tail].data, 2); add_entropy_words(r, batch_entropy_copy[tail].data, 2);
credit_entropy_store(r, batch_entropy_copy[tail].credit); credit_entropy_store(r, batch_entropy_copy[tail].credit);
tail = (tail+1) & (batch_max-1); tail = (tail + 1) & (batch_max - 1);
} }
if (p->entropy_count >= random_read_wakeup_thresh) if (p->entropy_count >= random_read_wakeup_thresh)
wake_up_interruptible(&random_read_wait); wake_up_interruptible(&random_read_wait);
...@@ -821,7 +815,7 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num) ...@@ -821,7 +815,7 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
preempt_disable(); preempt_disable();
/* if over the trickle threshold, use only 1 in 4096 samples */ /* if over the trickle threshold, use only 1 in 4096 samples */
if ( random_state->entropy_count > trickle_thresh && if (random_state->entropy_count > trickle_thresh &&
(__get_cpu_var(trickle_count)++ & 0xfff)) (__get_cpu_var(trickle_count)++ & 0xfff))
goto out; goto out;
...@@ -898,7 +892,7 @@ void add_interrupt_randomness(int irq) ...@@ -898,7 +892,7 @@ void add_interrupt_randomness(int irq)
if (irq >= NR_IRQS || irq_timer_state[irq] == 0) if (irq >= NR_IRQS || irq_timer_state[irq] == 0)
return; return;
add_timer_randomness(irq_timer_state[irq], 0x100+irq); add_timer_randomness(irq_timer_state[irq], 0x100 + irq);
} }
void add_disk_randomness(struct gendisk *disk) void add_disk_randomness(struct gendisk *disk)
...@@ -906,7 +900,8 @@ void add_disk_randomness(struct gendisk *disk) ...@@ -906,7 +900,8 @@ void add_disk_randomness(struct gendisk *disk)
if (!disk || !disk->random) if (!disk || !disk->random)
return; return;
/* first major is 1, so we get >= 0x200 here */ /* first major is 1, so we get >= 0x200 here */
add_timer_randomness(disk->random, 0x100+MKDEV(disk->major, disk->first_minor)); add_timer_randomness(disk->random,
0x100 + MKDEV(disk->major, disk->first_minor));
} }
EXPORT_SYMBOL(add_disk_randomness); EXPORT_SYMBOL(add_disk_randomness);
...@@ -958,9 +953,9 @@ EXPORT_SYMBOL(add_disk_randomness); ...@@ -958,9 +953,9 @@ EXPORT_SYMBOL(add_disk_randomness);
/* The SHA f()-functions. */ /* The SHA f()-functions. */
#define f1(x,y,z) ( z ^ (x & (y^z)) ) /* Rounds 0-19: x ? y : z */ #define f1(x,y,z) (z ^ (x & (y ^ z))) /* Rounds 0-19: x ? y : z */
#define f2(x,y,z) (x ^ y ^ z) /* Rounds 20-39: XOR */ #define f2(x,y,z) (x ^ y ^ z) /* Rounds 20-39: XOR */
#define f3(x,y,z) ( (x & y) + (z & (x ^ y)) ) /* Rounds 40-59: majority */ #define f3(x,y,z) ((x & y) + (z & (x ^ y))) /* Rounds 40-59: majority */
#define f4(x,y,z) (x ^ y ^ z) /* Rounds 60-79: XOR */ #define f4(x,y,z) (x ^ y ^ z) /* Rounds 60-79: XOR */
/* The SHA Mysterious Constants */ /* The SHA Mysterious Constants */
...@@ -970,11 +965,10 @@ EXPORT_SYMBOL(add_disk_randomness); ...@@ -970,11 +965,10 @@ EXPORT_SYMBOL(add_disk_randomness);
#define K3 0x8F1BBCDCL /* Rounds 40-59: sqrt(5) * 2^30 */ #define K3 0x8F1BBCDCL /* Rounds 40-59: sqrt(5) * 2^30 */
#define K4 0xCA62C1D6L /* Rounds 60-79: sqrt(10) * 2^30 */ #define K4 0xCA62C1D6L /* Rounds 60-79: sqrt(10) * 2^30 */
#define ROTL(n,X) ( ( ( X ) << n ) | ( ( X ) >> ( 32 - n ) ) ) #define ROTL(n,X) (((X) << n ) | ((X) >> (32 - n)))
#define subRound(a, b, c, d, e, f, k, data) \ #define subRound(a, b, c, d, e, f, k, data) \
( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) ) (e += ROTL(5, a) + f(b, c, d) + k + data, b = ROTL(30, b))
static void SHATransform(__u32 digest[85], __u32 const data[16]) static void SHATransform(__u32 digest[85], __u32 const data[16])
{ {
...@@ -1042,127 +1036,127 @@ static void SHATransform(__u32 digest[85], __u32 const data[16]) ...@@ -1042,127 +1036,127 @@ static void SHATransform(__u32 digest[85], __u32 const data[16])
} }
#elif SHA_CODE_SIZE == 2 #elif SHA_CODE_SIZE == 2
for (i = 0; i < 20; i += 5) { for (i = 0; i < 20; i += 5) {
subRound( A, B, C, D, E, f1, K1, W[ i ] ); subRound(A, B, C, D, E, f1, K1, W[i ]);
subRound( E, A, B, C, D, f1, K1, W[ i+1 ] ); subRound(E, A, B, C, D, f1, K1, W[i+1]);
subRound( D, E, A, B, C, f1, K1, W[ i+2 ] ); subRound(D, E, A, B, C, f1, K1, W[i+2]);
subRound( C, D, E, A, B, f1, K1, W[ i+3 ] ); subRound(C, D, E, A, B, f1, K1, W[i+3]);
subRound( B, C, D, E, A, f1, K1, W[ i+4 ] ); subRound(B, C, D, E, A, f1, K1, W[i+4]);
} }
for (; i < 40; i += 5) { for (; i < 40; i += 5) {
subRound( A, B, C, D, E, f2, K2, W[ i ] ); subRound(A, B, C, D, E, f2, K2, W[i ]);
subRound( E, A, B, C, D, f2, K2, W[ i+1 ] ); subRound(E, A, B, C, D, f2, K2, W[i+1]);
subRound( D, E, A, B, C, f2, K2, W[ i+2 ] ); subRound(D, E, A, B, C, f2, K2, W[i+2]);
subRound( C, D, E, A, B, f2, K2, W[ i+3 ] ); subRound(C, D, E, A, B, f2, K2, W[i+3]);
subRound( B, C, D, E, A, f2, K2, W[ i+4 ] ); subRound(B, C, D, E, A, f2, K2, W[i+4]);
} }
for (; i < 60; i += 5) { for (; i < 60; i += 5) {
subRound( A, B, C, D, E, f3, K3, W[ i ] ); subRound(A, B, C, D, E, f3, K3, W[i ]);
subRound( E, A, B, C, D, f3, K3, W[ i+1 ] ); subRound(E, A, B, C, D, f3, K3, W[i+1]);
subRound( D, E, A, B, C, f3, K3, W[ i+2 ] ); subRound(D, E, A, B, C, f3, K3, W[i+2]);
subRound( C, D, E, A, B, f3, K3, W[ i+3 ] ); subRound(C, D, E, A, B, f3, K3, W[i+3]);
subRound( B, C, D, E, A, f3, K3, W[ i+4 ] ); subRound(B, C, D, E, A, f3, K3, W[i+4]);
} }
for (; i < 80; i += 5) { for (; i < 80; i += 5) {
subRound( A, B, C, D, E, f4, K4, W[ i ] ); subRound(A, B, C, D, E, f4, K4, W[i ]);
subRound( E, A, B, C, D, f4, K4, W[ i+1 ] ); subRound(E, A, B, C, D, f4, K4, W[i+1]);
subRound( D, E, A, B, C, f4, K4, W[ i+2 ] ); subRound(D, E, A, B, C, f4, K4, W[i+2]);
subRound( C, D, E, A, B, f4, K4, W[ i+3 ] ); subRound(C, D, E, A, B, f4, K4, W[i+3]);
subRound( B, C, D, E, A, f4, K4, W[ i+4 ] ); subRound(B, C, D, E, A, f4, K4, W[i+4]);
} }
#elif SHA_CODE_SIZE == 3 /* Really large version */ #elif SHA_CODE_SIZE == 3 /* Really large version */
subRound( A, B, C, D, E, f1, K1, W[ 0 ] ); subRound(A, B, C, D, E, f1, K1, W[ 0]);
subRound( E, A, B, C, D, f1, K1, W[ 1 ] ); subRound(E, A, B, C, D, f1, K1, W[ 1]);
subRound( D, E, A, B, C, f1, K1, W[ 2 ] ); subRound(D, E, A, B, C, f1, K1, W[ 2]);
subRound( C, D, E, A, B, f1, K1, W[ 3 ] ); subRound(C, D, E, A, B, f1, K1, W[ 3]);
subRound( B, C, D, E, A, f1, K1, W[ 4 ] ); subRound(B, C, D, E, A, f1, K1, W[ 4]);
subRound( A, B, C, D, E, f1, K1, W[ 5 ] ); subRound(A, B, C, D, E, f1, K1, W[ 5]);
subRound( E, A, B, C, D, f1, K1, W[ 6 ] ); subRound(E, A, B, C, D, f1, K1, W[ 6]);
subRound( D, E, A, B, C, f1, K1, W[ 7 ] ); subRound(D, E, A, B, C, f1, K1, W[ 7]);
subRound( C, D, E, A, B, f1, K1, W[ 8 ] ); subRound(C, D, E, A, B, f1, K1, W[ 8]);
subRound( B, C, D, E, A, f1, K1, W[ 9 ] ); subRound(B, C, D, E, A, f1, K1, W[ 9]);
subRound( A, B, C, D, E, f1, K1, W[ 10 ] ); subRound(A, B, C, D, E, f1, K1, W[10]);
subRound( E, A, B, C, D, f1, K1, W[ 11 ] ); subRound(E, A, B, C, D, f1, K1, W[11]);
subRound( D, E, A, B, C, f1, K1, W[ 12 ] ); subRound(D, E, A, B, C, f1, K1, W[12]);
subRound( C, D, E, A, B, f1, K1, W[ 13 ] ); subRound(C, D, E, A, B, f1, K1, W[13]);
subRound( B, C, D, E, A, f1, K1, W[ 14 ] ); subRound(B, C, D, E, A, f1, K1, W[14]);
subRound( A, B, C, D, E, f1, K1, W[ 15 ] ); subRound(A, B, C, D, E, f1, K1, W[15]);
subRound( E, A, B, C, D, f1, K1, W[ 16 ] ); subRound(E, A, B, C, D, f1, K1, W[16]);
subRound( D, E, A, B, C, f1, K1, W[ 17 ] ); subRound(D, E, A, B, C, f1, K1, W[17]);
subRound( C, D, E, A, B, f1, K1, W[ 18 ] ); subRound(C, D, E, A, B, f1, K1, W[18]);
subRound( B, C, D, E, A, f1, K1, W[ 19 ] ); subRound(B, C, D, E, A, f1, K1, W[19]);
subRound( A, B, C, D, E, f2, K2, W[ 20 ] ); subRound(A, B, C, D, E, f2, K2, W[20]);
subRound( E, A, B, C, D, f2, K2, W[ 21 ] ); subRound(E, A, B, C, D, f2, K2, W[21]);
subRound( D, E, A, B, C, f2, K2, W[ 22 ] ); subRound(D, E, A, B, C, f2, K2, W[22]);
subRound( C, D, E, A, B, f2, K2, W[ 23 ] ); subRound(C, D, E, A, B, f2, K2, W[23]);
subRound( B, C, D, E, A, f2, K2, W[ 24 ] ); subRound(B, C, D, E, A, f2, K2, W[24]);
subRound( A, B, C, D, E, f2, K2, W[ 25 ] ); subRound(A, B, C, D, E, f2, K2, W[25]);
subRound( E, A, B, C, D, f2, K2, W[ 26 ] ); subRound(E, A, B, C, D, f2, K2, W[26]);
subRound( D, E, A, B, C, f2, K2, W[ 27 ] ); subRound(D, E, A, B, C, f2, K2, W[27]);
subRound( C, D, E, A, B, f2, K2, W[ 28 ] ); subRound(C, D, E, A, B, f2, K2, W[28]);
subRound( B, C, D, E, A, f2, K2, W[ 29 ] ); subRound(B, C, D, E, A, f2, K2, W[29]);
subRound( A, B, C, D, E, f2, K2, W[ 30 ] ); subRound(A, B, C, D, E, f2, K2, W[30]);
subRound( E, A, B, C, D, f2, K2, W[ 31 ] ); subRound(E, A, B, C, D, f2, K2, W[31]);
subRound( D, E, A, B, C, f2, K2, W[ 32 ] ); subRound(D, E, A, B, C, f2, K2, W[32]);
subRound( C, D, E, A, B, f2, K2, W[ 33 ] ); subRound(C, D, E, A, B, f2, K2, W[33]);
subRound( B, C, D, E, A, f2, K2, W[ 34 ] ); subRound(B, C, D, E, A, f2, K2, W[34]);
subRound( A, B, C, D, E, f2, K2, W[ 35 ] ); subRound(A, B, C, D, E, f2, K2, W[35]);
subRound( E, A, B, C, D, f2, K2, W[ 36 ] ); subRound(E, A, B, C, D, f2, K2, W[36]);
subRound( D, E, A, B, C, f2, K2, W[ 37 ] ); subRound(D, E, A, B, C, f2, K2, W[37]);
subRound( C, D, E, A, B, f2, K2, W[ 38 ] ); subRound(C, D, E, A, B, f2, K2, W[38]);
subRound( B, C, D, E, A, f2, K2, W[ 39 ] ); subRound(B, C, D, E, A, f2, K2, W[39]);
subRound( A, B, C, D, E, f3, K3, W[ 40 ] ); subRound(A, B, C, D, E, f3, K3, W[40]);
subRound( E, A, B, C, D, f3, K3, W[ 41 ] ); subRound(E, A, B, C, D, f3, K3, W[41]);
subRound( D, E, A, B, C, f3, K3, W[ 42 ] ); subRound(D, E, A, B, C, f3, K3, W[42]);
subRound( C, D, E, A, B, f3, K3, W[ 43 ] ); subRound(C, D, E, A, B, f3, K3, W[43]);
subRound( B, C, D, E, A, f3, K3, W[ 44 ] ); subRound(B, C, D, E, A, f3, K3, W[44]);
subRound( A, B, C, D, E, f3, K3, W[ 45 ] ); subRound(A, B, C, D, E, f3, K3, W[45]);
subRound( E, A, B, C, D, f3, K3, W[ 46 ] ); subRound(E, A, B, C, D, f3, K3, W[46]);
subRound( D, E, A, B, C, f3, K3, W[ 47 ] ); subRound(D, E, A, B, C, f3, K3, W[47]);
subRound( C, D, E, A, B, f3, K3, W[ 48 ] ); subRound(C, D, E, A, B, f3, K3, W[48]);
subRound( B, C, D, E, A, f3, K3, W[ 49 ] ); subRound(B, C, D, E, A, f3, K3, W[49]);
subRound( A, B, C, D, E, f3, K3, W[ 50 ] ); subRound(A, B, C, D, E, f3, K3, W[50]);
subRound( E, A, B, C, D, f3, K3, W[ 51 ] ); subRound(E, A, B, C, D, f3, K3, W[51]);
subRound( D, E, A, B, C, f3, K3, W[ 52 ] ); subRound(D, E, A, B, C, f3, K3, W[52]);
subRound( C, D, E, A, B, f3, K3, W[ 53 ] ); subRound(C, D, E, A, B, f3, K3, W[53]);
subRound( B, C, D, E, A, f3, K3, W[ 54 ] ); subRound(B, C, D, E, A, f3, K3, W[54]);
subRound( A, B, C, D, E, f3, K3, W[ 55 ] ); subRound(A, B, C, D, E, f3, K3, W[55]);
subRound( E, A, B, C, D, f3, K3, W[ 56 ] ); subRound(E, A, B, C, D, f3, K3, W[56]);
subRound( D, E, A, B, C, f3, K3, W[ 57 ] ); subRound(D, E, A, B, C, f3, K3, W[57]);
subRound( C, D, E, A, B, f3, K3, W[ 58 ] ); subRound(C, D, E, A, B, f3, K3, W[58]);
subRound( B, C, D, E, A, f3, K3, W[ 59 ] ); subRound(B, C, D, E, A, f3, K3, W[59]);
subRound( A, B, C, D, E, f4, K4, W[ 60 ] ); subRound(A, B, C, D, E, f4, K4, W[60]);
subRound( E, A, B, C, D, f4, K4, W[ 61 ] ); subRound(E, A, B, C, D, f4, K4, W[61]);
subRound( D, E, A, B, C, f4, K4, W[ 62 ] ); subRound(D, E, A, B, C, f4, K4, W[62]);
subRound( C, D, E, A, B, f4, K4, W[ 63 ] ); subRound(C, D, E, A, B, f4, K4, W[63]);
subRound( B, C, D, E, A, f4, K4, W[ 64 ] ); subRound(B, C, D, E, A, f4, K4, W[64]);
subRound( A, B, C, D, E, f4, K4, W[ 65 ] ); subRound(A, B, C, D, E, f4, K4, W[65]);
subRound( E, A, B, C, D, f4, K4, W[ 66 ] ); subRound(E, A, B, C, D, f4, K4, W[66]);
subRound( D, E, A, B, C, f4, K4, W[ 67 ] ); subRound(D, E, A, B, C, f4, K4, W[67]);
subRound( C, D, E, A, B, f4, K4, W[ 68 ] ); subRound(C, D, E, A, B, f4, K4, W[68]);
subRound( B, C, D, E, A, f4, K4, W[ 69 ] ); subRound(B, C, D, E, A, f4, K4, W[69]);
subRound( A, B, C, D, E, f4, K4, W[ 70 ] ); subRound(A, B, C, D, E, f4, K4, W[70]);
subRound( E, A, B, C, D, f4, K4, W[ 71 ] ); subRound(E, A, B, C, D, f4, K4, W[71]);
subRound( D, E, A, B, C, f4, K4, W[ 72 ] ); subRound(D, E, A, B, C, f4, K4, W[72]);
subRound( C, D, E, A, B, f4, K4, W[ 73 ] ); subRound(C, D, E, A, B, f4, K4, W[73]);
subRound( B, C, D, E, A, f4, K4, W[ 74 ] ); subRound(B, C, D, E, A, f4, K4, W[74]);
subRound( A, B, C, D, E, f4, K4, W[ 75 ] ); subRound(A, B, C, D, E, f4, K4, W[75]);
subRound( E, A, B, C, D, f4, K4, W[ 76 ] ); subRound(E, A, B, C, D, f4, K4, W[76]);
subRound( D, E, A, B, C, f4, K4, W[ 77 ] ); subRound(D, E, A, B, C, f4, K4, W[77]);
subRound( C, D, E, A, B, f4, K4, W[ 78 ] ); subRound(C, D, E, A, B, f4, K4, W[78]);
subRound( B, C, D, E, A, f4, K4, W[ 79 ] ); subRound(B, C, D, E, A, f4, K4, W[79]);
#else #else
#error Illegal SHA_CODE_SIZE #error Illegal SHA_CODE_SIZE
#endif #endif
/* Build message digest */ /* Build message digest */
digest[ 0 ] += A; digest[0] += A;
digest[ 1 ] += B; digest[1] += B;
digest[ 2 ] += C; digest[2] += C;
digest[ 3 ] += D; digest[3] += D;
digest[ 4 ] += E; digest[4] += E;
/* W is wiped by the caller */ /* W is wiped by the caller */
#undef W #undef W
...@@ -1200,7 +1194,7 @@ static void SHATransform(__u32 digest[85], __u32 const data[16]) ...@@ -1200,7 +1194,7 @@ static void SHATransform(__u32 digest[85], __u32 const data[16])
/* This is the central step in the MD5 algorithm. */ /* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \ #define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x )
/* /*
* The core of the MD5 algorithm, this alters an existing MD5 hash to * The core of the MD5 algorithm, this alters an existing MD5 hash to
...@@ -1360,7 +1354,6 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1360,7 +1354,6 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
__u32 x; __u32 x;
unsigned long cpuflags; unsigned long cpuflags;
/* Redundant, but just in case... */ /* Redundant, but just in case... */
if (r->entropy_count > r->poolinfo.POOLBITS) if (r->entropy_count > r->poolinfo.POOLBITS)
r->entropy_count = r->poolinfo.POOLBITS; r->entropy_count = r->poolinfo.POOLBITS;
...@@ -1467,6 +1460,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1467,6 +1460,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
} }
} else } else
memcpy(buf, (__u8 const *)tmp, i); memcpy(buf, (__u8 const *)tmp, i);
nbytes -= i; nbytes -= i;
buf += i; buf += i;
ret += i; ret += i;
...@@ -2095,7 +2089,7 @@ static void sysctl_init_random(struct entropy_store *random_state) ...@@ -2095,7 +2089,7 @@ static void sysctl_init_random(struct entropy_store *random_state)
* Rotation is separate from addition to prevent recomputation * Rotation is separate from addition to prevent recomputation
*/ */
#define ROUND(f, a, b, c, d, x, s) \ #define ROUND(f, a, b, c, d, x, s) \
(a += f(b, c, d) + x, a = (a << s) | (a >> (32-s))) (a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s)))
#define K1 0 #define K1 0
#define K2 013240474631UL #define K2 013240474631UL
#define K3 015666365641UL #define K3 015666365641UL
...@@ -2203,7 +2197,7 @@ static __u32 twothirdsMD4Transform (__u32 const buf[4], __u32 const in[12]) ...@@ -2203,7 +2197,7 @@ static __u32 twothirdsMD4Transform (__u32 const buf[4], __u32 const in[12])
#undef K3 #undef K3
/* This should not be decreased so low that ISNs wrap too fast. */ /* This should not be decreased so low that ISNs wrap too fast. */
#define REKEY_INTERVAL (300*HZ) #define REKEY_INTERVAL (300 * HZ)
/* /*
* Bit layout of the tcp sequence numbers (before adding current time): * Bit layout of the tcp sequence numbers (before adding current time):
* bit 24-31: increased after every key exchange * bit 24-31: increased after every key exchange
...@@ -2224,12 +2218,12 @@ static __u32 twothirdsMD4Transform (__u32 const buf[4], __u32 const in[12]) ...@@ -2224,12 +2218,12 @@ static __u32 twothirdsMD4Transform (__u32 const buf[4], __u32 const in[12])
* *
*/ */
#define COUNT_BITS 8 #define COUNT_BITS 8
#define COUNT_MASK ( (1<<COUNT_BITS)-1) #define COUNT_MASK ((1 << COUNT_BITS) - 1)
#define HASH_BITS 24 #define HASH_BITS 24
#define HASH_MASK ( (1<<HASH_BITS)-1 ) #define HASH_MASK ((1 << HASH_BITS) - 1)
static struct keydata { static struct keydata {
__u32 count; // already shifted to the final position __u32 count; /* already shifted to the final position */
__u32 secret[12]; __u32 secret[12];
} ____cacheline_aligned ip_keydata[2]; } ____cacheline_aligned ip_keydata[2];
...@@ -2253,10 +2247,10 @@ static DECLARE_WORK(rekey_work, rekey_seq_generator, NULL); ...@@ -2253,10 +2247,10 @@ static DECLARE_WORK(rekey_work, rekey_seq_generator, NULL);
*/ */
static void rekey_seq_generator(void *private_) static void rekey_seq_generator(void *private_)
{ {
struct keydata *keyptr = &ip_keydata[1^(ip_cnt&1)]; struct keydata *keyptr = &ip_keydata[1 ^ (ip_cnt & 1)];
get_random_bytes(keyptr->secret, sizeof(keyptr->secret)); get_random_bytes(keyptr->secret, sizeof(keyptr->secret));
keyptr->count = (ip_cnt&COUNT_MASK)<<HASH_BITS; keyptr->count = (ip_cnt & COUNT_MASK) << HASH_BITS;
smp_wmb(); smp_wmb();
ip_cnt++; ip_cnt++;
schedule_delayed_work(&rekey_work, REKEY_INTERVAL); schedule_delayed_work(&rekey_work, REKEY_INTERVAL);
...@@ -2264,7 +2258,7 @@ static void rekey_seq_generator(void *private_) ...@@ -2264,7 +2258,7 @@ static void rekey_seq_generator(void *private_)
static inline struct keydata *get_keyptr(void) static inline struct keydata *get_keyptr(void)
{ {
struct keydata *keyptr = &ip_keydata[ip_cnt&1]; struct keydata *keyptr = &ip_keydata[ip_cnt & 1];
smp_rmb(); smp_rmb();
...@@ -2291,16 +2285,15 @@ __u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr, ...@@ -2291,16 +2285,15 @@ __u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr,
* Thus we must use twothirdsMD4Transform. * Thus we must use twothirdsMD4Transform.
*/ */
memcpy(hash, saddr, 16); memcpy(hash, saddr, 16);
hash[4]=(sport << 16) + dport; hash[4]=(sport << 16) + dport;
memcpy(&hash[5],keyptr->secret,sizeof(__u32)*7); memcpy(&hash[5],keyptr->secret,sizeof(__u32) * 7);
seq = twothirdsMD4Transform(daddr, hash) & HASH_MASK; seq = twothirdsMD4Transform(daddr, hash) & HASH_MASK;
seq += keyptr->count; seq += keyptr->count;
do_gettimeofday(&tv); do_gettimeofday(&tv);
seq += tv.tv_usec + tv.tv_sec*1000000; seq += tv.tv_usec + tv.tv_sec * 1000000;
return seq; return seq;
} }
...@@ -2337,7 +2330,7 @@ __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr, ...@@ -2337,7 +2330,7 @@ __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr,
* (Networks are faster now - should this be increased?) * (Networks are faster now - should this be increased?)
*/ */
do_gettimeofday(&tv); do_gettimeofday(&tv);
seq += tv.tv_usec + tv.tv_sec*1000000; seq += tv.tv_usec + tv.tv_sec * 1000000;
#if 0 #if 0
printk("init_seq(%lx, %lx, %d, %d) = %d\n", printk("init_seq(%lx, %lx, %d, %d) = %d\n",
saddr, daddr, sport, dport, seq); saddr, daddr, sport, dport, seq);
...@@ -2428,19 +2421,19 @@ __u32 secure_tcp_syn_cookie(__u32 saddr, __u32 daddr, __u16 sport, ...@@ -2428,19 +2421,19 @@ __u32 secure_tcp_syn_cookie(__u32 saddr, __u32 daddr, __u16 sport,
* MSS into the second hash value. * MSS into the second hash value.
*/ */
memcpy(tmp+3, syncookie_secret[0], sizeof(syncookie_secret[0])); memcpy(tmp + 3, syncookie_secret[0], sizeof(syncookie_secret[0]));
tmp[0]=saddr; tmp[0]=saddr;
tmp[1]=daddr; tmp[1]=daddr;
tmp[2]=(sport << 16) + dport; tmp[2]=(sport << 16) + dport;
HASH_TRANSFORM(tmp+16, tmp); HASH_TRANSFORM(tmp+16, tmp);
seq = tmp[17] + sseq + (count << COOKIEBITS); seq = tmp[17] + sseq + (count << COOKIEBITS);
memcpy(tmp+3, syncookie_secret[1], sizeof(syncookie_secret[1])); memcpy(tmp + 3, syncookie_secret[1], sizeof(syncookie_secret[1]));
tmp[0]=saddr; tmp[0]=saddr;
tmp[1]=daddr; tmp[1]=daddr;
tmp[2]=(sport << 16) + dport; tmp[2]=(sport << 16) + dport;
tmp[3] = count; /* minute counter */ tmp[3] = count; /* minute counter */
HASH_TRANSFORM(tmp+16, tmp); HASH_TRANSFORM(tmp + 16, tmp);
/* Add in the second hash and the data */ /* Add in the second hash and the data */
return seq + ((tmp[17] + data) & COOKIEMASK); return seq + ((tmp[17] + data) & COOKIEMASK);
...@@ -2465,15 +2458,15 @@ __u32 check_tcp_syn_cookie(__u32 cookie, __u32 saddr, __u32 daddr, __u16 sport, ...@@ -2465,15 +2458,15 @@ __u32 check_tcp_syn_cookie(__u32 cookie, __u32 saddr, __u32 daddr, __u16 sport,
return (__u32)-1; /* Well, duh! */ return (__u32)-1; /* Well, duh! */
/* Strip away the layers from the cookie */ /* Strip away the layers from the cookie */
memcpy(tmp+3, syncookie_secret[0], sizeof(syncookie_secret[0])); memcpy(tmp + 3, syncookie_secret[0], sizeof(syncookie_secret[0]));
tmp[0]=saddr; tmp[0]=saddr;
tmp[1]=daddr; tmp[1]=daddr;
tmp[2]=(sport << 16) + dport; tmp[2]=(sport << 16) + dport;
HASH_TRANSFORM(tmp+16, tmp); HASH_TRANSFORM(tmp + 16, tmp);
cookie -= tmp[17] + sseq; cookie -= tmp[17] + sseq;
/* Cookie is now reduced to (count * 2^24) ^ (hash % 2^24) */ /* Cookie is now reduced to (count * 2^24) ^ (hash % 2^24) */
diff = (count - (cookie >> COOKIEBITS)) & ((__u32)-1 >> COOKIEBITS); diff = (count - (cookie >> COOKIEBITS)) & ((__u32) - 1 >> COOKIEBITS);
if (diff >= maxdiff) if (diff >= maxdiff)
return (__u32)-1; return (__u32)-1;
...@@ -2482,7 +2475,7 @@ __u32 check_tcp_syn_cookie(__u32 cookie, __u32 saddr, __u32 daddr, __u16 sport, ...@@ -2482,7 +2475,7 @@ __u32 check_tcp_syn_cookie(__u32 cookie, __u32 saddr, __u32 daddr, __u16 sport,
tmp[1] = daddr; tmp[1] = daddr;
tmp[2] = (sport << 16) + dport; tmp[2] = (sport << 16) + dport;
tmp[3] = count - diff; /* minute counter */ tmp[3] = count - diff; /* minute counter */
HASH_TRANSFORM(tmp+16, tmp); HASH_TRANSFORM(tmp + 16, tmp);
return (cookie - tmp[17]) & COOKIEMASK; /* Leaving the data behind */ return (cookie - tmp[17]) & COOKIEMASK; /* Leaving the data behind */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment