Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/ciphersuites.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const std = @import("std");
const mem = std.mem;

usingnamespace @import("crypto.zig");
const crypto = @import("crypto.zig");
const ChaCha20Stream = crypto.ChaCha20Stream;
const Chacha20Poly1305 = std.crypto.aead.chacha_poly.ChaCha20Poly1305;
const Poly1305 = std.crypto.onetimeauth.Poly1305;
const Aes128Gcm = std.crypto.aead.aes_gcm.Aes128Gcm;
Expand Down Expand Up @@ -49,7 +50,7 @@ pub const suites = struct {
c[1] = mem.readIntLittle(u32, nonce[0..4]);
c[2] = mem.readIntLittle(u32, nonce[4..8]);
c[3] = mem.readIntLittle(u32, nonce[8..12]);
const server_key = keyToWords(key_data.server_key(@This()).*);
const server_key = crypto.keyToWords(key_data.server_key(@This()).*);

return .{
.mac = ChaCha20Stream.initPoly1305(key_data.server_key(@This()).*, nonce, additional_data),
Expand All @@ -72,7 +73,7 @@ pub const suites = struct {
ChaCha20Stream.chacha20Xor(
out,
encrypted,
keyToWords(key_data.server_key(@This()).*),
crypto.keyToWords(key_data.server_key(@This()).*),
&state.context,
idx,
&state.buf,
Expand Down Expand Up @@ -210,7 +211,7 @@ pub const suites = struct {

std.debug.assert(encrypted.len == out.len);

ctr(
crypto.ctr(
@TypeOf(state.aes),
state.aes,
out,
Expand Down
7 changes: 4 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,8 @@ pub fn client_connect(
server_public_key_buf,
);

var seed: [77]u8 = undefined;
const seed_len = 77; // extra len variable to workaround a bug
var seed: [seed_len]u8 = undefined;
seed[0..13].* = "master secret".*;
seed[13..45].* = client_random;
seed[45..77].* = server_random;
Expand Down Expand Up @@ -1604,8 +1605,8 @@ pub fn client_connect(

const KeyExpansionState = struct {
seed: *const [77]u8,
a1: *[32 + seed.len]u8,
a2: *[32 + seed.len]u8,
a1: *[32 + seed_len]u8,
a2: *[32 + seed_len]u8,
master_secret: *const [48]u8,
};

Expand Down