authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-21 16:16:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-02 16:57:15-07:00
log4f9f4575bdf35fa69f09910d3d0ae349f9071c18
treed88b02c1310768c4eecdf58f219ca8bd0f5846af
parent22db1e166a6e3721df21546209fbfe9df7ddc0c0

std.crypto.tls: rename HandshakeCipher


2 files changed, 17 insertions(+), 17 deletions(-)

lib/std/crypto/tls.zig+7-7
......@@ -227,7 +227,7 @@ pub const CertificateType = enum(u8) {
227227 _,
228228};
229229
230pub fn CipherParamsT(comptime AeadType: type, comptime HashType: type) type {
230pub fn HandshakeCipherT(comptime AeadType: type, comptime HashType: type) type {
231231 return struct {
232232 pub const AEAD = AeadType;
233233 pub const Hash = HashType;
......@@ -246,12 +246,12 @@ pub fn CipherParamsT(comptime AeadType: type, comptime HashType: type) type {
246246 };
247247}
248248
249pub const CipherParams = union(enum) {
250 AES_128_GCM_SHA256: CipherParamsT(crypto.aead.aes_gcm.Aes128Gcm, crypto.hash.sha2.Sha256),
251 AES_256_GCM_SHA384: CipherParamsT(crypto.aead.aes_gcm.Aes256Gcm, crypto.hash.sha2.Sha384),
252 CHACHA20_POLY1305_SHA256: CipherParamsT(crypto.aead.chacha_poly.ChaCha20Poly1305, crypto.hash.sha2.Sha256),
253 AEGIS_256_SHA384: CipherParamsT(crypto.aead.aegis.Aegis256, crypto.hash.sha2.Sha384),
254 AEGIS_128L_SHA256: CipherParamsT(crypto.aead.aegis.Aegis128L, crypto.hash.sha2.Sha256),
249pub const HandshakeCipher = union(enum) {
250 AES_128_GCM_SHA256: HandshakeCipherT(crypto.aead.aes_gcm.Aes128Gcm, crypto.hash.sha2.Sha256),
251 AES_256_GCM_SHA384: HandshakeCipherT(crypto.aead.aes_gcm.Aes256Gcm, crypto.hash.sha2.Sha384),
252 CHACHA20_POLY1305_SHA256: HandshakeCipherT(crypto.aead.chacha_poly.ChaCha20Poly1305, crypto.hash.sha2.Sha256),
253 AEGIS_256_SHA384: HandshakeCipherT(crypto.aead.aegis.Aegis256, crypto.hash.sha2.Sha384),
254 AEGIS_128L_SHA256: HandshakeCipherT(crypto.aead.aegis.Aegis128L, crypto.hash.sha2.Sha256),
255255};
256256
257257pub fn ApplicationCipherT(comptime AeadType: type, comptime HashType: type) type {
lib/std/crypto/tls/Client.zig+10-10
......@@ -11,7 +11,7 @@ const ApplicationCipher = tls.ApplicationCipher;
1111const CipherSuite = tls.CipherSuite;
1212const ContentType = tls.ContentType;
1313const HandshakeType = tls.HandshakeType;
14const CipherParams = tls.CipherParams;
14const HandshakeCipher = tls.HandshakeCipher;
1515const max_ciphertext_len = tls.max_ciphertext_len;
1616const hkdfExpandLabel = tls.hkdfExpandLabel;
1717const int2 = tls.int2;
......@@ -117,7 +117,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
117117
118118 const client_hello_bytes1 = plaintext_header[5..];
119119
120 var cipher_params: CipherParams = undefined;
120 var handshake_cipher: HandshakeCipher = undefined;
121121
122122 var handshake_buf: [8000]u8 = undefined;
123123 var len: usize = 0;
......@@ -243,8 +243,8 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
243243 .AEGIS_256_SHA384,
244244 .AEGIS_128L_SHA256,
245245 => |tag| {
246 const P = std.meta.TagPayloadByName(CipherParams, @tagName(tag));
247 cipher_params = @unionInit(CipherParams, @tagName(tag), .{
246 const P = std.meta.TagPayloadByName(HandshakeCipher, @tagName(tag));
247 handshake_cipher = @unionInit(HandshakeCipher, @tagName(tag), .{
248248 .handshake_secret = undefined,
249249 .master_secret = undefined,
250250 .client_handshake_key = undefined,
......@@ -255,7 +255,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
255255 .server_handshake_iv = undefined,
256256 .transcript_hash = P.Hash.init(.{}),
257257 });
258 const p = &@field(cipher_params, @tagName(tag));
258 const p = &@field(handshake_cipher, @tagName(tag));
259259 p.transcript_hash.update(client_hello_bytes1); // Client Hello part 1
260260 p.transcript_hash.update(host); // Client Hello part 2
261261 p.transcript_hash.update(frag); // Server Hello
......@@ -329,7 +329,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
329329 },
330330 .application_data => {
331331 var cleartext_buf: [8000]u8 = undefined;
332 const cleartext = switch (cipher_params) {
332 const cleartext = switch (handshake_cipher) {
333333 inline else => |*p| c: {
334334 const P = @TypeOf(p.*);
335335 const ciphertext_len = record_size - P.AEAD.tag_length;
......@@ -366,7 +366,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
366366 const handshake = cleartext[ct_i..next_handshake_i];
367367 switch (handshake_type) {
368368 @enumToInt(HandshakeType.encrypted_extensions) => {
369 switch (cipher_params) {
369 switch (handshake_cipher) {
370370 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
371371 }
372372 const total_ext_size = mem.readIntBig(u16, handshake[0..2]);
......@@ -390,7 +390,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
390390 }
391391 },
392392 @enumToInt(HandshakeType.certificate) => cert: {
393 switch (cipher_params) {
393 switch (handshake_cipher) {
394394 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
395395 }
396396 if (validated_cert) break :cert;
......@@ -445,7 +445,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
445445 }
446446 },
447447 @enumToInt(HandshakeType.certificate_verify) => {
448 switch (cipher_params) {
448 switch (handshake_cipher) {
449449 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
450450 }
451451 std.debug.print("ignoring certificate_verify\n", .{});
......@@ -458,7 +458,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
458458 0x00, 0x01, // length
459459 0x01,
460460 };
461 const app_cipher = switch (cipher_params) {
461 const app_cipher = switch (handshake_cipher) {
462462 inline else => |*p, tag| c: {
463463 const P = @TypeOf(p.*);
464464 const finished_digest = p.transcript_hash.peek();