Skip to content

Commit

Permalink
feat: support BLS (Boneh-Lynn-Shacham) signature (#579)
Browse files Browse the repository at this point in the history
Map privatekey to bls primefield
Map publickey to projective point of G2
Implemented sign and verify of bls
implementation of bls aggregate
The msg is extending with prefix "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_ which is as same as filecoin's implementation.
  • Loading branch information
RyanKung authored May 29, 2024
1 parent e85f00f commit bb061f9
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qaci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Run core browser tests
uses: coactions/setup-xvfb@v1
with:
run: cargo test -p rings-core --target=wasm32-unknown-unknown --features wasm --no-default-features
run: cargo test -p rings-core --release --target=wasm32-unknown-unknown --features wasm --no-default-features
working-directory: ./

- name: Run node browser tests
Expand All @@ -64,7 +64,7 @@ jobs:

build:
name: Build and test
timeout-minutes: 25
timeout-minutes: 30
strategy:
matrix:
os: ["ubuntu-latest"]
Expand Down
186 changes: 175 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ browser_chrome_test = ["wasm"]

[dependencies]
# global
ark-bls12-381 = "0.4.0"
ark-ec = "0.4.2"
ark-ff = "0.4.2"
ark-serialize = "0.4.2"
ark-std = "0.4.0"
arrayref = "0.3.6"
async-lock = "2.5.0"
async-recursion = "1.0.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/ecc/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn affine_to_str(a: &[Affine]) -> Result<String> {
field_to_str(a.iter().map(|x| x.x).collect::<Vec<Field>>().as_slice())
}

pub fn encrypt(s: &str, k: PublicKey) -> Result<Vec<(CurveEle, CurveEle)>> {
pub fn encrypt(s: &str, k: PublicKey<33>) -> Result<Vec<(CurveEle<33>, CurveEle<33>)>> {
let random_sar: Scalar = SecretKey::random().into();
let mut h: Affine = k.try_into()?;
h.y.normalize();
Expand All @@ -143,14 +143,14 @@ pub fn encrypt(s: &str, k: PublicKey) -> Result<Vec<(CurveEle, CurveEle)>> {
(a_c1, a_c2)
})
.collect();
let mut ret: Vec<(CurveEle, CurveEle)> = vec![];
let mut ret: Vec<(CurveEle<33>, CurveEle<33>)> = vec![];
for (c1, c2) in affines {
ret.push((c1.try_into()?, c2.try_into()?))
}
Ok(ret)
}

pub fn decrypt(m: &[(CurveEle, CurveEle)], k: SecretKey) -> Result<String> {
pub fn decrypt(m: &[(CurveEle<33>, CurveEle<33>)], k: SecretKey) -> Result<String> {
let sar: Scalar = k.into();
let cxt = ECMultContext::new_boxed();
affine_to_str(
Expand Down
Loading

0 comments on commit bb061f9

Please sign in to comment.