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, };