mirror of
https://github.com/jedisct1/minisign.git
synced 2025-04-04 19:37:48 +03:00
parent
c165362385
commit
101e90a668
2 changed files with 29 additions and 11 deletions
38
build.zig
38
build.zig
|
@ -1,3 +1,4 @@
|
||||||
|
const builtin = @import("builtin");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
|
@ -15,21 +16,38 @@ pub fn build(b: *std.Build) !void {
|
||||||
});
|
});
|
||||||
minisign.linkLibC();
|
minisign.linkLibC();
|
||||||
if (use_libzodium) {
|
if (use_libzodium) {
|
||||||
const libzodium_mod = b.createModule(.{
|
var libzodium = lib: {
|
||||||
.root_source_file = b.path("src/libzodium/libzodium.zig"),
|
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 13) {
|
||||||
.target = target,
|
@compileError("Building requires Zig 0.13.0 or later");
|
||||||
.optimize = optimize,
|
}
|
||||||
});
|
if (builtin.zig_version.major == 0 and builtin.zig_version.minor == 13) {
|
||||||
const libzodium = b.addStaticLibrary(.{
|
break :lib b.addStaticLibrary(.{
|
||||||
.name = "zodium",
|
.name = "zodium",
|
||||||
.root_module = libzodium_mod,
|
.strip = true,
|
||||||
.strip = true,
|
.root_source_file = b.path("src/libzodium/libzodium.zig"),
|
||||||
});
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const libzodium_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/libzodium/libzodium.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
break :lib b.addStaticLibrary(.{
|
||||||
|
.name = "zodium",
|
||||||
|
.root_module = libzodium_mod,
|
||||||
|
.strip = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
libzodium.linkLibC();
|
libzodium.linkLibC();
|
||||||
b.installArtifact(libzodium);
|
b.installArtifact(libzodium);
|
||||||
minisign.root_module.addCMacro("LIBZODIUM", "1");
|
minisign.root_module.addCMacro("LIBZODIUM", "1");
|
||||||
minisign.linkLibrary(libzodium);
|
minisign.linkLibrary(libzodium);
|
||||||
} else {
|
} else {
|
||||||
|
minisign.addLibraryPath(.{ .cwd_relative = "/opt/homebrew/lib" });
|
||||||
|
minisign.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });
|
||||||
minisign.root_module.linkSystemLibrary(
|
minisign.root_module.linkSystemLibrary(
|
||||||
"sodium",
|
"sodium",
|
||||||
.{
|
.{
|
||||||
|
|
|
@ -75,7 +75,7 @@ export fn crypto_generichash_final(
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn crypto_sign_keypair(pk: [*c]u8, sk: [*c]u8) callconv(.C) c_int {
|
export fn crypto_sign_keypair(pk: [*c]u8, sk: [*c]u8) callconv(.C) c_int {
|
||||||
const kp = Ed25519.KeyPair.generate();
|
const kp = if (std.meta.hasFn(Ed25519.KeyPair, "generate")) Ed25519.KeyPair.generate() else (Ed25519.KeyPair.create(null) catch return -1);
|
||||||
pk[0..32].* = kp.public_key.toBytes();
|
pk[0..32].* = kp.public_key.toBytes();
|
||||||
sk[0..64].* = kp.secret_key.toBytes();
|
sk[0..64].* = kp.secret_key.toBytes();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue