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) {...@@ -227,7 +227,7 @@ pub const CertificateType = enum(u8) {
227 _,227 _,
228};228};
229229
230pub fn CipherParamsT(comptime AeadType: type, comptime HashType: type) type {230pub fn HandshakeCipherT(comptime AeadType: type, comptime HashType: type) type {
231 return struct {231 return struct {
232 pub const AEAD = AeadType;232 pub const AEAD = AeadType;
233 pub const Hash = HashType;233 pub const Hash = HashType;
...@@ -246,12 +246,12 @@ pub fn CipherParamsT(comptime AeadType: type, comptime HashType: type) type {...@@ -246,12 +246,12 @@ pub fn CipherParamsT(comptime AeadType: type, comptime HashType: type) type {
246 };246 };
247}247}
248248
249pub const CipherParams = union(enum) {249pub const HandshakeCipher = union(enum) {
250 AES_128_GCM_SHA256: CipherParamsT(crypto.aead.aes_gcm.Aes128Gcm, crypto.hash.sha2.Sha256),250 AES_128_GCM_SHA256: HandshakeCipherT(crypto.aead.aes_gcm.Aes128Gcm, crypto.hash.sha2.Sha256),
251 AES_256_GCM_SHA384: CipherParamsT(crypto.aead.aes_gcm.Aes256Gcm, crypto.hash.sha2.Sha384),251 AES_256_GCM_SHA384: HandshakeCipherT(crypto.aead.aes_gcm.Aes256Gcm, crypto.hash.sha2.Sha384),
252 CHACHA20_POLY1305_SHA256: CipherParamsT(crypto.aead.chacha_poly.ChaCha20Poly1305, crypto.hash.sha2.Sha256),252 CHACHA20_POLY1305_SHA256: HandshakeCipherT(crypto.aead.chacha_poly.ChaCha20Poly1305, crypto.hash.sha2.Sha256),
253 AEGIS_256_SHA384: CipherParamsT(crypto.aead.aegis.Aegis256, crypto.hash.sha2.Sha384),253 AEGIS_256_SHA384: HandshakeCipherT(crypto.aead.aegis.Aegis256, crypto.hash.sha2.Sha384),
254 AEGIS_128L_SHA256: CipherParamsT(crypto.aead.aegis.Aegis128L, crypto.hash.sha2.Sha256),254 AEGIS_128L_SHA256: HandshakeCipherT(crypto.aead.aegis.Aegis128L, crypto.hash.sha2.Sha256),
255};255};
256256
257pub fn ApplicationCipherT(comptime AeadType: type, comptime HashType: type) type {257pub 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;...@@ -11,7 +11,7 @@ const ApplicationCipher = tls.ApplicationCipher;
11const CipherSuite = tls.CipherSuite;11const CipherSuite = tls.CipherSuite;
12const ContentType = tls.ContentType;12const ContentType = tls.ContentType;
13const HandshakeType = tls.HandshakeType;13const HandshakeType = tls.HandshakeType;
14const CipherParams = tls.CipherParams;14const HandshakeCipher = tls.HandshakeCipher;
15const max_ciphertext_len = tls.max_ciphertext_len;15const max_ciphertext_len = tls.max_ciphertext_len;
16const hkdfExpandLabel = tls.hkdfExpandLabel;16const hkdfExpandLabel = tls.hkdfExpandLabel;
17const int2 = tls.int2;17const int2 = tls.int2;
...@@ -117,7 +117,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -117,7 +117,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
117117
118 const client_hello_bytes1 = plaintext_header[5..];118 const client_hello_bytes1 = plaintext_header[5..];
119119
120 var cipher_params: CipherParams = undefined;120 var handshake_cipher: HandshakeCipher = undefined;
121121
122 var handshake_buf: [8000]u8 = undefined;122 var handshake_buf: [8000]u8 = undefined;
123 var len: usize = 0;123 var len: usize = 0;
...@@ -243,8 +243,8 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -243,8 +243,8 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
243 .AEGIS_256_SHA384,243 .AEGIS_256_SHA384,
244 .AEGIS_128L_SHA256,244 .AEGIS_128L_SHA256,
245 => |tag| {245 => |tag| {
246 const P = std.meta.TagPayloadByName(CipherParams, @tagName(tag));246 const P = std.meta.TagPayloadByName(HandshakeCipher, @tagName(tag));
247 cipher_params = @unionInit(CipherParams, @tagName(tag), .{247 handshake_cipher = @unionInit(HandshakeCipher, @tagName(tag), .{
248 .handshake_secret = undefined,248 .handshake_secret = undefined,
249 .master_secret = undefined,249 .master_secret = undefined,
250 .client_handshake_key = undefined,250 .client_handshake_key = undefined,
...@@ -255,7 +255,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -255,7 +255,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
255 .server_handshake_iv = undefined,255 .server_handshake_iv = undefined,
256 .transcript_hash = P.Hash.init(.{}),256 .transcript_hash = P.Hash.init(.{}),
257 });257 });
258 const p = &@field(cipher_params, @tagName(tag));258 const p = &@field(handshake_cipher, @tagName(tag));
259 p.transcript_hash.update(client_hello_bytes1); // Client Hello part 1259 p.transcript_hash.update(client_hello_bytes1); // Client Hello part 1
260 p.transcript_hash.update(host); // Client Hello part 2260 p.transcript_hash.update(host); // Client Hello part 2
261 p.transcript_hash.update(frag); // Server Hello261 p.transcript_hash.update(frag); // Server Hello
...@@ -329,7 +329,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -329,7 +329,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
329 },329 },
330 .application_data => {330 .application_data => {
331 var cleartext_buf: [8000]u8 = undefined;331 var cleartext_buf: [8000]u8 = undefined;
332 const cleartext = switch (cipher_params) {332 const cleartext = switch (handshake_cipher) {
333 inline else => |*p| c: {333 inline else => |*p| c: {
334 const P = @TypeOf(p.*);334 const P = @TypeOf(p.*);
335 const ciphertext_len = record_size - P.AEAD.tag_length;335 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...@@ -366,7 +366,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
366 const handshake = cleartext[ct_i..next_handshake_i];366 const handshake = cleartext[ct_i..next_handshake_i];
367 switch (handshake_type) {367 switch (handshake_type) {
368 @enumToInt(HandshakeType.encrypted_extensions) => {368 @enumToInt(HandshakeType.encrypted_extensions) => {
369 switch (cipher_params) {369 switch (handshake_cipher) {
370 inline else => |*p| p.transcript_hash.update(wrapped_handshake),370 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
371 }371 }
372 const total_ext_size = mem.readIntBig(u16, handshake[0..2]);372 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...@@ -390,7 +390,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
390 }390 }
391 },391 },
392 @enumToInt(HandshakeType.certificate) => cert: {392 @enumToInt(HandshakeType.certificate) => cert: {
393 switch (cipher_params) {393 switch (handshake_cipher) {
394 inline else => |*p| p.transcript_hash.update(wrapped_handshake),394 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
395 }395 }
396 if (validated_cert) break :cert;396 if (validated_cert) break :cert;
...@@ -445,7 +445,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -445,7 +445,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
445 }445 }
446 },446 },
447 @enumToInt(HandshakeType.certificate_verify) => {447 @enumToInt(HandshakeType.certificate_verify) => {
448 switch (cipher_params) {448 switch (handshake_cipher) {
449 inline else => |*p| p.transcript_hash.update(wrapped_handshake),449 inline else => |*p| p.transcript_hash.update(wrapped_handshake),
450 }450 }
451 std.debug.print("ignoring certificate_verify\n", .{});451 std.debug.print("ignoring certificate_verify\n", .{});
...@@ -458,7 +458,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con...@@ -458,7 +458,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con
458 0x00, 0x01, // length458 0x00, 0x01, // length
459 0x01,459 0x01,
460 };460 };
461 const app_cipher = switch (cipher_params) {461 const app_cipher = switch (handshake_cipher) {
462 inline else => |*p, tag| c: {462 inline else => |*p, tag| c: {
463 const P = @TypeOf(p.*);463 const P = @TypeOf(p.*);
464 const finished_digest = p.transcript_hash.peek();464 const finished_digest = p.transcript_hash.peek();