Added the random crypto module with its default implementation, implemented the Ed25519 keys generation function
This commit is contained in:
parent
1216dc2282
commit
ff60995aaa
3 changed files with 44 additions and 26 deletions
|
|
@ -3,40 +3,39 @@ pub const Implementation = struct {
|
|||
pub const KEY_SIZE = 32;
|
||||
pub const SIGNATURE_SIZE = 64;
|
||||
|
||||
generateKey: *const fn (privkey_buffer: *[KEY_SIZE]u8) void,
|
||||
generateKeys: *const fn (pubkey_buffer: []u8, privkey_buffer: []u8) void,
|
||||
sign: *const fn (key: *const [KEY_SIZE]u8, data: *const []const u8, signature_out: *const [SIGNATURE_SIZE]u8) void,
|
||||
verify: *const fn (key: *const [KEY_SIZE]u8, data: *const []const u8, signature: *const [SIGNATURE_SIZE]u8) void,
|
||||
};
|
||||
|
||||
// TODO
|
||||
pub fn defaultImplementation() type {
|
||||
pub const defaultImplementation = struct {
|
||||
|
||||
const Ed25519 = @import("std").crypto.sign.Ed25519;
|
||||
_ = Ed25519;
|
||||
|
||||
// Again, some Ed25519 functions seem to rely on the io module that is not necessarily available on embedded systems
|
||||
// It may need some custom implementation or other library
|
||||
|
||||
return struct {
|
||||
pub fn generateKeys(pubkey_buffer: []u8, privkey_buffer: []u8) !void {
|
||||
if (Ed25519.SecretKey.encoded_length > privkey_buffer or
|
||||
Ed25519.SecretKey.encoded_length > privkey_buffer)
|
||||
{
|
||||
return error.BufferTooShort;
|
||||
}
|
||||
// TODO replace by a secure random number generator
|
||||
const keypair: Ed25519.KeyPair = try Ed25519.KeyPair.generateDeterministic(undefined);
|
||||
|
||||
pub fn generateKeys(pubkey_buffer: *[32]u8, privkey_buffer: *[32]u8) !void {
|
||||
_ = pubkey_buffer;
|
||||
_ = privkey_buffer;
|
||||
return error.NotImplemented;
|
||||
@memcpy(pubkey_buffer[0..Ed25519.PublicKey.encoded_length], keypair.public_key.bytes);
|
||||
@memcpy(privkey_buffer[0..Ed25519.SecretKey.encoded_length], keypair.secret_key.bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn sign(key: *const [32]u8, data: *const []const u8, signature_out: *const [64]u8) !void {
|
||||
_ = key;
|
||||
_ = data;
|
||||
_ = signature_out;
|
||||
return error.NotImplemented;
|
||||
}
|
||||
pub fn sign(key: *const [32]u8, data: *const []const u8, signature_out: *const [64]u8) !void {
|
||||
_ = key;
|
||||
_ = data;
|
||||
_ = signature_out;
|
||||
return error.NotImplemented;
|
||||
}
|
||||
|
||||
pub fn verify(signature: *const [64]u8, data: *const []const u8) !void {
|
||||
_ = signature;
|
||||
_ = data;
|
||||
return error.NotImplemented;
|
||||
}
|
||||
};
|
||||
}
|
||||
pub fn verify(signature: *const [64]u8, data: *const []const u8) !void {
|
||||
_ = signature;
|
||||
_ = data;
|
||||
return error.NotImplemented;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue