From 794e61ef45fde03936b836a810d5f25f83e3ae2f Mon Sep 17 00:00:00 2001 From: "Abdel @ StarkWare" Date: Fri, 9 Aug 2024 10:18:45 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20benchmark=20without=20dleq?= =?UTF-8?q?=20proof?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bdhke.zig | 16 +++++++++++----- src/benchmarks.zig | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bdhke.zig b/src/bdhke.zig index 28667ac..7589426 100644 --- a/src/bdhke.zig +++ b/src/bdhke.zig @@ -18,14 +18,20 @@ pub fn step1Alice(secret_msg: []const u8, blinding_factor: Point) !Point { } /// Step 2: Bob signs the blinded message -pub fn step2Bob(B_: Point, a: Scalar) !struct { C_: Point, e: Scalar, s: Scalar } { +pub fn step2Bob(B_: Point, a: Scalar, generate_dleq_proof: bool) !struct { C_: Point, e: Scalar, s: Scalar } { const C_ = try B_.mul(a.toBytes(.little), .little); + if (!generate_dleq_proof) { + return .{ .C_ = C_, .e = Scalar.zero, .s = Scalar.zero }; + } + + // Generate DLEQ proof const result = try step2BobDLEQ(B_, a, C_); - return .{ .C_ = result.C_, .e = result.e, .s = result.s }; + + return .{ .C_ = C_, .e = result.e, .s = result.s }; } /// Generates DLEQ proof -fn step2BobDLEQ(B_: Point, a: Scalar, C_: Point) !struct { C_: Point, e: Scalar, s: Scalar } { +fn step2BobDLEQ(B_: Point, a: Scalar, C_: Point) !struct { e: Scalar, s: Scalar } { const p = Scalar.random(); const R1 = try Point.basePoint.mul(p.toBytes(.little), .little); const R2 = try B_.mul(p.toBytes(.little), .little); @@ -34,7 +40,7 @@ fn step2BobDLEQ(B_: Point, a: Scalar, C_: Point) !struct { C_: Point, e: Scalar, const e = try hashE(&[_]Point{ R1, R2, A, C_ }); const s = p.add(a.mul(e)); - return .{ .C_ = C_, .e = e, .s = s }; + return .{ .e = e, .s = s }; } /// Step 3: Alice unblinds the signature @@ -153,7 +159,7 @@ pub fn testBDHKE() !void { std.debug.print("Step 1 complete: Message blinded\n", .{}); // Step 2: Bob signs the blinded message - const step2_result = try step2Bob(B_, a); + const step2_result = try step2Bob(B_, a, true); const C_ = step2_result.C_; const e = step2_result.e; const s = step2_result.s; diff --git a/src/benchmarks.zig b/src/benchmarks.zig index 997ba42..0f458a2 100644 --- a/src/benchmarks.zig +++ b/src/benchmarks.zig @@ -56,11 +56,11 @@ fn benchmarkAll(results: *std.ArrayList(BenchmarkResult)) !void { const B_ = try bdhke.step1Alice(secret_msg, blinding_factor); try benchmarkStep(results, "step2Bob", struct { fn func(b: Point, key: Scalar) !void { - _ = try bdhke.step2Bob(b, key); + _ = try bdhke.step2Bob(b, key, false); } }.func, .{ B_, a }); - const step2_result = try bdhke.step2Bob(B_, a); + const step2_result = try bdhke.step2Bob(B_, a, false); try benchmarkStep(results, "step3Alice", struct { fn func(c: Point, key: Scalar, pub_key: Point) !void { _ = try bdhke.step3Alice(c, key, pub_key); @@ -78,7 +78,7 @@ fn benchmarkAll(results: *std.ArrayList(BenchmarkResult)) !void { try benchmarkStep(results, "End-to-End BDHKE", struct { fn func(msg: []const u8, bf: Point, key: Scalar, pub_key: Point, _r: Scalar) !void { const b = try bdhke.step1Alice(msg, bf); - const step2_res = try bdhke.step2Bob(b, key); + const step2_res = try bdhke.step2Bob(b, key, false); const c = try bdhke.step3Alice(step2_res.C_, _r, pub_key); const is_valid = try bdhke.verify(key, c, secret_msg); // Fail if the verification fails