feat: refactor core+network+protocol: use platform abstractions,
transport vtable
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user