Skip to content

Commit

Permalink
add web eq
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoXuan40404 committed Dec 27, 2023
1 parent 44aeded commit 8154994
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"ffi/ffi_c/ffi_c_fisco_bcos",
"ffi/ffi_c/ffi_c_zkp",
"ffi/ffi_c/ffi_c_equality",
"ffi/ffi_wasm/ffi_wasm_web_equlity",
"ffi/ffi_common",
"ffi/ffi_java/ffi_java_crypto",
"ffi/ffi_java/ffi_java_crypto_binary",
Expand Down
20 changes: 17 additions & 3 deletions crypto/pairing/bls12_381/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ mod tests {
use crate::*;
use hex;

#[test]
fn test_complex_word_cm() {
let id1 = hex::decode("f0a59684f0acba93").unwrap();
let web_cipher = hex::decode("830e9f65febccc7a3baba23b3216b3ee23003b57d95b834afbb0405312ce93306c9011973c4b278f080d62c822bd0bd699dedef98481ad3114de742cbc4c58078b67f56f037b112d4759090cd400e26a97cb14ca4bc03b9f87f8d663bd8f107308b4cfba32849d031bb045db5fb282a1cfa3c9ff3cac1eea4407c89a213fdda7f2528a40268fbd919c9f8abf54734893").unwrap();
let cipher1_m1_recover =
WedprBls128Cipher::from_bytes(&web_cipher).unwrap();
let cipher1_m1 = encrypt_message(&id1);
let cipher1_m2 = encrypt_message(&id1);
assert_eq!(equality_test(&cipher1_m1, &cipher1_m2), true);
assert_eq!(equality_test(&cipher1_m1, &cipher1_m1_recover), true);

}

#[test]
fn test_equality() {
let message1: &[u8] = b"hello world";
Expand Down Expand Up @@ -200,14 +213,15 @@ mod tests {

#[test]
fn test_from_web() {
let message_hello = b"abc";
// let message_hello = b"𥖄𬺓";
let message_hello = &hex::decode("e6ada6e6b189").unwrap();
// let message_hello:Vec<u8> = vec![96,97,98,0,0,0,0,0];
wedpr_println!("message_hello:{:?}", message_hello);
wedpr_println!("message:{:?}", message_hello);
// let message_wrong = b"wrong";
let cipher1_hello = encrypt_message(message_hello);
// let cipher1_wrong = encrypt_message(message_wrong);

let web_hello1 = "a91c14d9111e95206e5be9e644f68dd6ddb5865da5bfab80d4c7fb7a1a1299db401e200bb401adc87da751283dd8cb2984820a100894e50583daec6261bd8728d6c80689fa02d8f3e7fae23329755229c98456db47f78071e03dd4344e7e8dc3029bf4809a8fc3198dcd4c6810465cbc42fc57329b1d980f70b2a383507c257e35f33f2851e0ab2a40bb24606900c152";
let web_hello1 = "80f26419aa4ab90def42ef065a1f3ee73fc4b1d7b9a28c3e886082641d1f144378df52b27f47eeb74e275c29e9a04a00ac06154bf0c7c741bdd4f65e22c156c2f5e7a0779e2fa51a461307886c6c6443952e76c54ea46106eef58fe3151aa9f20c52c47263b061b611921cdaabfc686cd79f41b42ab303c74396f60d64287d7e452fe50576e6550a9ff77493446f41ef";
let web_bytes1 = hex::decode(web_hello1).unwrap();

// let web_hello2 =
Expand Down
9 changes: 9 additions & 0 deletions crypto/pairing/bls12_381/src/peks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ mod tests {
use wedpr_l_common_coder_base64::WedprBase64;
use wedpr_l_utils::traits::Coder;

#[test]
fn test_complex_word() {
let id1 = hex::decode("f0a59684f0acba93").unwrap();
let key1 = generate_key();
let cipher_id1 = encrypt_message(&id1, &key1.pk);
let trapdoor1 = trapdoor(&id1, &key1.sk);
assert_eq!(trapdoor_test(&cipher_id1, &trapdoor1), true);
}

#[test]
fn test_peks() {
let id1 = "zhangsan".as_bytes();
Expand Down
15 changes: 15 additions & 0 deletions ffi/ffi_wasm/ffi_wasm_web_equlity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "ffi_wasm_web_equlity"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "ffi_wasm_equality"
crate-type = ["rlib", "cdylib"]

[dependencies]
wasm-bindgen = "0.2"
hex = "0.4.2"
wedpr_bls12_381 = { path = "../../../crypto/pairing/bls12_381" }
getrandom = { version = "0.2", features = ["js"] }
13 changes: 13 additions & 0 deletions ffi/ffi_wasm/ffi_wasm_web_equlity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use wasm_bindgen::prelude::*;
extern crate wedpr_bls12_381;


#[wasm_bindgen]
pub fn encrypt_message(message: &str) -> String {
let message_bytes = match hex::decode(message) {
Ok(v) => v,
Err(_) => return "".to_string(),
};
let result = wedpr_bls12_381::encrypt_message(&message_bytes);
hex::encode(result.to_bytes())
}

0 comments on commit 8154994

Please sign in to comment.