Big code refactor, get rid of HAL entirely
This commit is contained in:
13
kernel/randcrypto/physrand.S
Normal file
13
kernel/randcrypto/physrand.S
Normal file
@ -0,0 +1,13 @@
|
||||
.global randcrypto_get_physrand
|
||||
randcrypto_get_physrand:
|
||||
mov $100, %ecx
|
||||
xor %eax, %eax
|
||||
|
||||
.retry:
|
||||
rdrand %eax
|
||||
jc .done
|
||||
loop .retry
|
||||
.fail:
|
||||
mov $-1, %eax
|
||||
.done:
|
||||
ret
|
||||
8
kernel/randcrypto/physrand.h
Normal file
8
kernel/randcrypto/physrand.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef RANDCRYPTO_PHYSDRAND_H_
|
||||
#define RANDCRYPTO_PHYSDRAND_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t randcrypto_get_physrand(void);
|
||||
|
||||
#endif // RANDCRYPTO_PHYSDRAND_H_
|
||||
@ -1,5 +1,5 @@
|
||||
#include "randcrypto.h"
|
||||
#include "uniqid.h"
|
||||
#include "randcrypto/randcrypto.h"
|
||||
#include "randcrypto/uniqid.h"
|
||||
|
||||
void randcrypto_init(void) {
|
||||
randcrypto_uniqid_init();
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "uniqid.h"
|
||||
#include "atomic.h"
|
||||
#include "randcrypto/uniqid.h"
|
||||
#include "randcrypto/physrand.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "hal/hal.h"
|
||||
|
||||
static const char *base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
@ -28,7 +27,7 @@ void uniqseed(void) {
|
||||
return;
|
||||
|
||||
uint32_t seed = 0;
|
||||
int32_t r = hal_randnum();
|
||||
int32_t r = randcrypto_get_physrand();
|
||||
if (r != -1) {
|
||||
seed = (uint32_t)r;
|
||||
} else {
|
||||
@ -48,7 +47,7 @@ void randcrypto_gen_uniqid(char *out, size_t n) {
|
||||
|
||||
uniqseed();
|
||||
|
||||
int32_t r = hal_randnum();
|
||||
int32_t r = randcrypto_get_physrand();
|
||||
uint32_t extra = (r != -1) ? (uint32_t)r : uniqstate * 0x27d4eb2dU;
|
||||
|
||||
uniqstate += 0x9E3779B1u;
|
||||
|
||||
Reference in New Issue
Block a user