Big code refactor, get rid of HAL entirely

This commit is contained in:
2025-11-11 21:26:27 +01:00
parent 7015bc9576
commit 566b35f4d5
84 changed files with 477 additions and 520 deletions

View 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

View 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_

View File

@ -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();

View File

@ -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;