Began Identity implementation and testing
This commit is contained in:
parent
547a515952
commit
3209ae87a1
1 changed files with 52 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
///////////////// Imports
|
///////////////// Imports
|
||||||
//
|
//
|
||||||
|
|
||||||
const CryptoEngine = @import("crypto.zig").Engine;
|
const Crypto = @import("crypto.zig");
|
||||||
|
|
||||||
///////////////// Constants
|
///////////////// Constants
|
||||||
//
|
//
|
||||||
|
|
@ -13,25 +13,25 @@ const CryptoEngine = @import("crypto.zig").Engine;
|
||||||
//
|
//
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
pub fn Identity(comptime crypto_engine: CryptoEngine) type {
|
pub fn resolveIdentity(comptime crypto_engine: Crypto.Engine) type {
|
||||||
_ = crypto_engine;
|
|
||||||
|
|
||||||
return struct {
|
return struct {
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
//////// Fields
|
//////// Fields
|
||||||
//
|
//
|
||||||
publicKey: []const u8,
|
privKey: [Crypto.Ed25519.secret_key_length]u8,
|
||||||
privateKey: []const u8,
|
signatureKey: [Crypto.X25519.secret_key_size]u8,
|
||||||
signature: []const u8,
|
|
||||||
hash: []const u8,
|
hash: []const u8,
|
||||||
|
|
||||||
//////// Functions
|
//////// Functions
|
||||||
//
|
//
|
||||||
pub fn generate() !Identity {
|
pub fn generate() !Self {
|
||||||
return .{
|
const result: Self = undefined;
|
||||||
// .privateKey = crypto_engine.ed25519.generateKey(...),
|
crypto_engine.ed25519.generateKeys(null, &result.signatureKey, crypto_engine.random);
|
||||||
// .signature = crypto_engine.x25519.
|
// TODO privKey and signature
|
||||||
};
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -46,3 +46,44 @@ pub fn Identity(comptime crypto_engine: CryptoEngine) type {
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const expect = std.testing.expect;
|
const expect = std.testing.expect;
|
||||||
|
const memeql = std.mem.eql;
|
||||||
|
|
||||||
|
const testPattern: u8 = 0b10101010;
|
||||||
|
const pubkey_size = Crypto.Ed25519.public_key_length;
|
||||||
|
const privkey_size = Crypto.Ed25519.secret_key_length;
|
||||||
|
|
||||||
|
// Fills out with alternating 0s and 1s
|
||||||
|
fn fillPattern(out: []u8) void {
|
||||||
|
for(out) |*byte| {
|
||||||
|
byte.* = testPattern;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generateFakeKeys(pubkey_buffer: *[pubkey_size]u8, privkey_buffer: *[privkey_size]u8, rng: Crypto.Random.Implementation) Crypto.CryptoError!void {
|
||||||
|
_ = rng;
|
||||||
|
fillPattern(pubkey_buffer);
|
||||||
|
fillPattern(privkey_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Basic identity generation" {
|
||||||
|
|
||||||
|
const fake_rng: Crypto.Random.Implementation = .{
|
||||||
|
.generate = fillPattern,
|
||||||
|
};
|
||||||
|
const fake_ed25519: Crypto.Ed25519.Implementation = .{
|
||||||
|
.generateKeys = generateFakeKeys,
|
||||||
|
};
|
||||||
|
const crypto_engine = Crypto.resolveEngine(.{
|
||||||
|
.random = fake_rng,
|
||||||
|
.ed25519 = fake_ed25519,
|
||||||
|
});
|
||||||
|
|
||||||
|
const Identity = resolveIdentity(crypto_engine);
|
||||||
|
const new_id: Identity = try Identity.generate();
|
||||||
|
|
||||||
|
|
||||||
|
try expect(memeql(u8, new_id.privKey, testPattern));
|
||||||
|
try expect(memeql(u8, new_id.signatureKey, testPattern));
|
||||||
|
// try expect(memeql(u8, new_id.hash, testPattern));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue