Skip to content

Commit

Permalink
👷 init ci
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Aug 8, 2024
1 parent a1c8911 commit fa82d0a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Zig BDHKE Test

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
ZIG_VERSION: 0.14.0-dev.909+f9f894200

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Cache Zig
uses: actions/cache@v3
with:
path: ~/zig
key: ${{ runner.os }}-zig-${{ env.ZIG_VERSION }}

- name: Install Zig
if: steps.cache.outputs.cache-hit != 'true'
run: |
wget https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz
tar -xf zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz
mv zig-linux-x86_64-${{ env.ZIG_VERSION }} ~/zig
- name: Add Zig to PATH
run: echo "${HOME}/zig" >> $GITHUB_PATH

- name: Cache Zig build artifacts
uses: actions/cache@v3
with:
path: |
zig-cache
~/.cache/zig
key: ${{ runner.os }}-zig-build-${{ hashFiles('**/*.zig') }}
restore-keys: |
${{ runner.os }}-zig-build-
- name: Build and Run
run: zig build run
21 changes: 16 additions & 5 deletions src/bdhke.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,27 @@ fn hashE(points: []const Point) !Scalar {

/// End-to-end test scenario for BDHKE
pub fn testBDHKE() !void {
// Initialize
// Initialize with deterministic values
const secret_msg = "test_message";
const a = Scalar.random();
var a_bytes: [32]u8 = [_]u8{0} ** 31 ++ [_]u8{1};
const a = try Scalar.fromBytes(a_bytes, .big);
const A = try Point.basePoint.mul(a.toBytes(.little), .little);

std.debug.print("Starting BDHKE test\n", .{});
std.debug.print("Secret message: {s}\n", .{secret_msg});
const r = Scalar.random();
std.debug.print("Alice's private key (a): {s}\n", .{std.fmt.fmtSliceHexLower(&a_bytes)});
std.debug.print("Alice's public key (A): {s}\n", .{std.fmt.fmtSliceHexLower(&A.toCompressedSec1())});

// Deterministic blinding factor
var r_bytes: [32]u8 = [_]u8{0} ** 31 ++ [_]u8{1};
const r = try Scalar.fromBytes(r_bytes, .big);
const blinding_factor = try Point.basePoint.mul(r.toBytes(.little), .little);
std.debug.print("r private key: {s}\n", .{std.fmt.fmtSliceHexLower(&r_bytes)});
std.debug.print("Blinding factor (r): {s}\n", .{std.fmt.fmtSliceHexLower(&blinding_factor.toCompressedSec1())});

// Step 1: Alice blinds the message
const B_ = try step1Alice(secret_msg, blinding_factor);

std.debug.print("Blinded message (B_): {s}\n", .{std.fmt.fmtSliceHexLower(&B_.toCompressedSec1())});
std.debug.print("Step 1 complete: Message blinded\n", .{});

// Step 2: Bob signs the blinded message
Expand All @@ -150,6 +158,9 @@ pub fn testBDHKE() !void {
const e = step2_result.e;
const s = step2_result.s;

std.debug.print("Blinded signature (C_): {s}\n", .{std.fmt.fmtSliceHexLower(&C_.toCompressedSec1())});
std.debug.print("DLEQ proof - e: {s}\n", .{std.fmt.fmtSliceHexLower(&e.toBytes(.big))});
std.debug.print("DLEQ proof - s: {s}\n", .{std.fmt.fmtSliceHexLower(&s.toBytes(.big))});
std.debug.print("Step 2 complete: Blinded message signed\n", .{});

// Alice verifies DLEQ proof
Expand All @@ -161,7 +172,7 @@ pub fn testBDHKE() !void {

// Step 3: Alice unblinds the signature
const C = try step3Alice(C_, r, A);

std.debug.print("Unblinded signature (C): {s}\n", .{std.fmt.fmtSliceHexLower(&C.toCompressedSec1())});
std.debug.print("Step 3 complete: Signature unblinded\n", .{});

// Carol verifies DLEQ proof
Expand Down

0 comments on commit fa82d0a

Please sign in to comment.