-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrng.c
More file actions
34 lines (27 loc) · 747 Bytes
/
Copy pathrng.c
File metadata and controls
34 lines (27 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "rng.h"
#include <efilib.h>
UINT32 const BSD_MODULUS = 2147483648;
UINT32 const BSD_INCREMENT = 12345;
UINT32 const BSD_MULTIPLIER = 1103515245;
RNG make_rng(UINT32 seed) {
return (RNG) {
.modulus = 2147483648,
.increment = 12345,
.multiplier = 1103515245,
.state = seed
};
}
RNG load_rng(EFI_STATUS * status) {
// create the initial seed by using the time
EFI_TIME time;
if(EFI_ERROR((*status = RT->GetTime(&time, NULL))))
return (RNG) {};
*status = EFI_SUCCESS;
UINT32 s = (time.Hour * 60 + time.Minute * 60) + time.Second;
return make_rng(s);
}
UINT32 next_uint32(RNG * const rng) {
UINT32 r = (rng->multiplier * rng->state + rng->increment) % rng->modulus;
rng->state = r;
return r;
}