GitHub

Original file line numberDiff line numberDiff line change

@@ -904,7 +904,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out)

904904

int i;

905905

union {

906906

__u32 w[5];

907-

unsigned long l[LONGS(EXTRACT_SIZE)];

907+

unsigned long l[LONGS(20)];

908908

} hash;

909909

__u32 workspace[SHA_WORKSPACE_WORDS];

910910

__u8 extract[64];

@@ -916,6 +916,17 @@ static void extract_buf(struct entropy_store *r, __u8 *out)

916916

for (i = 0; i < r->poolinfo->poolwords; i += 16)

917917

sha_transform(hash.w, (__u8 *)(r->pool + i), workspace);

918918
919+

/*

920+

* If we have a architectural hardware random number

921+

* generator, mix that in, too.

922+

*/

923+

for (i = 0; i < LONGS(20); i++) {

924+

unsigned long v;

925+

if (!arch_get_random_long(&v))

926+

break;

927+

hash.l[i] ^= v;

928+

}

929+
919930

/*

920931

* We mix the hash back into the pool to prevent backtracking

921932

* attacks (where the attacker knows the state of the pool

@@ -945,17 +956,6 @@ static void extract_buf(struct entropy_store *r, __u8 *out)

945956

hash.w[1] ^= hash.w[4];

946957

hash.w[2] ^= rol32(hash.w[2], 16);

947958
948-

/*

949-

* If we have a architectural hardware random number

950-

* generator, mix that in, too.

951-

*/

952-

for (i = 0; i < LONGS(EXTRACT_SIZE); i++) {

953-

unsigned long v;

954-

if (!arch_get_random_long(&v))

955-

break;

956-

hash.l[i] ^= v;

957-

}

958-
959959

memcpy(out, &hash, EXTRACT_SIZE);

960960

memset(&hash, 0, sizeof(hash));

961961

}

Read the original on github.com ↗