random testing

This commit is contained in:
David Allemang
2024-03-04 17:28:29 -05:00
parent 7cd5f61256
commit 12ab3391e8

View File

@@ -36,15 +36,25 @@ const Peer = struct {
return self; return self;
} }
pub fn encrypt(ally: std.mem.Allocator, msg: []const u8) !Packet { /// Caller must free result
pub fn encrypt(self: Self, ally: std.mem.Allocator, msg: []const u8) !Packet {
var pkt: Packet = undefined; var pkt: Packet = undefined;
std.crypto.random.bytes(&pkt.nonce); std.crypto.random.bytes(&pkt.nonce);
pkt.cipher_text = try ally.alloc(u8, msg.len);
AES.encrypt(pkt.cipher_text, &pkt.tag, msg, "", pkt.nonce, self.shared_key);
return pkt;
}
/// Caller must free result
pub fn decrypt(self: Self, ally: std.mem.Allocator, msg: []const u8) ![]const u8 {
} }
}; };
const Packet = struct { const Packet = struct {
ally: std.mem.Allocator, ally: std.mem.Allocator,
nonce: [AES.tag_length]u8, nonce: [AES.nonce_length]u8,
tag: [AES.tag_length]u8,
cipher_text: []u8, cipher_text: []u8,
}; };