-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
86 additions
and
176 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
third_party/ecdh_psi/psi_utils/Cargo.toml → crypto/ecc/ecc_ed25519/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "psi_utils" | ||
name = "ecc_ed25519" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use sha2::Sha512; | ||
// use sha2::Digest; | ||
use rand::rngs::ThreadRng; | ||
// use rand::RngCore; | ||
use curve25519_dalek::{edwards::CompressedEdwardsY, Scalar}; | ||
|
||
const SCALAR_SIZE: usize = 32; | ||
const POINT_SIZE: usize = 32; | ||
|
||
pub fn random_scalar() -> Vec<u8> { | ||
// 创建一个随机数生成器 | ||
let mut rng: ThreadRng = rand::thread_rng(); | ||
|
||
// 生成一个随机的 Scalar | ||
let scalar = Scalar::random(&mut rng); | ||
|
||
// 将 Scalar 转换成 &[u8] | ||
scalar.to_bytes().to_vec() | ||
} | ||
|
||
pub fn hash_to_curve(message: &[u8]) -> Vec<u8> { | ||
let hash_scalar = Scalar::hash_from_bytes::<Sha256>(message).to_bytes(); | ||
let opt_point = match CompressedEdwardsY::from_slice(&hash_scalar) { | ||
Ok(v) => v, | ||
Err(_) => return Vec::new(), | ||
}; | ||
|
||
return opt_point.to_bytes().to_vec(); | ||
} | ||
|
||
pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec<u8> { | ||
// 检查输入切片是否具有正确的大小 | ||
if point.len() != POINT_SIZE || scalar.len() != SCALAR_SIZE { | ||
return Vec::new(); // 如果大小不正确,返回空的 Vec<u8> | ||
} | ||
|
||
// 将输入 &[u8] 转换成 CompressedEdwardsY 表示的点 | ||
let mut point_bytes = [0u8; POINT_SIZE]; | ||
point_bytes.copy_from_slice(point); | ||
let compressed_point = match CompressedEdwardsY(point_bytes).decompress() { | ||
Some(point) => point, | ||
None => return Vec::new(), // 解析点失败,返回空的 Vec<u8> | ||
}; | ||
|
||
// 将输入 &[u8] 转换成 Scalar | ||
let mut scalar_bytes = [0u8; SCALAR_SIZE]; | ||
scalar_bytes.copy_from_slice(scalar); | ||
let scalar = Scalar::from_bytes_mod_order(scalar_bytes); | ||
|
||
// 执行点乘操作 | ||
let result_point = compressed_point * scalar; | ||
|
||
// 将结果转换成压缩格式的点 | ||
let compressed_result = result_point.compress(); | ||
|
||
// 将结果转换成 &[u8] | ||
compressed_result.as_bytes().to_vec() | ||
} |
6 changes: 3 additions & 3 deletions
6
...rty/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml → crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
[package] | ||
name = "ffi_java_ecdh_psi" | ||
name = "ffi_java_ecc_ed25519" | ||
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_java_ecdh_psi" | ||
name = "ffi_java_ecc_ed25519" | ||
crate-type = [ "cdylib", "staticlib" ] | ||
|
||
[dependencies] | ||
jni = "0.13.0" | ||
psi_utils = { path = "../psi_utils"} | ||
ecc_ed25519 = { path = "../ecc_ed25519"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...rty/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml → crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
[package] | ||
name = "ffi_wasm_ecdh_psi" | ||
name = "ffi_wasm_ecc_ed25519" | ||
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_ecdh_psi" | ||
name = "ffi_wasm_ecc_ed25519" | ||
crate-type = ["rlib", "cdylib"] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
getrandom = { version = "0.2", features = ["js"] } | ||
psi_utils = { path = "../psi_utils"} | ||
ecc_ed25519 = { path = "../ecc_ed25519"} |
File renamed without changes.
9 changes: 2 additions & 7 deletions
9
...rty/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs → crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.