Skip to content

Commit

Permalink
Merge pull request #3 from davxy/ci-pipeline
Browse files Browse the repository at this point in the history
Introduce CI pipeline
  • Loading branch information
davxy authored Apr 14, 2024
2 parents a68eae0 + 2fb2c6f commit db51c2c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Rust

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

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: '-D warnings'
RUST_BACKTRACE: 1

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
- name: Format
run: cargo fmt --all --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
- name: Clippy
run: cargo clippy --all-targets --all-features

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build
run: cargo build --verbose --all-features

build-wasm32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
- name: Build
run: cargo build --verbose --no-default-features --target wasm32-unknown-unknown

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Run tests
run: cargo test --release --all-features

15 changes: 6 additions & 9 deletions src/suites/secp256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,34 @@ mod tests {
}

fn test_vector(v: &TestVector) {
let encode_point = |p| utils::encode_point::<S>(p);
let encode_scalar = |s| utils::encode_scalar::<S>(s);

let mut sk_bytes = hex::decode(v.sk).unwrap();
sk_bytes.reverse();
let sk = Secret::deserialize_compressed(&mut sk_bytes.as_slice()).unwrap();

let pk_bytes = encode_point(&sk.public.0);
let pk_bytes = utils::encode_point::<S>(&sk.public.0);
assert_eq!(v.pk, hex::encode(&pk_bytes));

// Prepare hash_to_curve data = salt || alpha
// Salt is defined to be pk (adjust it to make the encoding to match)
let h2c_data = [&pk_bytes[..], v.alpha].concat();
let h = S::data_to_point(&h2c_data).unwrap();
let h_bytes = encode_point(&h);
let h_bytes = utils::encode_point::<S>(&h);
assert_eq!(v.h, hex::encode(h_bytes));

let input = Input::from(h);
let signature = sk.sign(input, []);

let gamma_bytes = encode_point(&signature.output().0);
assert_eq!(v.gamma, hex::encode(&gamma_bytes));
let gamma_bytes = utils::encode_point::<S>(&signature.output().0);
assert_eq!(v.gamma, hex::encode(gamma_bytes));

if v.skip_sign_check {
return;
}

let c_bytes = encode_scalar(&signature.c);
let c_bytes = utils::encode_scalar::<S>(&signature.c);
assert_eq!(v.c, hex::encode(c_bytes));

let s_bytes = encode_scalar(&signature.s);
let s_bytes = utils::encode_scalar::<S>(&signature.s);
assert_eq!(v.s, hex::encode(s_bytes));

let beta = signature.gamma.hash();
Expand Down

0 comments on commit db51c2c

Please sign in to comment.