rand: Add ChaCha20-based CSPRNG, among other things

We now have RNG!

- Implement ChaCha20-based cryptographically secure random number generator (CSPRNG) in `src/drivers/rand/random.c` and its header in `src/drivers/rand/random.h`.
- Modify VFS to support directory operations, including opening directories and reading directory entries.
- Update syscall interface to include new syscalls for directory handling: `SYS_OPEN_DIR` and `SYS_READ_ENTRIES`.
- Enhance file creation in EXT2 to allow specifying file modes.
- Refactor VFS file handling to accommodate new flags and modes.
- Update user-space application in `user/include/mlibc/helloworld.c` to demonstrate file operations including `touch`, `ls`, and `cat`.
- Clean up debug print statements in EXT2 file system code.
- Worked on proper error handling and return codes across VFS and syscall implementations.

It's only a small step but we're getting closer to making error codes standardized

We also setup SSE exactly as we should've the first time we introduced it in commit 9a9b91c

We have added it correctly to the user stack trampoline (hopefully), so there shouldn't be any issues now.

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
kaguya
2026-05-03 00:46:59 -04:00
parent 9a16250a1b
commit ef14a52b49
20 changed files with 716 additions and 79 deletions
+20 -2
View File
@@ -57,6 +57,11 @@ int sys_close(int fd) {
return r >= 0 ? 0 : -r;
}
int sys_getrandom(void *buffer, size_t length, int flags) {
long r = syscall(SYS_GETRANDOM, buffer, length, flags);
return r;
}
// ─────────────────────────────────────────────────────────────────────────────
// Memory
// ─────────────────────────────────────────────────────────────────────────────
@@ -118,8 +123,7 @@ int sys_tcb_set(void *pointer) {
}
int sys_open(const char *path, int flags, unsigned int mode, int *fd) {
(void)flags; (void)mode;
long r = syscall(SYS_OPEN, (uintptr_t)path);
long r = syscall(SYS_OPEN, (uintptr_t)path, (long)flags, (long)mode);
if (r < 0) return -r;
*fd = (int)r;
return 0;
@@ -136,6 +140,20 @@ int sys_futex_wake(int *ptr) {
return (r < 0) ? -r : 0;
}
int sys_open_dir(const char *path, int *handle) {
long r = syscall(SYS_OPEN_DIR, (uintptr_t)path, (uintptr_t)handle);
return (r < 0) ? -r : 0;
}
int sys_read_entries(int handle, void *buf, size_t bufsize, size_t *out) {
long r = syscall(SYS_READ_ENTRIES, handle, (uintptr_t)buf, bufsize, (uintptr_t)out);
if (r < 0) return -r;
// Kernel already wrote the byte count into *out via the pointer.
// Do NOT overwrite it with r (which is always 0 on success).
return 0;
}
int sys_clock_get(int, time_t *, long *) { return ENOSYS; }
} // namespace mlibc