@@ -430,14 +430,20 @@ static int random_write_wakeup_bits = 28 * OUTPUT_POOL_WORDS;
430
430
* polynomial which improves the resulting TGFSR polynomial to be
431
431
* irreducible, which we have made here.
432
432
*/
433
- static const struct poolinfo {
434
- int poolbitshift , poolwords , poolbytes , poolfracbits ;
435
- #define S (x ) ilog2(x)+5, (x), (x)*4, (x) << (ENTROPY_SHIFT+5)
436
- int tap1 , tap2 , tap3 , tap4 , tap5 ;
437
- } poolinfo_table [] = {
438
- /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
433
+ enum poolinfo {
434
+ POOL_WORDS = 128 ,
435
+ POOL_WORDMASK = POOL_WORDS - 1 ,
436
+ POOL_BYTES = POOL_WORDS * sizeof (u32 ),
437
+ POOL_BITS = POOL_BYTES * 8 ,
438
+ POOL_BITSHIFT = ilog2 (POOL_WORDS ) + 5 ,
439
+ POOL_FRACBITS = POOL_WORDS << (ENTROPY_SHIFT + 5 ),
440
+
439
441
/* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
440
- { S (128 ), 104 , 76 , 51 , 25 , 1 },
442
+ POOL_TAP1 = 104 ,
443
+ POOL_TAP2 = 76 ,
444
+ POOL_TAP3 = 51 ,
445
+ POOL_TAP4 = 25 ,
446
+ POOL_TAP5 = 1
441
447
};
442
448
443
449
/*
@@ -503,7 +509,6 @@ MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression");
503
509
struct entropy_store ;
504
510
struct entropy_store {
505
511
/* read-only data: */
506
- const struct poolinfo * poolinfo ;
507
512
__u32 * pool ;
508
513
const char * name ;
509
514
@@ -525,7 +530,6 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r);
525
530
static __u32 input_pool_data [INPUT_POOL_WORDS ] __latent_entropy ;
526
531
527
532
static struct entropy_store input_pool = {
528
- .poolinfo = & poolinfo_table [0 ],
529
533
.name = "input" ,
530
534
.lock = __SPIN_LOCK_UNLOCKED (input_pool .lock ),
531
535
.pool = input_pool_data
@@ -548,33 +552,26 @@ static __u32 const twist_table[8] = {
548
552
static void _mix_pool_bytes (struct entropy_store * r , const void * in ,
549
553
int nbytes )
550
554
{
551
- unsigned long i , tap1 , tap2 , tap3 , tap4 , tap5 ;
555
+ unsigned long i ;
552
556
int input_rotate ;
553
- int wordmask = r -> poolinfo -> poolwords - 1 ;
554
557
const unsigned char * bytes = in ;
555
558
__u32 w ;
556
559
557
- tap1 = r -> poolinfo -> tap1 ;
558
- tap2 = r -> poolinfo -> tap2 ;
559
- tap3 = r -> poolinfo -> tap3 ;
560
- tap4 = r -> poolinfo -> tap4 ;
561
- tap5 = r -> poolinfo -> tap5 ;
562
-
563
560
input_rotate = r -> input_rotate ;
564
561
i = r -> add_ptr ;
565
562
566
563
/* mix one byte at a time to simplify size handling and churn faster */
567
564
while (nbytes -- ) {
568
565
w = rol32 (* bytes ++ , input_rotate );
569
- i = (i - 1 ) & wordmask ;
566
+ i = (i - 1 ) & POOL_WORDMASK ;
570
567
571
568
/* XOR in the various taps */
572
569
w ^= r -> pool [i ];
573
- w ^= r -> pool [(i + tap1 ) & wordmask ];
574
- w ^= r -> pool [(i + tap2 ) & wordmask ];
575
- w ^= r -> pool [(i + tap3 ) & wordmask ];
576
- w ^= r -> pool [(i + tap4 ) & wordmask ];
577
- w ^= r -> pool [(i + tap5 ) & wordmask ];
570
+ w ^= r -> pool [(i + POOL_TAP1 ) & POOL_WORDMASK ];
571
+ w ^= r -> pool [(i + POOL_TAP2 ) & POOL_WORDMASK ];
572
+ w ^= r -> pool [(i + POOL_TAP3 ) & POOL_WORDMASK ];
573
+ w ^= r -> pool [(i + POOL_TAP4 ) & POOL_WORDMASK ];
574
+ w ^= r -> pool [(i + POOL_TAP5 ) & POOL_WORDMASK ];
578
575
579
576
/* Mix the result back in with a twist */
580
577
r -> pool [i ] = (w >> 3 ) ^ twist_table [w & 7 ];
@@ -672,7 +669,6 @@ static void process_random_ready_list(void)
672
669
static void credit_entropy_bits (struct entropy_store * r , int nbits )
673
670
{
674
671
int entropy_count , orig ;
675
- const int pool_size = r -> poolinfo -> poolfracbits ;
676
672
int nfrac = nbits << ENTROPY_SHIFT ;
677
673
678
674
if (!nbits )
@@ -706,25 +702,25 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
706
702
* turns no matter how large nbits is.
707
703
*/
708
704
int pnfrac = nfrac ;
709
- const int s = r -> poolinfo -> poolbitshift + ENTROPY_SHIFT + 2 ;
705
+ const int s = POOL_BITSHIFT + ENTROPY_SHIFT + 2 ;
710
706
/* The +2 corresponds to the /4 in the denominator */
711
707
712
708
do {
713
- unsigned int anfrac = min (pnfrac , pool_size /2 );
709
+ unsigned int anfrac = min (pnfrac , POOL_FRACBITS /2 );
714
710
unsigned int add =
715
- ((pool_size - entropy_count )* anfrac * 3 ) >> s ;
711
+ ((POOL_FRACBITS - entropy_count )* anfrac * 3 ) >> s ;
716
712
717
713
entropy_count += add ;
718
714
pnfrac -= anfrac ;
719
- } while (unlikely (entropy_count < pool_size - 2 && pnfrac ));
715
+ } while (unlikely (entropy_count < POOL_FRACBITS - 2 && pnfrac ));
720
716
}
721
717
722
718
if (WARN_ON (entropy_count < 0 )) {
723
719
pr_warn ("negative entropy/overflow: pool %s count %d\n" ,
724
720
r -> name , entropy_count );
725
721
entropy_count = 0 ;
726
- } else if (entropy_count > pool_size )
727
- entropy_count = pool_size ;
722
+ } else if (entropy_count > POOL_FRACBITS )
723
+ entropy_count = POOL_FRACBITS ;
728
724
if (cmpxchg (& r -> entropy_count , orig , entropy_count ) != orig )
729
725
goto retry ;
730
726
@@ -741,13 +737,11 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
741
737
742
738
static int credit_entropy_bits_safe (struct entropy_store * r , int nbits )
743
739
{
744
- const int nbits_max = r -> poolinfo -> poolwords * 32 ;
745
-
746
740
if (nbits < 0 )
747
741
return - EINVAL ;
748
742
749
743
/* Cap the value to avoid overflows */
750
- nbits = min (nbits , nbits_max );
744
+ nbits = min (nbits , POOL_BITS );
751
745
752
746
credit_entropy_bits (r , nbits );
753
747
return 0 ;
@@ -1343,7 +1337,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
1343
1337
int entropy_count , orig , have_bytes ;
1344
1338
size_t ibytes , nfrac ;
1345
1339
1346
- BUG_ON (r -> entropy_count > r -> poolinfo -> poolfracbits );
1340
+ BUG_ON (r -> entropy_count > POOL_FRACBITS );
1347
1341
1348
1342
/* Can we pull enough? */
1349
1343
retry :
@@ -1409,8 +1403,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
1409
1403
1410
1404
/* Generate a hash across the pool */
1411
1405
spin_lock_irqsave (& r -> lock , flags );
1412
- blake2s_update (& state , (const u8 * )r -> pool ,
1413
- r -> poolinfo -> poolwords * sizeof (* r -> pool ));
1406
+ blake2s_update (& state , (const u8 * )r -> pool , POOL_BYTES );
1414
1407
blake2s_final (& state , hash ); /* final zeros out state */
1415
1408
1416
1409
/*
@@ -1766,7 +1759,7 @@ static void __init init_std_data(struct entropy_store *r)
1766
1759
unsigned long rv ;
1767
1760
1768
1761
mix_pool_bytes (r , & now , sizeof (now ));
1769
- for (i = r -> poolinfo -> poolbytes ; i > 0 ; i -= sizeof (rv )) {
1762
+ for (i = POOL_BYTES ; i > 0 ; i -= sizeof (rv )) {
1770
1763
if (!arch_get_random_seed_long (& rv ) &&
1771
1764
!arch_get_random_long (& rv ))
1772
1765
rv = random_get_entropy ();
0 commit comments