Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

---

- Roadmap/Features: [here!](docs/ROADMAP.md)
- How it works: [here!](docs/ARCHITECTURE.md)
- Development Guide: [here!](docs/DEVELOPMENT.md)

Expand Down Expand Up @@ -60,7 +59,7 @@ cd VoidFrame
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/<linux/windows/macos>-x64.cmake \
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/linux-x64.cmake \
-G Ninja \
-DVF_SCHEDULER=<MLFQ/EEVDF>
ccmake . # Optinal, tune as needed
Expand Down Expand Up @@ -138,6 +137,12 @@ ninja run
- [x] Create
- [x] Delete
- [x] List
- DEVFS
- [x] Read
- [x] Write
- [x] Create (register)
- [ ] Delete (unregister)
- [x] List
- ISO9660 (RO)
- [x] Read
- [x] List
Expand All @@ -146,6 +151,7 @@ ninja run
- [x] EXT2
- [x] FAT1x
- [x] VFRFS
- [ ] DEVFS
- [ ] ISO9660
### Drivers
- Network
Expand Down
11 changes: 11 additions & 0 deletions cmake/source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ set(FS_SOURCES
fs/FileSystem.c
fs/MBR.c
fs/DriveNaming.c
fs/CharDevice.c
fs/devfs/DevFS.c
)

set(DRIVER_SOURCES
Expand Down Expand Up @@ -122,6 +124,12 @@ set(INCLUDE_SOURCES
include/Io.c
)

set(CRYPTO_SOURCES
crypto/RNG.c
crypto/CRC32.c
crypto/SHA256.c
)

set(CPP_SOURCES
ports/6502/6502.cpp
)
Expand Down Expand Up @@ -165,6 +173,7 @@ include_directories(
fs/FAT
fs/EXT
fs/NTFS
fs/devfs
mm
mm/dynamic
mm/dynamic/c
Expand All @@ -181,6 +190,7 @@ include_directories(
arch/x86_64/syscall
vfcompositor
vfcompositor/app
crypto
)

# ============================================================================
Expand Down Expand Up @@ -209,4 +219,5 @@ set(C_SOURCES
${ARCH_SOURCES}
${INCLUDE_SOURCES}
${VFC_SOURCES}
${CRYPTO_SOURCES}
)
35 changes: 35 additions & 0 deletions crypto/CRC32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "CRC32.h"

static uint32_t crc32_table[256];

void CRC32Init() {
uint32_t polynomial = 0xEDB88320;
for (uint32_t i = 0; i < 256; i++) {
uint32_t c = i;
for (size_t j = 0; j < 8; j++) {
if (c & 1) {
c = polynomial ^ (c >> 1);
} else {
c >>= 1;
}
}
crc32_table[i] = c;
}
}

uint32_t CRC32(const void* data, size_t length) {
static int table_generated = 0;
if (!table_generated) {
CRC32Init();
table_generated = 1;
}

uint32_t crc = 0xFFFFFFFF;
const uint8_t* p = (const uint8_t*)data;

for (size_t i = 0; i < length; i++) {
crc = crc32_table[(crc ^ p[i]) & 0xFF] ^ (crc >> 8);
}

return crc ^ 0xFFFFFFFF;
}
10 changes: 10 additions & 0 deletions crypto/CRC32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef VOIDFRAME_CRC32_H
#define VOIDFRAME_CRC32_H

#include <stdint.h>
#include <stddef.h>

uint32_t CRC32(const void* data, size_t length);
void CRC32Init();

#endif //VOIDFRAME_CRC32_H
57 changes: 57 additions & 0 deletions crypto/RNG.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "RNG.h"
#include "Io.h"

static uint64_t s[2]; // state

static inline uint64_t rotl(const uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}

uint64_t xoroshiro128plus(void) {
uint64_t s0 = s[0];
uint64_t s1 = s[1];
uint64_t result = s0 + s1;
s1 ^= s0;
s[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14);
s[1] = rotl(s1, 36);
return result;
}

static uint64_t splitmix64(uint64_t* x) {
*x += 0x9e3779b97f4a7c15ULL;
uint64_t z = *x;
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
return z ^ (z >> 31);
}

void rng_seed(uint64_t seed_lo, uint64_t seed_hi) {
uint64_t seed = seed_lo ^ (seed_hi + 0x9e3779b97f4a7c15ULL);
s[0] ^= splitmix64(&seed);
s[1] ^= splitmix64(&seed);
if ((s[0] | s[1]) == 0) s[0] = 0x8a5cd789635d2dffULL; // ensure non-zero state
}

int rdrand_supported(void) {
uint32_t eax, ebx, ecx, edx;
cpuid(1, &eax, &ebx, &ecx, &edx);
return (ecx & (1u << 30)) != 0;
}

uint16_t rdrand16(void) {
uint16_t r;
__asm__ volatile("rdrand %0" : "=r"(r));
return r;
}

uint32_t rdrand32(void) {
uint32_t r;
__asm__ volatile("rdrand %0" : "=r"(r));
return r;
}

uint64_t rdrand64(void) {
uint64_t r;
__asm__ volatile("rdrand %0" : "=r"(r));
return r;
}
14 changes: 14 additions & 0 deletions crypto/RNG.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef VOIDFRAME_RNG_H
#define VOIDFRAME_RNG_H
#include "stdint.h"

void rng_seed(uint64_t a, uint64_t b);
uint64_t xoroshiro128plus();

int rdrand_supported(void);

uint16_t rdrand16(void);
uint32_t rdrand32(void);
uint64_t rdrand64(void);

#endif //VOIDFRAME_RNG_H
124 changes: 124 additions & 0 deletions crypto/SHA256.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

#include "SHA256.h"
#include "MemOps.h"

#define ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#define CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define EP0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
#define EP1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
#define SIG0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ ((x) >> 3))
#define SIG1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ ((x) >> 10))

static const uint32_t k[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};

static void SHA256Transform(SHA256_CTX *ctx, const uint8_t data[]) {
uint32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];

for (i = 0, j = 0; i < 16; ++i, j += 4)
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);

for (; i < 64; ++i)
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];

a = ctx->state[0];
b = ctx->state[1];
c = ctx->state[2];
d = ctx->state[3];
e = ctx->state[4];
f = ctx->state[5];
g = ctx->state[6];
h = ctx->state[7];

for (i = 0; i < 64; ++i) {
t1 = h + EP1(e) + CH(e, f, g) + k[i] + m[i];
t2 = EP0(a) + MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
}

ctx->state[0] += a;
ctx->state[1] += b;
ctx->state[2] += c;
ctx->state[3] += d;
ctx->state[4] += e;
ctx->state[5] += f;
ctx->state[6] += g;
ctx->state[7] += h;
}

void SHA256Init(SHA256_CTX *ctx) {
ctx->datalen = 0;
ctx->bitlen = 0;
ctx->state[0] = 0x6a09e667;
ctx->state[1] = 0xbb67ae85;
ctx->state[2] = 0x3c6ef372;
ctx->state[3] = 0xa54ff53a;
ctx->state[4] = 0x510e527f;
ctx->state[5] = 0x9b05688c;
ctx->state[6] = 0x1f83d9ab;
ctx->state[7] = 0x5be0cd19;
}

void SHA256Update(SHA256_CTX *ctx, const uint8_t data[], size_t len) {
for (size_t i = 0; i < len; ++i) {
ctx->data[ctx->datalen] = data[i];
ctx->datalen++;
if (ctx->datalen == 64) {
SHA256Transform(ctx, ctx->data);
ctx->bitlen += 512;
ctx->datalen = 0;
}
}
}

void SHA256Final(SHA256_CTX *ctx, uint8_t hash[]) {
uint32_t i = ctx->datalen;

ctx->data[i++] = 0x80;

if (ctx->datalen < 56) {
FastMemset(ctx->data + i, 0, 56 - i);
} else {
FastMemset(ctx->data + i, 0, 64 - i);
SHA256Transform(ctx, ctx->data);
FastMemset(ctx->data, 0, 56);
}

ctx->bitlen += ctx->datalen * 8;
ctx->data[63] = ctx->bitlen;
ctx->data[62] = ctx->bitlen >> 8;
ctx->data[61] = ctx->bitlen >> 16;
ctx->data[60] = ctx->bitlen >> 24;
ctx->data[59] = ctx->bitlen >> 32;
ctx->data[58] = ctx->bitlen >> 40;
ctx->data[57] = ctx->bitlen >> 48;
ctx->data[56] = ctx->bitlen >> 56;
SHA256Transform(ctx, ctx->data);

for (i = 0; i < 4; ++i) {
hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0xff;
hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0xff;
hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0xff;
hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0xff;
hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0xff;
hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0xff;
hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0xff;
hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0xff;
}
}
20 changes: 20 additions & 0 deletions crypto/SHA256.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef VOIDFRAME_SHA256_H
#define VOIDFRAME_SHA256_H

#include <stdint.h>
#include <stddef.h>

#define SHA256_BLOCK_SIZE 32

typedef struct {
uint8_t data[64];
uint32_t datalen;
uint64_t bitlen;
uint32_t state[8];
} SHA256_CTX;

void sha256_init(SHA256_CTX *ctx);
void SHA256Update(SHA256_CTX *ctx, const uint8_t data[], size_t len);
void SHA256Final(SHA256_CTX *ctx, uint8_t hash[]);

#endif //VOIDFRAME_SHA256_H
10 changes: 0 additions & 10 deletions docs/ROADMAP.md

This file was deleted.

Loading