This repository was archived by the owner on Jan 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Development #167
Merged
Merged
Development #167
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endif //VOIDFRAME_CRC32_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static inline uint64_t rotl(const uint64_t x, int k) { | ||
| return (x << k) | (x >> (64 - k)); | ||
| } | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
| } | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void rng_seed(uint64_t a, uint64_t b); | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uint64_t xoroshiro128plus(); | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| int rdrand_supported(void); | ||
|
|
||
| uint16_t rdrand16(void); | ||
| uint32_t rdrand32(void); | ||
| uint64_t rdrand64(void); | ||
|
|
||
| #endif //VOIDFRAME_RNG_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| typedef struct { | ||
| uint8_t data[64]; | ||
| uint32_t datalen; | ||
| uint64_t bitlen; | ||
| uint32_t state[8]; | ||
| } SHA256_CTX; | ||
|
|
||
| void sha256_init(SHA256_CTX *ctx); | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void SHA256Update(SHA256_CTX *ctx, const uint8_t data[], size_t len); | ||
| void SHA256Final(SHA256_CTX *ctx, uint8_t hash[]); | ||
|
|
||
| #endif //VOIDFRAME_SHA256_H | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.