fix(l1): Export PQXDH module and correct build linkage

- l1-identity/crypto.zig: Export pqxdh module for SDK consumption
- build.zig: Define proper modules for PQXDH library and tests
- Link liboqs to l1_pqxdh_mod and propagate dependency to l1_mod
This commit is contained in:
Markus Maiwald 2026-01-30 23:12:35 +01:00
parent d9adadd1d5
commit 3b3993bea6
2 changed files with 29 additions and 5 deletions

View File

@ -143,17 +143,36 @@ pub fn build(b: *std.Build) void {
// L1 PQXDH tests (Phase 3) // L1 PQXDH tests (Phase 3)
// ======================================================================== // ========================================================================
const l1_pqxdh_mod = b.createModule(.{ const l1_pqxdh_mod = b.createModule(.{
.root_source_file = b.path("l1-identity/pqxdh.zig"),
.target = target,
.optimize = optimize,
});
l1_pqxdh_mod.addIncludePath(b.path("vendor/liboqs/install/include"));
l1_pqxdh_mod.addLibraryPath(b.path("vendor/liboqs/install/lib"));
l1_pqxdh_mod.linkSystemLibrary("oqs", .{ .needed = true });
// Consuming artifacts must linkLibC()
// Import PQXDH into main L1 module
l1_mod.addImport("pqxdh", l1_pqxdh_mod);
// Tests (root is test_pqxdh.zig)
const l1_pqxdh_tests_mod = b.createModule(.{
.root_source_file = b.path("l1-identity/test_pqxdh.zig"), .root_source_file = b.path("l1-identity/test_pqxdh.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
// Tests import the library module 'pqxdh' (relative import works too, but module is cleaner if we use @import("pqxdh"))
// But test_pqxdh.zig uses @import("pqxdh.zig") which is relative file import.
// If we use relative import, the test module must be able to resolve pqxdh.zig.
// Since they are in same dir, relative import works.
// BUT the artifact compiled from test_pqxdh.zig needs to link liboqs because it effectively includes pqxdh.zig code.
const l1_pqxdh_tests = b.addTest(.{ const l1_pqxdh_tests = b.addTest(.{
.root_module = l1_pqxdh_mod, .root_module = l1_pqxdh_tests_mod,
}); });
l1_pqxdh_tests.linkLibC(); l1_pqxdh_tests.linkLibC();
l1_pqxdh_tests.addIncludePath(b.path("vendor/liboqs/install/include")); l1_pqxdh_tests.addIncludePath(b.path("vendor/liboqs/install/include"));
l1_pqxdh_tests.addLibraryPath(b.path("vendor/liboqs/install/lib")); // For liboqs.a l1_pqxdh_tests.addLibraryPath(b.path("vendor/liboqs/install/lib"));
l1_pqxdh_tests.linkSystemLibrary("oqs"); l1_pqxdh_tests.linkSystemLibrary("oqs");
const run_l1_pqxdh_tests = b.addRunArtifact(l1_pqxdh_tests); const run_l1_pqxdh_tests = b.addRunArtifact(l1_pqxdh_tests);

View File

@ -11,10 +11,15 @@
const std = @import("std"); const std = @import("std");
const crypto = std.crypto; const crypto = std.crypto;
// Ensure crypto FFI exports are compiled when this module is used
// This makes Zig-exported C functions available to C code
// Ensure crypto FFI exports are compiled when this module is used // Ensure crypto FFI exports are compiled when this module is used
// This makes Zig-exported C functions available to C code // This makes Zig-exported C functions available to C code
const _ = @import("crypto_exports"); const _ = @import("crypto_exports");
// Post-Quantum XDH (RFC-0830)
pub const pqxdh = @import("pqxdh");
/// RFC-0830 Section 2.6: WORLD_PUBLIC_KEY /// RFC-0830 Section 2.6: WORLD_PUBLIC_KEY
/// This is the well-known public key used for World Feed encryption. /// This is the well-known public key used for World Feed encryption.
/// Everyone can decrypt World posts, but ISPs see only ciphertext. /// Everyone can decrypt World posts, but ISPs see only ciphertext.