From 12ab3391e81fe6f904ecef76ad4514fbecbd89b0 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Mon, 4 Mar 2024 17:28:29 -0500 Subject: [PATCH] random testing --- src/main.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 79969c6..f943360 100644 --- a/src/main.zig +++ b/src/main.zig @@ -36,15 +36,25 @@ const Peer = struct { 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; 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 { ally: std.mem.Allocator, - nonce: [AES.tag_length]u8, + nonce: [AES.nonce_length]u8, + tag: [AES.tag_length]u8, cipher_text: []u8, };