feat: refactor core+network+protocol: use platform abstractions,

transport vtable
This commit is contained in:
2026-02-19 11:32:30 -03:00
parent 63e5ac59ce
commit b466979bc7
33 changed files with 884 additions and 624 deletions

View File

@@ -5,6 +5,7 @@
const std = @import("std");
const X25519 = std.crypto.dh.X25519;
const platform_random = @import("platform").random;
const noise = @import("noise.zig");
const Error = noise.Error;
@@ -23,10 +24,17 @@ pub const KeyPair = struct {
/// Generate a new random key pair
pub fn generate() Self {
const seed = X25519.KeyPair.generate();
var seed: [32]u8 = undefined;
platform_random.bytes(&seed);
const kp = X25519.KeyPair.generateDeterministic(seed) catch {
// Identity element is astronomically unlikely with random seed;
// regenerate if it somehow happens.
platform_random.bytes(&seed);
return generate();
};
return Self{
.private = seed.secret_key,
.public = seed.public_key,
.private = kp.secret_key,
.public = kp.public_key,
};
}