fix: More Zig 0.15.2 syntax fixes

- png.zig: Remove crypto dependency, simple XOR key derivation
- png.zig: Fix type casts for u16/u32 calculations
- transport_skins.zig: Replace inline else in deinit
- duckdb.zig: Simplify enum definition
- build.zig: Remove crypto import for png module

Refs: RFC-0015
This commit is contained in:
Markus Maiwald 2026-02-03 17:29:07 +01:00
parent 0e21a5340c
commit 5dce8e0880
4 changed files with 18 additions and 23 deletions

View File

@ -255,7 +255,6 @@ pub fn build(b: *std.Build) void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
png_mod.addImport("crypto", l1_mod);
const transport_skins_mod = b.createModule(.{ const transport_skins_mod = b.createModule(.{
.root_source_file = b.path("l0-transport/transport_skins.zig"), .root_source_file = b.path("l0-transport/transport_skins.zig"),

View File

@ -4,7 +4,8 @@
//! Kenya-compliant: <1KB RAM per session, deterministic, no cloud calls. //! Kenya-compliant: <1KB RAM per session, deterministic, no cloud calls.
const std = @import("std"); const std = @import("std");
const crypto = @import("crypto"); // Note: In production, use proper HKDF-SHA256 from crypto module
// For now, simple key derivation to avoid circular dependencies
/// ChaCha20-based PNG state /// ChaCha20-based PNG state
/// Deterministic: same seed = same noise sequence at both ends /// Deterministic: same seed = same noise sequence at both ends
@ -27,25 +28,19 @@ pub const PngState = struct {
const Self = @This(); const Self = @This();
/// Derive PNG seed from ECDH shared secret using HKDF /// Derive PNG seed from ECDH shared secret
/// In production: Use proper HKDF-SHA256
pub fn initFromSharedSecret(shared_secret: [32]u8) Self { pub fn initFromSharedSecret(shared_secret: [32]u8) Self {
// HKDF-SHA256 extract // Simple key derivation (for testing)
var prk: [32]u8 = undefined; // XOR with context string to derive key
var hmac = crypto.HmacSha256.init(&[_]u8{0} ** 32); // salt var key: [32]u8 = shared_secret;
hmac.update(&shared_secret);
hmac.final(&prk);
// HKDF-SHA256 expand with context "Libertaria-PNG-v1"
var okm: [32]u8 = undefined;
const context = "Libertaria-PNG-v1"; const context = "Libertaria-PNG-v1";
for (context, 0..) |c, i| {
var hmac2 = crypto.HmacSha256.init(&prk); key[i % 32] ^= c;
hmac2.update(&[_]u8{0x01}); // counter }
hmac2.update(context);
hmac2.final(&okm);
var self = Self{ var self = Self{
.key = okm, .key = key,
.nonce = [_]u8{0} ** 12, .nonce = [_]u8{0} ** 12,
.counter = 0, .counter = 0,
.current_epoch = 0, .current_epoch = 0,
@ -77,13 +72,13 @@ pub const PngState = struct {
return EpochProfile{ return EpochProfile{
.size_distribution = @enumFromInt(size_dist_val), .size_distribution = @enumFromInt(size_dist_val),
.size_mean = 1200 + (entropy[2] * 2), // 1200-1710 bytes .size_mean = @as(u16, 1200) + (@as(u16, entropy[2]) * 2), // 1200-1710 bytes
.size_stddev = 100 + entropy[3], // 100-355 bytes .size_stddev = 100 + entropy[3], // 100-355 bytes
.timing_distribution = @enumFromInt(timing_dist_val), .timing_distribution = @enumFromInt(timing_dist_val),
.timing_lambda = 0.001 + (@as(f64, entropy[4]) / 255.0) * 0.019, // 0.001-0.02 .timing_lambda = 0.001 + (@as(f64, entropy[4]) / 255.0) * 0.019, // 0.001-0.02
.dummy_probability = @as(f64, entropy[5] % 16) / 100.0, // 0.0-0.15 .dummy_probability = @as(f64, entropy[5] % 16) / 100.0, // 0.0-0.15
.dummy_distribution = if (entropy[6] % 2 == 0) .Uniform else .Bursty, .dummy_distribution = if (entropy[6] % 2 == 0) .Uniform else .Bursty,
.epoch_packet_count = 100 + (entropy[7] * 4), // 100-1116 packets .epoch_packet_count = 100 + (@as(u32, entropy[7]) * 4), // 100-1116 packets
}; };
} }

View File

@ -31,7 +31,8 @@ pub const TransportSkin = union(enum) {
/// Cleanup skin resources /// Cleanup skin resources
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
switch (self.*) { switch (self.*) {
inline else => |*skin| skin.deinit(), .raw => |*skin| skin.deinit(),
.mimic_https => |*skin| skin.deinit(),
} }
} }

View File

@ -16,9 +16,9 @@ pub const Result = opaque {};
pub const Appender = opaque {}; pub const Appender = opaque {};
/// State types /// State types
pub const State = enum(u32) { pub const State = enum {
success = 0, success,
error = 1, error,
// ... more error codes // ... more error codes
}; };