Skip to content

Commit

Permalink
⚡️ benchmark without dleq proof
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Aug 9, 2024
1 parent 6530b9b commit 794e61e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/bdhke.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/benchmarks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 794e61e

Please sign in to comment.