Skip to content

Commit 4036f3a

Browse files
authored
Merge pull request #10 from zig-bitcoin/ecdsa-schnorr-split
Split schnorr + ecdsa sign impl + recovery
2 parents 022b409 + 2714c1b commit 4036f3a

File tree

8 files changed

+1024
-213
lines changed

8 files changed

+1024
-213
lines changed

build.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn buildSecp256k1(libsecp_c: *std.Build.Dependency, b: *std.Build, target: std.B
1010

1111
lib.addIncludePath(libsecp_c.path(""));
1212
lib.addIncludePath(libsecp_c.path("src"));
13+
lib.addIncludePath(libsecp_c.path("include"));
1314

1415
var flags = std.ArrayList([]const u8).init(b.allocator);
1516
defer flags.deinit();
@@ -19,7 +20,15 @@ fn buildSecp256k1(libsecp_c: *std.Build.Dependency, b: *std.Build, target: std.B
1920
try flags.appendSlice(&.{"-DENABLE_MODULE_ECDH=1"});
2021
try flags.appendSlice(&.{"-DENABLE_MODULE_EXTRAKEYS=1"});
2122

22-
lib.addCSourceFiles(.{ .root = libsecp_c.path(""), .flags = flags.items, .files = &.{ "./src/secp256k1.c", "./src/precomputed_ecmult.c", "./src/precomputed_ecmult_gen.c" } });
23+
lib.addCSourceFiles(.{
24+
.root = libsecp_c.path(""),
25+
.flags = flags.items,
26+
.files = &.{
27+
"./src/secp256k1.c",
28+
"./src/precomputed_ecmult.c",
29+
"./src/precomputed_ecmult_gen.c",
30+
},
31+
});
2332
lib.defineCMacro("USE_FIELD_10X26", "1");
2433
lib.defineCMacro("USE_SCALAR_8X32", "1");
2534
lib.defineCMacro("USE_ENDOMORPHISM", "1");

src/constants.zig

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Constants related to the API and the underlying curve.
4+
//!
5+
6+
/// The size (in bytes) of a message.
7+
pub const message_size: usize = 32;
8+
9+
/// the size (in bytes) of a secret key.
10+
pub const secret_key_size: usize = 32;
11+
12+
/// the size (in bytes) of a serialized public key.
13+
pub const public_key_size: usize = 33;
14+
15+
/// the size (in bytes) of an serialized uncompressed public key.
16+
pub const uncompressed_public_key_size: usize = 65;
17+
18+
/// the maximum size of a signature.
19+
pub const max_signature_size: usize = 72;
20+
21+
/// the maximum size of a compact signature.
22+
pub const compact_signature_size: usize = 64;
23+
24+
/// the size of a schnorr signature.
25+
pub const schnorr_signature_size: usize = 64;
26+
27+
/// the size of a schnorr public key.
28+
pub const schnorr_public_key_size: usize = 32;
29+
30+
/// the size of a key pair.
31+
pub const key_pair_size: usize = 96;
32+
33+
/// the size of a full elligatorswift encoding.
34+
pub const ellswift_encoding_size: usize = 64;
35+
36+
/// The Prime for the secp256k1 field element.
37+
pub const field_size: [32]u8 = .{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f };
38+
39+
/// the order of the secp256k1 curve.
40+
pub const curve_order: [32]u8 = .{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 };
41+
42+
/// the x coordinate of the generator.
43+
pub const generator_x: [32]u8 = .{ 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98 };
44+
45+
/// the y coordinate of the generator.
46+
pub const generator_y: [32]u8 = .{ 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8 };
47+
48+
/// the value zero as an array of bytes.
49+
pub const zero: [32]u8 = [_]u8{0} ** 32;
50+
51+
/// the value one as big-endian array of bytes.
52+
pub const one: [32]u8 = .{
53+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
54+
};

0 commit comments

Comments
 (0)