From 616785148fee2a026be8310a9d0b48e819e81465 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Tue, 3 Jan 2023 18:31:27 +0800 Subject: [PATCH 1/8] fix vcl demo --- protos/crypto/ot.proto | 47 ++ protos/crypto/zkp.proto | 33 + protos/src/generated/mod.rs | 2 + protos/src/generated/ot.rs | 1390 +++++++++++++++++++++++++++++++++++ protos/src/generated/zkp.rs | 875 ++++++++++++++++++++++ 5 files changed, 2347 insertions(+) create mode 100644 protos/crypto/ot.proto create mode 100644 protos/crypto/zkp.proto create mode 100644 protos/src/generated/ot.rs create mode 100644 protos/src/generated/zkp.rs diff --git a/protos/crypto/ot.proto b/protos/crypto/ot.proto new file mode 100644 index 0000000..a1cbd2b --- /dev/null +++ b/protos/crypto/ot.proto @@ -0,0 +1,47 @@ +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +syntax = "proto3"; + +package com.webank.wedpr.crypto.proto; +option java_package = "com.webank.wedpr.crypto.proto"; +option java_multiple_files = true; + +// Receiver's secret to decrypt the chosen messages during k-out-of-n OT. +message ReceiverSecretKOutOfN { + bytes scalar_b = 2; +} + +// Receiver's commitment for the chosen messages during k-out-of-n OT. +message ReceiverCommitmentKOutOfN { + bytes point_x = 1; + bytes point_y = 2; + repeated bytes point_z = 3; +} + +// Sender's ciphertext item for a single encrypted message of k-out-of-n OT. +message OtCiphertextItemKOutOfN { + bytes fingerprint = 1; + bytes key_basepoint = 2; + repeated bytes encrypted_message = 3; +} + +// Sender's ciphertext collection of k-out-of-n OT. +message OtCiphertextsKOutOfN { + repeated OtCiphertextItemKOutOfN ciphertext = 1; +} + +// Pair of id and message bytes. +message BytesToBytesPair { + bytes id = 1; + bytes message = 2; +} + +// Dict of id and message bytes. +message DataDict { + repeated BytesToBytesPair pair = 1; +} + +// List of ids. +message IdList { + repeated bytes id = 1; +} \ No newline at end of file diff --git a/protos/crypto/zkp.proto b/protos/crypto/zkp.proto new file mode 100644 index 0000000..7072cee --- /dev/null +++ b/protos/crypto/zkp.proto @@ -0,0 +1,33 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +syntax = "proto3"; + +package com.webank.wedpr.crypto.proto; +option java_package = "com.webank.wedpr.crypto.proto"; +option java_multiple_files = true; + +// ZKP data to verify the balance relationship among value commitments. +// For example, given C(x), C(y), C(z), this proof data can be used to +// verify whether x * y =? z. +message BalanceProof { + bytes t1 = 1; + bytes t2 = 2; + bytes t3 = 3; + bytes m1 = 4; + bytes m2 = 5; + bytes m3 = 6; + bytes m4 = 7; + bytes m5 = 8; + bytes m6 = 9; + bytes check1 = 10; + bytes check2 = 11; +} + +// ZKP data to verify the equality relationship among value commitments. +// For example, given C(x), C(y), this proof data can be used to +// verify whether x =? y. +message EqualityProof { + bytes m1 = 1; + bytes t1 = 2; + bytes t2 = 3; +} \ No newline at end of file diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index a700ddc..6094c5b 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -1,3 +1,5 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. pub mod common; +pub mod ot; +pub mod zkp; \ No newline at end of file diff --git a/protos/src/generated/ot.rs b/protos/src/generated/ot.rs new file mode 100644 index 0000000..47cba76 --- /dev/null +++ b/protos/src/generated/ot.rs @@ -0,0 +1,1390 @@ +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `crypto/ot.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct ReceiverSecretKOutOfN { + // message fields + pub scalar_b: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a ReceiverSecretKOutOfN { + fn default() -> &'a ReceiverSecretKOutOfN { + ::default_instance() + } +} + +impl ReceiverSecretKOutOfN { + pub fn new() -> ReceiverSecretKOutOfN { + ::std::default::Default::default() + } + + // bytes scalar_b = 2; + + + pub fn get_scalar_b(&self) -> &[u8] { + &self.scalar_b + } + pub fn clear_scalar_b(&mut self) { + self.scalar_b.clear(); + } + + // Param is passed by value, moved + pub fn set_scalar_b(&mut self, v: ::std::vec::Vec) { + self.scalar_b = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_scalar_b(&mut self) -> &mut ::std::vec::Vec { + &mut self.scalar_b + } + + // Take field + pub fn take_scalar_b(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.scalar_b, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for ReceiverSecretKOutOfN { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.scalar_b)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.scalar_b.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.scalar_b); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.scalar_b.is_empty() { + os.write_bytes(2, &self.scalar_b)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> ReceiverSecretKOutOfN { + ReceiverSecretKOutOfN::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "scalar_b", + |m: &ReceiverSecretKOutOfN| { &m.scalar_b }, + |m: &mut ReceiverSecretKOutOfN| { &mut m.scalar_b }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "ReceiverSecretKOutOfN", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static ReceiverSecretKOutOfN { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(ReceiverSecretKOutOfN::new) + } +} + +impl ::protobuf::Clear for ReceiverSecretKOutOfN { + fn clear(&mut self) { + self.scalar_b.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ReceiverSecretKOutOfN { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ReceiverSecretKOutOfN { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct ReceiverCommitmentKOutOfN { + // message fields + pub point_x: ::std::vec::Vec, + pub point_y: ::std::vec::Vec, + pub point_z: ::protobuf::RepeatedField<::std::vec::Vec>, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a ReceiverCommitmentKOutOfN { + fn default() -> &'a ReceiverCommitmentKOutOfN { + ::default_instance() + } +} + +impl ReceiverCommitmentKOutOfN { + pub fn new() -> ReceiverCommitmentKOutOfN { + ::std::default::Default::default() + } + + // bytes point_x = 1; + + + pub fn get_point_x(&self) -> &[u8] { + &self.point_x + } + pub fn clear_point_x(&mut self) { + self.point_x.clear(); + } + + // Param is passed by value, moved + pub fn set_point_x(&mut self, v: ::std::vec::Vec) { + self.point_x = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_point_x(&mut self) -> &mut ::std::vec::Vec { + &mut self.point_x + } + + // Take field + pub fn take_point_x(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.point_x, ::std::vec::Vec::new()) + } + + // bytes point_y = 2; + + + pub fn get_point_y(&self) -> &[u8] { + &self.point_y + } + pub fn clear_point_y(&mut self) { + self.point_y.clear(); + } + + // Param is passed by value, moved + pub fn set_point_y(&mut self, v: ::std::vec::Vec) { + self.point_y = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_point_y(&mut self) -> &mut ::std::vec::Vec { + &mut self.point_y + } + + // Take field + pub fn take_point_y(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.point_y, ::std::vec::Vec::new()) + } + + // repeated bytes point_z = 3; + + + pub fn get_point_z(&self) -> &[::std::vec::Vec] { + &self.point_z + } + pub fn clear_point_z(&mut self) { + self.point_z.clear(); + } + + // Param is passed by value, moved + pub fn set_point_z(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec>) { + self.point_z = v; + } + + // Mutable pointer to the field. + pub fn mut_point_z(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { + &mut self.point_z + } + + // Take field + pub fn take_point_z(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { + ::std::mem::replace(&mut self.point_z, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for ReceiverCommitmentKOutOfN { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.point_x)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.point_y)?; + }, + 3 => { + ::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.point_z)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.point_x.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.point_x); + } + if !self.point_y.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.point_y); + } + for value in &self.point_z { + my_size += ::protobuf::rt::bytes_size(3, &value); + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.point_x.is_empty() { + os.write_bytes(1, &self.point_x)?; + } + if !self.point_y.is_empty() { + os.write_bytes(2, &self.point_y)?; + } + for v in &self.point_z { + os.write_bytes(3, &v)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> ReceiverCommitmentKOutOfN { + ReceiverCommitmentKOutOfN::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "point_x", + |m: &ReceiverCommitmentKOutOfN| { &m.point_x }, + |m: &mut ReceiverCommitmentKOutOfN| { &mut m.point_x }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "point_y", + |m: &ReceiverCommitmentKOutOfN| { &m.point_y }, + |m: &mut ReceiverCommitmentKOutOfN| { &mut m.point_y }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "point_z", + |m: &ReceiverCommitmentKOutOfN| { &m.point_z }, + |m: &mut ReceiverCommitmentKOutOfN| { &mut m.point_z }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "ReceiverCommitmentKOutOfN", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static ReceiverCommitmentKOutOfN { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(ReceiverCommitmentKOutOfN::new) + } +} + +impl ::protobuf::Clear for ReceiverCommitmentKOutOfN { + fn clear(&mut self) { + self.point_x.clear(); + self.point_y.clear(); + self.point_z.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ReceiverCommitmentKOutOfN { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ReceiverCommitmentKOutOfN { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct OtCiphertextItemKOutOfN { + // message fields + pub fingerprint: ::std::vec::Vec, + pub key_basepoint: ::std::vec::Vec, + pub encrypted_message: ::protobuf::RepeatedField<::std::vec::Vec>, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a OtCiphertextItemKOutOfN { + fn default() -> &'a OtCiphertextItemKOutOfN { + ::default_instance() + } +} + +impl OtCiphertextItemKOutOfN { + pub fn new() -> OtCiphertextItemKOutOfN { + ::std::default::Default::default() + } + + // bytes fingerprint = 1; + + + pub fn get_fingerprint(&self) -> &[u8] { + &self.fingerprint + } + pub fn clear_fingerprint(&mut self) { + self.fingerprint.clear(); + } + + // Param is passed by value, moved + pub fn set_fingerprint(&mut self, v: ::std::vec::Vec) { + self.fingerprint = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_fingerprint(&mut self) -> &mut ::std::vec::Vec { + &mut self.fingerprint + } + + // Take field + pub fn take_fingerprint(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.fingerprint, ::std::vec::Vec::new()) + } + + // bytes key_basepoint = 2; + + + pub fn get_key_basepoint(&self) -> &[u8] { + &self.key_basepoint + } + pub fn clear_key_basepoint(&mut self) { + self.key_basepoint.clear(); + } + + // Param is passed by value, moved + pub fn set_key_basepoint(&mut self, v: ::std::vec::Vec) { + self.key_basepoint = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_key_basepoint(&mut self) -> &mut ::std::vec::Vec { + &mut self.key_basepoint + } + + // Take field + pub fn take_key_basepoint(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.key_basepoint, ::std::vec::Vec::new()) + } + + // repeated bytes encrypted_message = 3; + + + pub fn get_encrypted_message(&self) -> &[::std::vec::Vec] { + &self.encrypted_message + } + pub fn clear_encrypted_message(&mut self) { + self.encrypted_message.clear(); + } + + // Param is passed by value, moved + pub fn set_encrypted_message(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec>) { + self.encrypted_message = v; + } + + // Mutable pointer to the field. + pub fn mut_encrypted_message(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { + &mut self.encrypted_message + } + + // Take field + pub fn take_encrypted_message(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { + ::std::mem::replace(&mut self.encrypted_message, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for OtCiphertextItemKOutOfN { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.fingerprint)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.key_basepoint)?; + }, + 3 => { + ::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.encrypted_message)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.fingerprint.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.fingerprint); + } + if !self.key_basepoint.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.key_basepoint); + } + for value in &self.encrypted_message { + my_size += ::protobuf::rt::bytes_size(3, &value); + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.fingerprint.is_empty() { + os.write_bytes(1, &self.fingerprint)?; + } + if !self.key_basepoint.is_empty() { + os.write_bytes(2, &self.key_basepoint)?; + } + for v in &self.encrypted_message { + os.write_bytes(3, &v)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> OtCiphertextItemKOutOfN { + OtCiphertextItemKOutOfN::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "fingerprint", + |m: &OtCiphertextItemKOutOfN| { &m.fingerprint }, + |m: &mut OtCiphertextItemKOutOfN| { &mut m.fingerprint }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "key_basepoint", + |m: &OtCiphertextItemKOutOfN| { &m.key_basepoint }, + |m: &mut OtCiphertextItemKOutOfN| { &mut m.key_basepoint }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "encrypted_message", + |m: &OtCiphertextItemKOutOfN| { &m.encrypted_message }, + |m: &mut OtCiphertextItemKOutOfN| { &mut m.encrypted_message }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "OtCiphertextItemKOutOfN", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static OtCiphertextItemKOutOfN { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(OtCiphertextItemKOutOfN::new) + } +} + +impl ::protobuf::Clear for OtCiphertextItemKOutOfN { + fn clear(&mut self) { + self.fingerprint.clear(); + self.key_basepoint.clear(); + self.encrypted_message.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for OtCiphertextItemKOutOfN { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for OtCiphertextItemKOutOfN { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct OtCiphertextsKOutOfN { + // message fields + pub ciphertext: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a OtCiphertextsKOutOfN { + fn default() -> &'a OtCiphertextsKOutOfN { + ::default_instance() + } +} + +impl OtCiphertextsKOutOfN { + pub fn new() -> OtCiphertextsKOutOfN { + ::std::default::Default::default() + } + + // repeated .com.webank.wedpr.crypto.proto.OtCiphertextItemKOutOfN ciphertext = 1; + + + pub fn get_ciphertext(&self) -> &[OtCiphertextItemKOutOfN] { + &self.ciphertext + } + pub fn clear_ciphertext(&mut self) { + self.ciphertext.clear(); + } + + // Param is passed by value, moved + pub fn set_ciphertext(&mut self, v: ::protobuf::RepeatedField) { + self.ciphertext = v; + } + + // Mutable pointer to the field. + pub fn mut_ciphertext(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.ciphertext + } + + // Take field + pub fn take_ciphertext(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.ciphertext, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for OtCiphertextsKOutOfN { + fn is_initialized(&self) -> bool { + for v in &self.ciphertext { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.ciphertext)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.ciphertext { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.ciphertext { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> OtCiphertextsKOutOfN { + OtCiphertextsKOutOfN::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ciphertext", + |m: &OtCiphertextsKOutOfN| { &m.ciphertext }, + |m: &mut OtCiphertextsKOutOfN| { &mut m.ciphertext }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "OtCiphertextsKOutOfN", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static OtCiphertextsKOutOfN { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(OtCiphertextsKOutOfN::new) + } +} + +impl ::protobuf::Clear for OtCiphertextsKOutOfN { + fn clear(&mut self) { + self.ciphertext.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for OtCiphertextsKOutOfN { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for OtCiphertextsKOutOfN { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct BytesToBytesPair { + // message fields + pub id: ::std::vec::Vec, + pub message: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a BytesToBytesPair { + fn default() -> &'a BytesToBytesPair { + ::default_instance() + } +} + +impl BytesToBytesPair { + pub fn new() -> BytesToBytesPair { + ::std::default::Default::default() + } + + // bytes id = 1; + + + pub fn get_id(&self) -> &[u8] { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::vec::Vec) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::vec::Vec { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.id, ::std::vec::Vec::new()) + } + + // bytes message = 2; + + + pub fn get_message(&self) -> &[u8] { + &self.message + } + pub fn clear_message(&mut self) { + self.message.clear(); + } + + // Param is passed by value, moved + pub fn set_message(&mut self, v: ::std::vec::Vec) { + self.message = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_message(&mut self) -> &mut ::std::vec::Vec { + &mut self.message + } + + // Take field + pub fn take_message(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.message, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for BytesToBytesPair { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.message)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.id); + } + if !self.message.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.message); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_bytes(1, &self.id)?; + } + if !self.message.is_empty() { + os.write_bytes(2, &self.message)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> BytesToBytesPair { + BytesToBytesPair::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "id", + |m: &BytesToBytesPair| { &m.id }, + |m: &mut BytesToBytesPair| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "message", + |m: &BytesToBytesPair| { &m.message }, + |m: &mut BytesToBytesPair| { &mut m.message }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "BytesToBytesPair", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static BytesToBytesPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(BytesToBytesPair::new) + } +} + +impl ::protobuf::Clear for BytesToBytesPair { + fn clear(&mut self) { + self.id.clear(); + self.message.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for BytesToBytesPair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for BytesToBytesPair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct DataDict { + // message fields + pub pair: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a DataDict { + fn default() -> &'a DataDict { + ::default_instance() + } +} + +impl DataDict { + pub fn new() -> DataDict { + ::std::default::Default::default() + } + + // repeated .com.webank.wedpr.crypto.proto.BytesToBytesPair pair = 1; + + + pub fn get_pair(&self) -> &[BytesToBytesPair] { + &self.pair + } + pub fn clear_pair(&mut self) { + self.pair.clear(); + } + + // Param is passed by value, moved + pub fn set_pair(&mut self, v: ::protobuf::RepeatedField) { + self.pair = v; + } + + // Mutable pointer to the field. + pub fn mut_pair(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.pair + } + + // Take field + pub fn take_pair(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.pair, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for DataDict { + fn is_initialized(&self) -> bool { + for v in &self.pair { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.pair)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.pair { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.pair { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> DataDict { + DataDict::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "pair", + |m: &DataDict| { &m.pair }, + |m: &mut DataDict| { &mut m.pair }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DataDict", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static DataDict { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DataDict::new) + } +} + +impl ::protobuf::Clear for DataDict { + fn clear(&mut self) { + self.pair.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for DataDict { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for DataDict { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct IdList { + // message fields + pub id: ::protobuf::RepeatedField<::std::vec::Vec>, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a IdList { + fn default() -> &'a IdList { + ::default_instance() + } +} + +impl IdList { + pub fn new() -> IdList { + ::std::default::Default::default() + } + + // repeated bytes id = 1; + + + pub fn get_id(&self) -> &[::std::vec::Vec] { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec>) { + self.id = v; + } + + // Mutable pointer to the field. + pub fn mut_id(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { + ::std::mem::replace(&mut self.id, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for IdList { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.id)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.id { + my_size += ::protobuf::rt::bytes_size(1, &value); + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.id { + os.write_bytes(1, &v)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> IdList { + IdList::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "id", + |m: &IdList| { &m.id }, + |m: &mut IdList| { &mut m.id }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "IdList", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static IdList { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(IdList::new) + } +} + +impl ::protobuf::Clear for IdList { + fn clear(&mut self) { + self.id.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for IdList { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for IdList { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x0fcrypto/ot.proto\x12\x1dcom.webank.wedpr.crypto.proto\"2\n\x15Recei\ + verSecretKOutOfN\x12\x19\n\x08scalar_b\x18\x02\x20\x01(\x0cR\x07scalarB\ + \"f\n\x19ReceiverCommitmentKOutOfN\x12\x17\n\x07point_x\x18\x01\x20\x01(\ + \x0cR\x06pointX\x12\x17\n\x07point_y\x18\x02\x20\x01(\x0cR\x06pointY\x12\ + \x17\n\x07point_z\x18\x03\x20\x03(\x0cR\x06pointZ\"\x8d\x01\n\x17OtCiphe\ + rtextItemKOutOfN\x12\x20\n\x0bfingerprint\x18\x01\x20\x01(\x0cR\x0bfinge\ + rprint\x12#\n\rkey_basepoint\x18\x02\x20\x01(\x0cR\x0ckeyBasepoint\x12+\ + \n\x11encrypted_message\x18\x03\x20\x03(\x0cR\x10encryptedMessage\"n\n\ + \x14OtCiphertextsKOutOfN\x12V\n\nciphertext\x18\x01\x20\x03(\x0b26.com.w\ + ebank.wedpr.crypto.proto.OtCiphertextItemKOutOfNR\nciphertext\"<\n\x10By\ + tesToBytesPair\x12\x0e\n\x02id\x18\x01\x20\x01(\x0cR\x02id\x12\x18\n\x07\ + message\x18\x02\x20\x01(\x0cR\x07message\"O\n\x08DataDict\x12C\n\x04pair\ + \x18\x01\x20\x03(\x0b2/.com.webank.wedpr.crypto.proto.BytesToBytesPairR\ + \x04pair\"\x18\n\x06IdList\x12\x0e\n\x02id\x18\x01\x20\x03(\x0cR\x02idB!\ + \n\x1dcom.webank.wedpr.crypto.protoP\x01b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} \ No newline at end of file diff --git a/protos/src/generated/zkp.rs b/protos/src/generated/zkp.rs new file mode 100644 index 0000000..7a706d7 --- /dev/null +++ b/protos/src/generated/zkp.rs @@ -0,0 +1,875 @@ +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `crypto/zkp.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct BalanceProof { + // message fields + pub t1: ::std::vec::Vec, + pub t2: ::std::vec::Vec, + pub t3: ::std::vec::Vec, + pub m1: ::std::vec::Vec, + pub m2: ::std::vec::Vec, + pub m3: ::std::vec::Vec, + pub m4: ::std::vec::Vec, + pub m5: ::std::vec::Vec, + pub m6: ::std::vec::Vec, + pub check1: ::std::vec::Vec, + pub check2: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a BalanceProof { + fn default() -> &'a BalanceProof { + ::default_instance() + } +} + +impl BalanceProof { + pub fn new() -> BalanceProof { + ::std::default::Default::default() + } + + // bytes t1 = 1; + + + pub fn get_t1(&self) -> &[u8] { + &self.t1 + } + pub fn clear_t1(&mut self) { + self.t1.clear(); + } + + // Param is passed by value, moved + pub fn set_t1(&mut self, v: ::std::vec::Vec) { + self.t1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_t1(&mut self) -> &mut ::std::vec::Vec { + &mut self.t1 + } + + // Take field + pub fn take_t1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.t1, ::std::vec::Vec::new()) + } + + // bytes t2 = 2; + + + pub fn get_t2(&self) -> &[u8] { + &self.t2 + } + pub fn clear_t2(&mut self) { + self.t2.clear(); + } + + // Param is passed by value, moved + pub fn set_t2(&mut self, v: ::std::vec::Vec) { + self.t2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_t2(&mut self) -> &mut ::std::vec::Vec { + &mut self.t2 + } + + // Take field + pub fn take_t2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.t2, ::std::vec::Vec::new()) + } + + // bytes t3 = 3; + + + pub fn get_t3(&self) -> &[u8] { + &self.t3 + } + pub fn clear_t3(&mut self) { + self.t3.clear(); + } + + // Param is passed by value, moved + pub fn set_t3(&mut self, v: ::std::vec::Vec) { + self.t3 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_t3(&mut self) -> &mut ::std::vec::Vec { + &mut self.t3 + } + + // Take field + pub fn take_t3(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.t3, ::std::vec::Vec::new()) + } + + // bytes m1 = 4; + + + pub fn get_m1(&self) -> &[u8] { + &self.m1 + } + pub fn clear_m1(&mut self) { + self.m1.clear(); + } + + // Param is passed by value, moved + pub fn set_m1(&mut self, v: ::std::vec::Vec) { + self.m1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m1(&mut self) -> &mut ::std::vec::Vec { + &mut self.m1 + } + + // Take field + pub fn take_m1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m1, ::std::vec::Vec::new()) + } + + // bytes m2 = 5; + + + pub fn get_m2(&self) -> &[u8] { + &self.m2 + } + pub fn clear_m2(&mut self) { + self.m2.clear(); + } + + // Param is passed by value, moved + pub fn set_m2(&mut self, v: ::std::vec::Vec) { + self.m2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m2(&mut self) -> &mut ::std::vec::Vec { + &mut self.m2 + } + + // Take field + pub fn take_m2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m2, ::std::vec::Vec::new()) + } + + // bytes m3 = 6; + + + pub fn get_m3(&self) -> &[u8] { + &self.m3 + } + pub fn clear_m3(&mut self) { + self.m3.clear(); + } + + // Param is passed by value, moved + pub fn set_m3(&mut self, v: ::std::vec::Vec) { + self.m3 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m3(&mut self) -> &mut ::std::vec::Vec { + &mut self.m3 + } + + // Take field + pub fn take_m3(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m3, ::std::vec::Vec::new()) + } + + // bytes m4 = 7; + + + pub fn get_m4(&self) -> &[u8] { + &self.m4 + } + pub fn clear_m4(&mut self) { + self.m4.clear(); + } + + // Param is passed by value, moved + pub fn set_m4(&mut self, v: ::std::vec::Vec) { + self.m4 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m4(&mut self) -> &mut ::std::vec::Vec { + &mut self.m4 + } + + // Take field + pub fn take_m4(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m4, ::std::vec::Vec::new()) + } + + // bytes m5 = 8; + + + pub fn get_m5(&self) -> &[u8] { + &self.m5 + } + pub fn clear_m5(&mut self) { + self.m5.clear(); + } + + // Param is passed by value, moved + pub fn set_m5(&mut self, v: ::std::vec::Vec) { + self.m5 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m5(&mut self) -> &mut ::std::vec::Vec { + &mut self.m5 + } + + // Take field + pub fn take_m5(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m5, ::std::vec::Vec::new()) + } + + // bytes m6 = 9; + + + pub fn get_m6(&self) -> &[u8] { + &self.m6 + } + pub fn clear_m6(&mut self) { + self.m6.clear(); + } + + // Param is passed by value, moved + pub fn set_m6(&mut self, v: ::std::vec::Vec) { + self.m6 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m6(&mut self) -> &mut ::std::vec::Vec { + &mut self.m6 + } + + // Take field + pub fn take_m6(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m6, ::std::vec::Vec::new()) + } + + // bytes check1 = 10; + + + pub fn get_check1(&self) -> &[u8] { + &self.check1 + } + pub fn clear_check1(&mut self) { + self.check1.clear(); + } + + // Param is passed by value, moved + pub fn set_check1(&mut self, v: ::std::vec::Vec) { + self.check1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_check1(&mut self) -> &mut ::std::vec::Vec { + &mut self.check1 + } + + // Take field + pub fn take_check1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.check1, ::std::vec::Vec::new()) + } + + // bytes check2 = 11; + + + pub fn get_check2(&self) -> &[u8] { + &self.check2 + } + pub fn clear_check2(&mut self) { + self.check2.clear(); + } + + // Param is passed by value, moved + pub fn set_check2(&mut self, v: ::std::vec::Vec) { + self.check2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_check2(&mut self) -> &mut ::std::vec::Vec { + &mut self.check2 + } + + // Take field + pub fn take_check2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.check2, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for BalanceProof { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.t1)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.t2)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.t3)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m1)?; + }, + 5 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m2)?; + }, + 6 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m3)?; + }, + 7 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m4)?; + }, + 8 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m5)?; + }, + 9 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m6)?; + }, + 10 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.check1)?; + }, + 11 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.check2)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.t1.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.t1); + } + if !self.t2.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.t2); + } + if !self.t3.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.t3); + } + if !self.m1.is_empty() { + my_size += ::protobuf::rt::bytes_size(4, &self.m1); + } + if !self.m2.is_empty() { + my_size += ::protobuf::rt::bytes_size(5, &self.m2); + } + if !self.m3.is_empty() { + my_size += ::protobuf::rt::bytes_size(6, &self.m3); + } + if !self.m4.is_empty() { + my_size += ::protobuf::rt::bytes_size(7, &self.m4); + } + if !self.m5.is_empty() { + my_size += ::protobuf::rt::bytes_size(8, &self.m5); + } + if !self.m6.is_empty() { + my_size += ::protobuf::rt::bytes_size(9, &self.m6); + } + if !self.check1.is_empty() { + my_size += ::protobuf::rt::bytes_size(10, &self.check1); + } + if !self.check2.is_empty() { + my_size += ::protobuf::rt::bytes_size(11, &self.check2); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.t1.is_empty() { + os.write_bytes(1, &self.t1)?; + } + if !self.t2.is_empty() { + os.write_bytes(2, &self.t2)?; + } + if !self.t3.is_empty() { + os.write_bytes(3, &self.t3)?; + } + if !self.m1.is_empty() { + os.write_bytes(4, &self.m1)?; + } + if !self.m2.is_empty() { + os.write_bytes(5, &self.m2)?; + } + if !self.m3.is_empty() { + os.write_bytes(6, &self.m3)?; + } + if !self.m4.is_empty() { + os.write_bytes(7, &self.m4)?; + } + if !self.m5.is_empty() { + os.write_bytes(8, &self.m5)?; + } + if !self.m6.is_empty() { + os.write_bytes(9, &self.m6)?; + } + if !self.check1.is_empty() { + os.write_bytes(10, &self.check1)?; + } + if !self.check2.is_empty() { + os.write_bytes(11, &self.check2)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> BalanceProof { + BalanceProof::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "t1", + |m: &BalanceProof| { &m.t1 }, + |m: &mut BalanceProof| { &mut m.t1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "t2", + |m: &BalanceProof| { &m.t2 }, + |m: &mut BalanceProof| { &mut m.t2 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "t3", + |m: &BalanceProof| { &m.t3 }, + |m: &mut BalanceProof| { &mut m.t3 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m1", + |m: &BalanceProof| { &m.m1 }, + |m: &mut BalanceProof| { &mut m.m1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m2", + |m: &BalanceProof| { &m.m2 }, + |m: &mut BalanceProof| { &mut m.m2 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m3", + |m: &BalanceProof| { &m.m3 }, + |m: &mut BalanceProof| { &mut m.m3 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m4", + |m: &BalanceProof| { &m.m4 }, + |m: &mut BalanceProof| { &mut m.m4 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m5", + |m: &BalanceProof| { &m.m5 }, + |m: &mut BalanceProof| { &mut m.m5 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m6", + |m: &BalanceProof| { &m.m6 }, + |m: &mut BalanceProof| { &mut m.m6 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "check1", + |m: &BalanceProof| { &m.check1 }, + |m: &mut BalanceProof| { &mut m.check1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "check2", + |m: &BalanceProof| { &m.check2 }, + |m: &mut BalanceProof| { &mut m.check2 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "BalanceProof", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static BalanceProof { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(BalanceProof::new) + } +} + +impl ::protobuf::Clear for BalanceProof { + fn clear(&mut self) { + self.t1.clear(); + self.t2.clear(); + self.t3.clear(); + self.m1.clear(); + self.m2.clear(); + self.m3.clear(); + self.m4.clear(); + self.m5.clear(); + self.m6.clear(); + self.check1.clear(); + self.check2.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for BalanceProof { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for BalanceProof { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct EqualityProof { + // message fields + pub m1: ::std::vec::Vec, + pub t1: ::std::vec::Vec, + pub t2: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a EqualityProof { + fn default() -> &'a EqualityProof { + ::default_instance() + } +} + +impl EqualityProof { + pub fn new() -> EqualityProof { + ::std::default::Default::default() + } + + // bytes m1 = 1; + + + pub fn get_m1(&self) -> &[u8] { + &self.m1 + } + pub fn clear_m1(&mut self) { + self.m1.clear(); + } + + // Param is passed by value, moved + pub fn set_m1(&mut self, v: ::std::vec::Vec) { + self.m1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_m1(&mut self) -> &mut ::std::vec::Vec { + &mut self.m1 + } + + // Take field + pub fn take_m1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.m1, ::std::vec::Vec::new()) + } + + // bytes t1 = 2; + + + pub fn get_t1(&self) -> &[u8] { + &self.t1 + } + pub fn clear_t1(&mut self) { + self.t1.clear(); + } + + // Param is passed by value, moved + pub fn set_t1(&mut self, v: ::std::vec::Vec) { + self.t1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_t1(&mut self) -> &mut ::std::vec::Vec { + &mut self.t1 + } + + // Take field + pub fn take_t1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.t1, ::std::vec::Vec::new()) + } + + // bytes t2 = 3; + + + pub fn get_t2(&self) -> &[u8] { + &self.t2 + } + pub fn clear_t2(&mut self) { + self.t2.clear(); + } + + // Param is passed by value, moved + pub fn set_t2(&mut self, v: ::std::vec::Vec) { + self.t2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_t2(&mut self) -> &mut ::std::vec::Vec { + &mut self.t2 + } + + // Take field + pub fn take_t2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.t2, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for EqualityProof { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.m1)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.t1)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.t2)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.m1.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.m1); + } + if !self.t1.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.t1); + } + if !self.t2.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.t2); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.m1.is_empty() { + os.write_bytes(1, &self.m1)?; + } + if !self.t1.is_empty() { + os.write_bytes(2, &self.t1)?; + } + if !self.t2.is_empty() { + os.write_bytes(3, &self.t2)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> EqualityProof { + EqualityProof::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "m1", + |m: &EqualityProof| { &m.m1 }, + |m: &mut EqualityProof| { &mut m.m1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "t1", + |m: &EqualityProof| { &m.t1 }, + |m: &mut EqualityProof| { &mut m.t1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "t2", + |m: &EqualityProof| { &m.t2 }, + |m: &mut EqualityProof| { &mut m.t2 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "EqualityProof", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static EqualityProof { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(EqualityProof::new) + } +} + +impl ::protobuf::Clear for EqualityProof { + fn clear(&mut self) { + self.m1.clear(); + self.t1.clear(); + self.t2.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for EqualityProof { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for EqualityProof { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10crypto/zkp.proto\x12\x1dcom.webank.wedpr.crypto.proto\"\xce\x01\n\ + \x0cBalanceProof\x12\x0e\n\x02t1\x18\x01\x20\x01(\x0cR\x02t1\x12\x0e\n\ + \x02t2\x18\x02\x20\x01(\x0cR\x02t2\x12\x0e\n\x02t3\x18\x03\x20\x01(\x0cR\ + \x02t3\x12\x0e\n\x02m1\x18\x04\x20\x01(\x0cR\x02m1\x12\x0e\n\x02m2\x18\ + \x05\x20\x01(\x0cR\x02m2\x12\x0e\n\x02m3\x18\x06\x20\x01(\x0cR\x02m3\x12\ + \x0e\n\x02m4\x18\x07\x20\x01(\x0cR\x02m4\x12\x0e\n\x02m5\x18\x08\x20\x01\ + (\x0cR\x02m5\x12\x0e\n\x02m6\x18\t\x20\x01(\x0cR\x02m6\x12\x16\n\x06chec\ + k1\x18\n\x20\x01(\x0cR\x06check1\x12\x16\n\x06check2\x18\x0b\x20\x01(\ + \x0cR\x06check2\"?\n\rEqualityProof\x12\x0e\n\x02m1\x18\x01\x20\x01(\x0c\ + R\x02m1\x12\x0e\n\x02t1\x18\x02\x20\x01(\x0cR\x02t1\x12\x0e\n\x02t2\x18\ + \x03\x20\x01(\x0cR\x02t2B!\n\x1dcom.webank.wedpr.crypto.protoP\x01b\x06p\ + roto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} \ No newline at end of file From 40a2673c547ce813d51252ae21db3a96a82df92e Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Thu, 27 Jul 2023 11:04:08 +0800 Subject: [PATCH 2/8] add ecdh-psi wasm && jni interface --- Cargo.lock | 219 ++++++++++++++---- Cargo.toml | 3 + .../signature/secp256k1/benches/secp256k1.rs | 17 +- crypto/signature/secp256k1/src/lib.rs | 23 +- protos/src/generated/mod.rs | 2 +- .../ecdh_psi/ffi_java_ecdh_psi/Cargo.toml | 14 ++ .../ecdh_psi/ffi_java_ecdh_psi/src/lib.rs | 95 ++++++++ .../ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml | 14 ++ .../ecdh_psi/ffi_wasm_ecdh_psi/readme.md | 17 ++ .../ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs | 26 +++ third_party/ecdh_psi/psi_utils/Cargo.toml | 13 ++ third_party/ecdh_psi/psi_utils/src/lib.rs | 97 ++++++++ 12 files changed, 478 insertions(+), 62 deletions(-) create mode 100644 third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml create mode 100644 third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs create mode 100644 third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml create mode 100644 third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md create mode 100644 third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs create mode 100644 third_party/ecdh_psi/psi_utils/Cargo.toml create mode 100644 third_party/ecdh_psi/psi_utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 5c1b76f..e26b171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,15 @@ dependencies = [ "generic-array 0.14.4", ] +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "block-modes" version = "0.7.0" @@ -260,7 +269,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" dependencies = [ - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -275,7 +284,7 @@ dependencies = [ "quote", "serde", "serde_json", - "syn", + "syn 1.0.68", "tempfile", "toml", ] @@ -368,6 +377,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + [[package]] name = "criterion" version = "0.3.4" @@ -455,6 +473,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array 0.14.4", + "typenum", +] + [[package]] name = "crypto-mac" version = "0.8.0" @@ -524,6 +552,35 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures 0.2.9", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rand_core 0.6.4", + "rustc_version 0.4.0", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "digest" version = "0.6.2" @@ -551,6 +608,16 @@ dependencies = [ "generic-array 0.14.4", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", +] + [[package]] name = "ed25519" version = "1.0.3" @@ -694,7 +761,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", "synstructure", ] @@ -733,6 +800,29 @@ dependencies = [ "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ffi_java_ecdh_psi" +version = "0.1.0" +dependencies = [ + "jni", + "psi_utils", +] + +[[package]] +name = "ffi_wasm_ecdh_psi" +version = "0.1.0" +dependencies = [ + "getrandom 0.2.2", + "psi_utils", + "wasm-bindgen", +] + +[[package]] +name = "fiat-crypto" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" + [[package]] name = "foreign-types" version = "0.3.2" @@ -808,8 +898,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -1176,6 +1268,12 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "platforms" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" + [[package]] name = "plotters" version = "0.3.0" @@ -1212,11 +1310,11 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1256,11 +1354,21 @@ dependencies = [ "tempfile", ] +[[package]] +name = "psi_utils" +version = "0.1.0" +dependencies = [ + "curve25519-dalek 4.0.0", + "rand 0.8.5", + "rand_core 0.6.4", + "sha2 0.10.7", +] + [[package]] name = "quote" -version = "1.0.7" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -1322,14 +1430,13 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", + "rand_core 0.6.4", ] [[package]] @@ -1359,7 +1466,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", + "rand_core 0.6.4", ] [[package]] @@ -1388,9 +1495,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.2", ] @@ -1413,15 +1520,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", -] - [[package]] name = "rand_isaac" version = "0.1.1" @@ -1589,7 +1687,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.18", ] [[package]] @@ -1619,7 +1726,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4124a35fe33ae14259c490fd70fa199a32b9ce9502f2ee6bc4f81ec06fa65894" dependencies = [ - "rand 0.8.3", + "rand 0.8.5", "secp256k1-sys", ] @@ -1655,6 +1762,12 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + [[package]] name = "semver-parser" version = "0.7.0" @@ -1688,7 +1801,7 @@ checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", ] [[package]] @@ -1723,11 +1836,22 @@ checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.1.5", "digest 0.9.0", "opaque-debug 0.3.0", ] +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures 0.2.9", + "digest 0.10.7", +] + [[package]] name = "sha3" version = "0.6.0" @@ -1821,6 +1945,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "synstructure" version = "0.12.4" @@ -1829,7 +1964,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", "unicode-xid", ] @@ -1873,7 +2008,7 @@ checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", ] [[package]] @@ -1897,9 +2032,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.12.0" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-ident" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-width" @@ -1990,7 +2131,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 1.0.68", "wasm-bindgen-shared", ] @@ -2012,7 +2153,7 @@ checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2284,7 +2425,7 @@ version = "1.0.0" dependencies = [ "aes", "block-modes", - "rand 0.8.3", + "rand 0.8.5", "wedpr_l_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2297,7 +2438,7 @@ checksum = "a95a60c1f481a6d8303dd052437738720676de98c3771691df67d07e2c1115f2" dependencies = [ "aes", "block-modes", - "rand 0.8.3", + "rand 0.8.5", "wedpr_l_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2307,7 +2448,7 @@ name = "wedpr_l_crypto_block_cipher_sm4" version = "1.0.0" dependencies = [ "block-modes", - "rand 0.8.3", + "rand 0.8.5", "sm4", "wedpr_l_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2320,7 +2461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cb1235aa887c4f65d160d33fab200382edfd596732b86b50334ebe444abdbd" dependencies = [ "block-modes", - "rand 0.8.3", + "rand 0.8.5", "sm4", "wedpr_l_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2714,6 +2855,6 @@ checksum = "c3f369ddb18862aba61aa49bf31e74d29f0f162dec753063200e1dc084345d16" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.68", "synstructure", ] diff --git a/Cargo.toml b/Cargo.toml index 767d4d4..09b917f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,4 +34,7 @@ members = [ "protos", "third_party/fisco_bcos", "third_party/fisco_bcos_java_sdk", + "third_party/ecdh_psi/psi_utils", + "third_party/ecdh_psi/ffi_java_ecdh_psi", + "third_party/ecdh_psi/ffi_wasm_ecdh_psi", ] diff --git a/crypto/signature/secp256k1/benches/secp256k1.rs b/crypto/signature/secp256k1/benches/secp256k1.rs index 7cd7e75..073aafa 100644 --- a/crypto/signature/secp256k1/benches/secp256k1.rs +++ b/crypto/signature/secp256k1/benches/secp256k1.rs @@ -1,16 +1,16 @@ // Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. use criterion::Criterion; -use wedpr_l_crypto_signature_secp256k1::{WedprSecp256k1Recover}; -use wedpr_l_utils::traits::Signature; -use wedpr_l_utils::constant::tests::BASE64_ENCODED_TEST_MESSAGE; +use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; +use wedpr_l_utils::{ + constant::tests::BASE64_ENCODED_TEST_MESSAGE, traits::Signature, +}; #[macro_use] extern crate criterion; fn create_sign_helper(c: &mut Criterion, message_size: usize) { - let label = - format!("create_sign_helper, message_size = {}", message_size); + let label = format!("create_sign_helper, message_size = {}", message_size); let secp256k1 = WedprSecp256k1Recover::default(); let (pk_b, sk_b) = secp256k1.generate_keypair(); @@ -26,8 +26,7 @@ fn create_sign_helper(c: &mut Criterion, message_size: usize) { fn create_verify_helper(c: &mut Criterion, message_size: usize) { let label = format!("create_verify_helper, message_size = {}", message_size); - let label = - format!("create_sign_helper, message_size = {}", message_size); + let label = format!("create_sign_helper, message_size = {}", message_size); let secp256k1 = WedprSecp256k1Recover::default(); let (pk_b, sk_b) = secp256k1.generate_keypair(); @@ -35,11 +34,9 @@ fn create_verify_helper(c: &mut Criterion, message_size: usize) { let sign_obj = secp256k1.sign(&sk_b, &message.to_vec()).unwrap(); - c.bench_function(&label, move |b| { b.iter(|| { - let _ = secp256k1 - .recover_public_key(&message.to_vec(), &sign_obj); + let _ = secp256k1.recover_public_key(&message.to_vec(), &sign_obj); }) }); } diff --git a/crypto/signature/secp256k1/src/lib.rs b/crypto/signature/secp256k1/src/lib.rs index afbe54b..78ad3ad 100644 --- a/crypto/signature/secp256k1/src/lib.rs +++ b/crypto/signature/secp256k1/src/lib.rs @@ -9,11 +9,11 @@ extern crate lazy_static; extern crate secp256k1; use secp256k1::{ + ecdsa::{RecoverableSignature, RecoveryId}, + rand::rngs::OsRng, All, Message, PublicKey, Secp256k1, SecretKey, VerifyOnly, }; -use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; use wedpr_l_utils::{error::WedprError, traits::Signature}; -use secp256k1::rand::rngs::OsRng; lazy_static! { // Shared secp256k1 instance initialized for verification function only. @@ -22,7 +22,6 @@ lazy_static! { static ref SECP256K1_ALL: Secp256k1 = Secp256k1::new(); } - /// Implements FISCO-BCOS-compatible Secp256k1 as a Signature instance. #[derive(Default, Debug, Clone, Copy)] pub struct WedprSecp256k1Recover {} @@ -99,7 +98,6 @@ impl Signature for WedprSecp256k1Recover { fn generate_keypair(&self) -> (Vec, Vec) { loop { - let (secret_key, public_key) = SECP256K1_ALL.generate_keypair(&mut OsRng); @@ -155,14 +153,15 @@ impl WedprSecp256k1Recover { return Err(WedprError::FormatError); }, }; - let recovered_public_key = - match SECP256K1_VERIFY.recover_ecdsa(&msg_hash_obj, &get_sign_final) { - Ok(v) => v, - Err(_) => { - wedpr_println!("Signature recover failed"); - return Err(WedprError::FormatError); - }, - }; + let recovered_public_key = match SECP256K1_VERIFY + .recover_ecdsa(&msg_hash_obj, &get_sign_final) + { + Ok(v) => v, + Err(_) => { + wedpr_println!("Signature recover failed"); + return Err(WedprError::FormatError); + }, + }; return Ok(recovered_public_key.serialize_uncompressed().to_vec()); } diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index 6094c5b..b79093b 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -2,4 +2,4 @@ pub mod common; pub mod ot; -pub mod zkp; \ No newline at end of file +pub mod zkp; diff --git a/third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml b/third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml new file mode 100644 index 0000000..2e83eac --- /dev/null +++ b/third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ffi_java_ecdh_psi" +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" +crate-type = [ "cdylib", "staticlib" ] + +[dependencies] +jni = "0.13.0" +psi_utils = { path = "../psi_utils"} \ No newline at end of file diff --git a/third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs b/third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs new file mode 100644 index 0000000..1554822 --- /dev/null +++ b/third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs @@ -0,0 +1,95 @@ +extern crate jni; + +use psi_utils::{ + hash_to_curve, point_scalar_multi, random_scalar, scalar_inverse, +}; + +use jni::{objects::JClass, sys::jbyteArray, JNIEnv}; + +// 导出函数给JNI接口调用 + +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_randomScalar( + env: JNIEnv, + _class: JClass, +) -> jbyteArray { + // 调用原始函数 + let result = random_scalar(); + + // 将 Vec 转换成 jbyteArray 并返回给Java层 + match env.byte_array_from_slice(&result) { + Ok(array) => array, + Err(_) => env.new_byte_array(0).unwrap(), // 返回空的 jbyteArray + } +} + +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_hashToCurve( + env: JNIEnv, + _class: JClass, + message: jbyteArray, +) -> jbyteArray { + // 将 jbyteArray 转换成 Vec + let message_bytes = match env.convert_byte_array(message) { + Ok(bytes) => bytes, + Err(_) => return env.new_byte_array(0).unwrap(), /* 返回空的 jbyteArray */ + }; + + // 调用原始函数 + let result = hash_to_curve(&message_bytes); + + // 将 Vec 转换成 jbyteArray 并返回给Java层 + match env.byte_array_from_slice(&result) { + Ok(array) => array, + Err(_) => env.new_byte_array(0).unwrap(), // 返回空的 jbyteArray + } +} + +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_scalarInverse( + env: JNIEnv, + _class: JClass, + scalar: jbyteArray, +) -> jbyteArray { + // 将 jbyteArray 转换成 Vec + let scalar_bytes = match env.convert_byte_array(scalar) { + Ok(bytes) => bytes, + Err(_) => return env.new_byte_array(0).unwrap(), /* 返回空的 jbyteArray */ + }; + + // 调用原始函数 + let result = scalar_inverse(&scalar_bytes); + + // 将 Vec 转换成 jbyteArray 并返回给Java层 + match env.byte_array_from_slice(&result) { + Ok(array) => array, + Err(_) => env.new_byte_array(0).unwrap(), // 返回空的 jbyteArray + } +} + +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_pointScalarMulti( + env: JNIEnv, + _class: JClass, + point: jbyteArray, + scalar: jbyteArray, +) -> jbyteArray { + // 将 jbyteArray 转换成 Vec + let point_bytes = match env.convert_byte_array(point) { + Ok(bytes) => bytes, + Err(_) => return env.new_byte_array(0).unwrap(), /* 返回空的 jbyteArray */ + }; + let scalar_bytes = match env.convert_byte_array(scalar) { + Ok(bytes) => bytes, + Err(_) => return env.new_byte_array(0).unwrap(), /* 返回空的 jbyteArray */ + }; + + // 调用原始函数 + let result = point_scalar_multi(&point_bytes, &scalar_bytes); + + // 将 Vec 转换成 jbyteArray 并返回给Java层 + match env.byte_array_from_slice(&result) { + Ok(array) => array, + Err(_) => env.new_byte_array(0).unwrap(), // 返回空的 jbyteArray + } +} diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml new file mode 100644 index 0000000..fcf5c79 --- /dev/null +++ b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ffi_wasm_ecdh_psi" +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" +crate-type = ["rlib", "cdylib"] + +[dependencies] +wasm-bindgen = "0.2" +getrandom = { version = "0.2", features = ["js"] } +psi_utils = { path = "../psi_utils"} diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md new file mode 100644 index 0000000..0fc75a1 --- /dev/null +++ b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md @@ -0,0 +1,17 @@ +# 编译生成wasm + +`wasm-pack build`命令可以使用不同的目标参数,用于生成不同平台和环境可用的 WebAssembly(Wasm)模块。以下是`wasm-pack`库当前版本(v0.10.0)中支持的目标选项: + +1. `bundler`(默认):生成可以在现代浏览器和支持 ES6 模块的环境中使用的 Wasm 模块,打包为单个文件。 + +2. `web`:生成可以在现代浏览器中直接使用的 Wasm 模块,打包为单个文件。 + +3. `no-modules`:生成不依赖 ES6 模块的 Wasm 输出,适用于在没有模块系统的环境下使用。 + +4. `nodejs`:生成可以在 Node.js 环境中使用的 Wasm 模块,使用 CommonJS 模块进行导出。 + +5. `webworker`:生成用于 Web Worker 的 Wasm 模块,打包为单个文件。 + +6. `nodejs-esm`:生成可以在支持 ES6 模块的 Node.js 环境中使用的 Wasm 模块。 + +你可以根据你的需求,选择合适的构建目标,以便在不同的环境中正确地使用和部署生成的 Wasm 模块。使用对应的`--target`选项来选择特定的目标。例如:`wasm-pack build --target web`将生成支持现代浏览器的 Wasm 模块。 \ No newline at end of file diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs new file mode 100644 index 0000000..3c1605a --- /dev/null +++ b/third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs @@ -0,0 +1,26 @@ +extern crate wasm_bindgen; + +use psi_utils::{ + hash_to_curve, point_scalar_multi, random_scalar, scalar_inverse, +}; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub fn wasm_scalar_inverse(scalar: &[u8]) -> Vec { + scalar_inverse(scalar) +} + +#[wasm_bindgen] +pub fn wasm_point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { + point_scalar_multi(point, scalar) +} + +#[wasm_bindgen] +pub fn wasm_hash_to_curve(message: &[u8]) -> Vec { + hash_to_curve(message) +} + +#[wasm_bindgen] +pub fn wasm_random_scalar() -> Vec { + random_scalar() +} diff --git a/third_party/ecdh_psi/psi_utils/Cargo.toml b/third_party/ecdh_psi/psi_utils/Cargo.toml new file mode 100644 index 0000000..d0786f0 --- /dev/null +++ b/third_party/ecdh_psi/psi_utils/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "psi_utils" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + + +[dependencies] +sha2 = "0.10.7" +rand = "0.8.4" +rand_core = "0.6.3" +curve25519-dalek = { version = "4", features = [ "digest" , "rand_core"] } diff --git a/third_party/ecdh_psi/psi_utils/src/lib.rs b/third_party/ecdh_psi/psi_utils/src/lib.rs new file mode 100644 index 0000000..243a79a --- /dev/null +++ b/third_party/ecdh_psi/psi_utils/src/lib.rs @@ -0,0 +1,97 @@ +use sha2::Sha512; +// use sha2::Digest; +use rand::rngs::ThreadRng; +// use rand::RngCore; +use curve25519_dalek::{ + edwards::{CompressedEdwardsY, EdwardsPoint}, + Scalar, +}; + +const SCALAR_SIZE: usize = 32; +const POINT_SIZE: usize = 32; + +pub fn random_scalar() -> Vec { + // 创建一个随机数生成器 + 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 { + let hash_scalar = Scalar::hash_from_bytes::(message); + let hash_point = EdwardsPoint::mul_base(&hash_scalar); + return hash_point.compress().to_bytes().to_vec(); +} + +pub fn scalar_inverse(scalar: &[u8]) -> Vec { + // 检查输入切片是否具有正确的大小 + if scalar.len() != SCALAR_SIZE { + return Vec::new(); // 如果大小不正确,返回空的 Vec + } + + // 将输入 &[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 inverse_scalar = scalar.invert(); + return inverse_scalar.to_bytes().to_vec(); +} + +pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { + // 检查输入切片是否具有正确的大小 + if point.len() != POINT_SIZE || scalar.len() != SCALAR_SIZE { + return Vec::new(); // 如果大小不正确,返回空的 Vec + } + + // 将输入 &[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] 转换成 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() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_flow() { + // 生成一个随机的标量 + let random_scalar = random_scalar(); + println!("Random Scalar: {:?}", random_scalar); + + // 定义一个消息,对其进行哈希并生成哈希点 + let message = "To really appreciate architecture, you may even need \ + to commit a murder"; + let hash_point = hash_to_curve(message.as_bytes()); + + // 定义一个标量并计算其逆元 + let inverse_scalar = scalar_inverse(&random_scalar); + + // 定义一个点和标量,并进行点乘操作 + let point_mul_result = point_scalar_multi(&hash_point, &random_scalar); + let point_mul_result2 = + point_scalar_multi(&point_mul_result, &inverse_scalar); + assert_eq!(point_mul_result2, hash_point); + } +} From 2aa980923f6521da41964d388c276b580ee21010 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Tue, 19 Sep 2023 21:32:58 +0800 Subject: [PATCH 3/8] add safe hash to curve --- third_party/ecdh_psi/psi_utils/src/lib.rs | 58 ++++++++++++++++------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/third_party/ecdh_psi/psi_utils/src/lib.rs b/third_party/ecdh_psi/psi_utils/src/lib.rs index 243a79a..22b247e 100644 --- a/third_party/ecdh_psi/psi_utils/src/lib.rs +++ b/third_party/ecdh_psi/psi_utils/src/lib.rs @@ -2,10 +2,7 @@ use sha2::Sha512; // use sha2::Digest; use rand::rngs::ThreadRng; // use rand::RngCore; -use curve25519_dalek::{ - edwards::{CompressedEdwardsY, EdwardsPoint}, - Scalar, -}; +use curve25519_dalek::{edwards::CompressedEdwardsY, Scalar}; const SCALAR_SIZE: usize = 32; const POINT_SIZE: usize = 32; @@ -22,9 +19,13 @@ pub fn random_scalar() -> Vec { } pub fn hash_to_curve(message: &[u8]) -> Vec { - let hash_scalar = Scalar::hash_from_bytes::(message); - let hash_point = EdwardsPoint::mul_base(&hash_scalar); - return hash_point.compress().to_bytes().to_vec(); + let hash_scalar = Scalar::hash_from_bytes::(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 scalar_inverse(scalar: &[u8]) -> Vec { @@ -73,25 +74,48 @@ pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { #[cfg(test)] mod tests { use super::*; + use curve25519_dalek::EdwardsPoint; + use rand::Rng; + use std::ops::Mul; #[test] fn test_flow() { // 生成一个随机的标量 - let random_scalar = random_scalar(); - println!("Random Scalar: {:?}", random_scalar); + let random_scalar1 = random_scalar(); + let random_scalar2 = random_scalar(); + println!("Random Scalar: {:?}", random_scalar1); + // 创建一个随机数生成器 + let mut rng = rand::thread_rng(); + + // 定义要生成的字节长度 + let byte_length = 16; // 例如,生成 16 字节的随机数据 + + // 生成随机字节序列 + let random_bytes: Vec = + (0..byte_length).map(|_| rng.gen()).collect(); // 定义一个消息,对其进行哈希并生成哈希点 - let message = "To really appreciate architecture, you may even need \ - to commit a murder"; - let hash_point = hash_to_curve(message.as_bytes()); + let hash_point = hash_to_curve(&random_bytes); + println!("hash_point Scalar: {:?}", hash_point); // 定义一个标量并计算其逆元 - let inverse_scalar = scalar_inverse(&random_scalar); + let inverse_scalar = scalar_inverse(&random_scalar1); + let test_scalar = Scalar::from_bytes_mod_order( + <[u8; 32]>::try_from(random_scalar1.clone()).unwrap(), + ); + let test_scalar2 = Scalar::from_bytes_mod_order( + <[u8; 32]>::try_from(inverse_scalar.clone()).unwrap(), + ); + let test3 = test_scalar.mul(test_scalar2); + println!("test3 Scalar: {:?}", test3); + let point_mul_result = + point_scalar_multi(&hash_point, &test3.to_bytes().to_vec()); + assert_eq!(point_mul_result, hash_point); // 定义一个点和标量,并进行点乘操作 - let point_mul_result = point_scalar_multi(&hash_point, &random_scalar); - let point_mul_result2 = - point_scalar_multi(&point_mul_result, &inverse_scalar); - assert_eq!(point_mul_result2, hash_point); + // let point_mul_result = point_scalar_multi(&hash_point, + // &random_scalar1); let point_mul_result2 = + // point_scalar_multi(&point_mul_result, &inverse_scalar); + // assert_eq!(point_mul_result2, hash_point); } } From dad9db9ef87c9dbb1359b4f05522891953c9a2e8 Mon Sep 17 00:00:00 2001 From: shareong <740310627@qq.com> Date: Wed, 20 Sep 2023 16:01:43 +0800 Subject: [PATCH 4/8] optimize code structure --- Cargo.lock | 28 ++-- Cargo.toml | 6 +- .../ecc/ecc_ed25519}/Cargo.toml | 2 +- crypto/ecc/ecc_ed25519/src/lib.rs | 58 +++++++++ .../ecc/ffi_java_ecc_ed25519}/Cargo.toml | 6 +- .../ecc/ffi_java_ecc_ed25519}/src/lib.rs | 26 +--- .../ecc/ffi_wasm_ecc_ed25519}/Cargo.toml | 6 +- .../ecc/ffi_wasm_ecc_ed25519}/readme.md | 0 .../ecc/ffi_wasm_ecc_ed25519}/src/lib.rs | 9 +- third_party/ecdh_psi/psi_utils/src/lib.rs | 121 ------------------ 10 files changed, 86 insertions(+), 176 deletions(-) rename {third_party/ecdh_psi/psi_utils => crypto/ecc/ecc_ed25519}/Cargo.toml (93%) create mode 100644 crypto/ecc/ecc_ed25519/src/lib.rs rename {third_party/ecdh_psi/ffi_java_ecdh_psi => crypto/ecc/ffi_java_ecc_ed25519}/Cargo.toml (68%) rename {third_party/ecdh_psi/ffi_java_ecdh_psi => crypto/ecc/ffi_java_ecc_ed25519}/src/lib.rs (73%) rename {third_party/ecdh_psi/ffi_wasm_ecdh_psi => crypto/ecc/ffi_wasm_ecc_ed25519}/Cargo.toml (72%) rename {third_party/ecdh_psi/ffi_wasm_ecdh_psi => crypto/ecc/ffi_wasm_ecc_ed25519}/readme.md (100%) rename {third_party/ecdh_psi/ffi_wasm_ecdh_psi => crypto/ecc/ffi_wasm_ecc_ed25519}/src/lib.rs (67%) delete mode 100644 third_party/ecdh_psi/psi_utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e26b171..a50c7ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,6 +618,16 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "ecc_ed25519" +version = "0.1.0" +dependencies = [ + "curve25519-dalek 4.0.0", + "rand 0.8.5", + "rand_core 0.6.4", + "sha2 0.10.7", +] + [[package]] name = "ed25519" version = "1.0.3" @@ -801,19 +811,19 @@ dependencies = [ ] [[package]] -name = "ffi_java_ecdh_psi" +name = "ffi_java_ecc_ed25519" version = "0.1.0" dependencies = [ + "ecc_ed25519", "jni", - "psi_utils", ] [[package]] -name = "ffi_wasm_ecdh_psi" +name = "ffi_wasm_ecc_ed25519" version = "0.1.0" dependencies = [ + "ecc_ed25519", "getrandom 0.2.2", - "psi_utils", "wasm-bindgen", ] @@ -1354,16 +1364,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "psi_utils" -version = "0.1.0" -dependencies = [ - "curve25519-dalek 4.0.0", - "rand 0.8.5", - "rand_core 0.6.4", - "sha2 0.10.7", -] - [[package]] name = "quote" version = "1.0.32" diff --git a/Cargo.toml b/Cargo.toml index 09b917f..40e4310 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ members = [ "protos", "third_party/fisco_bcos", "third_party/fisco_bcos_java_sdk", - "third_party/ecdh_psi/psi_utils", - "third_party/ecdh_psi/ffi_java_ecdh_psi", - "third_party/ecdh_psi/ffi_wasm_ecdh_psi", + "crypto/ecc/ecc_ed25519", + "crypto/ecc/ffi_java_ecc_ed25519", + "crypto/ecc/ffi_wasm_ecc_ed25519", ] diff --git a/third_party/ecdh_psi/psi_utils/Cargo.toml b/crypto/ecc/ecc_ed25519/Cargo.toml similarity index 93% rename from third_party/ecdh_psi/psi_utils/Cargo.toml rename to crypto/ecc/ecc_ed25519/Cargo.toml index d0786f0..dbcdf8e 100644 --- a/third_party/ecdh_psi/psi_utils/Cargo.toml +++ b/crypto/ecc/ecc_ed25519/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "psi_utils" +name = "ecc_ed25519" version = "0.1.0" edition = "2021" diff --git a/crypto/ecc/ecc_ed25519/src/lib.rs b/crypto/ecc/ecc_ed25519/src/lib.rs new file mode 100644 index 0000000..7eef815 --- /dev/null +++ b/crypto/ecc/ecc_ed25519/src/lib.rs @@ -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 { + // 创建一个随机数生成器 + 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 { + let hash_scalar = Scalar::hash_from_bytes::(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 { + // 检查输入切片是否具有正确的大小 + if point.len() != POINT_SIZE || scalar.len() != SCALAR_SIZE { + return Vec::new(); // 如果大小不正确,返回空的 Vec + } + + // 将输入 &[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] 转换成 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() +} diff --git a/third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml b/crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml similarity index 68% rename from third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml rename to crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml index 2e83eac..e6b9013 100644 --- a/third_party/ecdh_psi/ffi_java_ecdh_psi/Cargo.toml +++ b/crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml @@ -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"} \ No newline at end of file +ecc_ed25519 = { path = "../ecc_ed25519"} \ No newline at end of file diff --git a/third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs b/crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs similarity index 73% rename from third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs rename to crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs index 1554822..981dc30 100644 --- a/third_party/ecdh_psi/ffi_java_ecdh_psi/src/lib.rs +++ b/crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs @@ -1,7 +1,7 @@ extern crate jni; -use psi_utils::{ - hash_to_curve, point_scalar_multi, random_scalar, scalar_inverse, +use ecc_ed25519::{ + hash_to_curve, point_scalar_multi, random_scalar, }; use jni::{objects::JClass, sys::jbyteArray, JNIEnv}; @@ -45,28 +45,6 @@ pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_hashToCurve( } } -#[no_mangle] -pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_scalarInverse( - env: JNIEnv, - _class: JClass, - scalar: jbyteArray, -) -> jbyteArray { - // 将 jbyteArray 转换成 Vec - let scalar_bytes = match env.convert_byte_array(scalar) { - Ok(bytes) => bytes, - Err(_) => return env.new_byte_array(0).unwrap(), /* 返回空的 jbyteArray */ - }; - - // 调用原始函数 - let result = scalar_inverse(&scalar_bytes); - - // 将 Vec 转换成 jbyteArray 并返回给Java层 - match env.byte_array_from_slice(&result) { - Ok(array) => array, - Err(_) => env.new_byte_array(0).unwrap(), // 返回空的 jbyteArray - } -} - #[no_mangle] pub extern "system" fn Java_com_webank_wedpr_crypto_NativeInterface_pointScalarMulti( env: JNIEnv, diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml b/crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml similarity index 72% rename from third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml rename to crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml index fcf5c79..89e608a 100644 --- a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/Cargo.toml +++ b/crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml @@ -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"} diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md b/crypto/ecc/ffi_wasm_ecc_ed25519/readme.md similarity index 100% rename from third_party/ecdh_psi/ffi_wasm_ecdh_psi/readme.md rename to crypto/ecc/ffi_wasm_ecc_ed25519/readme.md diff --git a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs b/crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs similarity index 67% rename from third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs rename to crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs index 3c1605a..904f9c8 100644 --- a/third_party/ecdh_psi/ffi_wasm_ecdh_psi/src/lib.rs +++ b/crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs @@ -1,15 +1,10 @@ extern crate wasm_bindgen; -use psi_utils::{ - hash_to_curve, point_scalar_multi, random_scalar, scalar_inverse, +use ecc_ed25519::{ + hash_to_curve, point_scalar_multi, random_scalar, }; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] -pub fn wasm_scalar_inverse(scalar: &[u8]) -> Vec { - scalar_inverse(scalar) -} - #[wasm_bindgen] pub fn wasm_point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { point_scalar_multi(point, scalar) diff --git a/third_party/ecdh_psi/psi_utils/src/lib.rs b/third_party/ecdh_psi/psi_utils/src/lib.rs deleted file mode 100644 index 22b247e..0000000 --- a/third_party/ecdh_psi/psi_utils/src/lib.rs +++ /dev/null @@ -1,121 +0,0 @@ -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 { - // 创建一个随机数生成器 - 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 { - let hash_scalar = Scalar::hash_from_bytes::(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 scalar_inverse(scalar: &[u8]) -> Vec { - // 检查输入切片是否具有正确的大小 - if scalar.len() != SCALAR_SIZE { - return Vec::new(); // 如果大小不正确,返回空的 Vec - } - - // 将输入 &[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 inverse_scalar = scalar.invert(); - return inverse_scalar.to_bytes().to_vec(); -} - -pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { - // 检查输入切片是否具有正确的大小 - if point.len() != POINT_SIZE || scalar.len() != SCALAR_SIZE { - return Vec::new(); // 如果大小不正确,返回空的 Vec - } - - // 将输入 &[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] 转换成 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() -} - -#[cfg(test)] -mod tests { - use super::*; - use curve25519_dalek::EdwardsPoint; - use rand::Rng; - use std::ops::Mul; - - #[test] - fn test_flow() { - // 生成一个随机的标量 - let random_scalar1 = random_scalar(); - let random_scalar2 = random_scalar(); - println!("Random Scalar: {:?}", random_scalar1); - // 创建一个随机数生成器 - let mut rng = rand::thread_rng(); - - // 定义要生成的字节长度 - let byte_length = 16; // 例如,生成 16 字节的随机数据 - - // 生成随机字节序列 - let random_bytes: Vec = - (0..byte_length).map(|_| rng.gen()).collect(); - - // 定义一个消息,对其进行哈希并生成哈希点 - let hash_point = hash_to_curve(&random_bytes); - println!("hash_point Scalar: {:?}", hash_point); - - // 定义一个标量并计算其逆元 - let inverse_scalar = scalar_inverse(&random_scalar1); - let test_scalar = Scalar::from_bytes_mod_order( - <[u8; 32]>::try_from(random_scalar1.clone()).unwrap(), - ); - let test_scalar2 = Scalar::from_bytes_mod_order( - <[u8; 32]>::try_from(inverse_scalar.clone()).unwrap(), - ); - let test3 = test_scalar.mul(test_scalar2); - println!("test3 Scalar: {:?}", test3); - let point_mul_result = - point_scalar_multi(&hash_point, &test3.to_bytes().to_vec()); - assert_eq!(point_mul_result, hash_point); - - // 定义一个点和标量,并进行点乘操作 - // let point_mul_result = point_scalar_multi(&hash_point, - // &random_scalar1); let point_mul_result2 = - // point_scalar_multi(&point_mul_result, &inverse_scalar); - // assert_eq!(point_mul_result2, hash_point); - } -} From 6b6a338c3e781309ad849712f0bc8a6ed02fce12 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Wed, 20 Sep 2023 17:22:09 +0800 Subject: [PATCH 5/8] add ffi c edwards25519 --- Cargo.lock | 20 ++++++++++++++----- Cargo.toml | 7 ++++--- .../Cargo.toml | 2 +- .../src/lib.rs | 0 .../ffi_java_ecc_edwards25519}/Cargo.toml | 6 +++--- .../ffi_java_ecc_edwards25519}/src/lib.rs | 4 +--- .../ffi_wasm_ecc_edwards25519}/Cargo.toml | 6 +++--- .../ffi_wasm_ecc_edwards25519}/readme.md | 0 .../ffi_wasm_ecc_edwards25519}/src/lib.rs | 4 +--- 9 files changed, 28 insertions(+), 21 deletions(-) rename crypto/ecc/{ecc_ed25519 => ecc_edwards25519}/Cargo.toml (91%) rename crypto/ecc/{ecc_ed25519 => ecc_edwards25519}/src/lib.rs (100%) rename {crypto/ecc/ffi_java_ecc_ed25519 => ffi/ffi_java/ffi_java_ecc_edwards25519}/Cargo.toml (61%) rename {crypto/ecc/ffi_java_ecc_ed25519 => ffi/ffi_java/ffi_java_ecc_edwards25519}/src/lib.rs (96%) rename {crypto/ecc/ffi_wasm_ecc_ed25519 => ffi/ffi_wasm/ffi_wasm_ecc_edwards25519}/Cargo.toml (65%) rename {crypto/ecc/ffi_wasm_ecc_ed25519 => ffi/ffi_wasm/ffi_wasm_ecc_edwards25519}/readme.md (100%) rename {crypto/ecc/ffi_wasm_ecc_ed25519 => ffi/ffi_wasm/ffi_wasm_ecc_edwards25519}/src/lib.rs (83%) diff --git a/Cargo.lock b/Cargo.lock index a50c7ec..800a6f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -619,7 +619,7 @@ dependencies = [ ] [[package]] -name = "ecc_ed25519" +name = "ecc_edwards25519" version = "0.1.0" dependencies = [ "curve25519-dalek 4.0.0", @@ -811,18 +811,18 @@ dependencies = [ ] [[package]] -name = "ffi_java_ecc_ed25519" +name = "ffi_java_ecc_edwards25519" version = "0.1.0" dependencies = [ - "ecc_ed25519", + "ecc_edwards25519", "jni", ] [[package]] -name = "ffi_wasm_ecc_ed25519" +name = "ffi_wasm_ecc_edwards25519" version = "0.1.0" dependencies = [ - "ecc_ed25519", + "ecc_edwards25519", "getrandom 0.2.2", "wasm-bindgen", ] @@ -2233,6 +2233,16 @@ dependencies = [ "wedpr_l_utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wedpr_ffi_c_edwards25519" +version = "1.0.0" +dependencies = [ + "cbindgen", + "ecc_edwards25519", + "libc", + "wedpr_ffi_common 1.1.0", +] + [[package]] name = "wedpr_ffi_c_fisco_bcos" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 40e4310..da2c03a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "ffi/ffi_c/ffi_c_crypto_binary", "ffi/ffi_c/ffi_c_fisco_bcos", "ffi/ffi_c/ffi_c_zkp", + "ffi/ffi_c/ffi_c_ecc_edwards25519", "ffi/ffi_common", "ffi/ffi_java/ffi_java_crypto", "ffi/ffi_java/ffi_java_crypto_binary", @@ -34,7 +35,7 @@ members = [ "protos", "third_party/fisco_bcos", "third_party/fisco_bcos_java_sdk", - "crypto/ecc/ecc_ed25519", - "crypto/ecc/ffi_java_ecc_ed25519", - "crypto/ecc/ffi_wasm_ecc_ed25519", + "crypto/ecc/ecc_edwards25519", + "ffi/ffi_java/ffi_java_ecc_edwards25519", + "ffi/ffi_wasm/ffi_wasm_ecc_edwards25519", ] diff --git a/crypto/ecc/ecc_ed25519/Cargo.toml b/crypto/ecc/ecc_edwards25519/Cargo.toml similarity index 91% rename from crypto/ecc/ecc_ed25519/Cargo.toml rename to crypto/ecc/ecc_edwards25519/Cargo.toml index dbcdf8e..efdaa6b 100644 --- a/crypto/ecc/ecc_ed25519/Cargo.toml +++ b/crypto/ecc/ecc_edwards25519/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ecc_ed25519" +name = "ecc_edwards25519" version = "0.1.0" edition = "2021" diff --git a/crypto/ecc/ecc_ed25519/src/lib.rs b/crypto/ecc/ecc_edwards25519/src/lib.rs similarity index 100% rename from crypto/ecc/ecc_ed25519/src/lib.rs rename to crypto/ecc/ecc_edwards25519/src/lib.rs diff --git a/crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml b/ffi/ffi_java/ffi_java_ecc_edwards25519/Cargo.toml similarity index 61% rename from crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml rename to ffi/ffi_java/ffi_java_ecc_edwards25519/Cargo.toml index e6b9013..1f42919 100644 --- a/crypto/ecc/ffi_java_ecc_ed25519/Cargo.toml +++ b/ffi/ffi_java/ffi_java_ecc_edwards25519/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "ffi_java_ecc_ed25519" +name = "ffi_java_ecc_edwards25519" 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_ecc_ed25519" +name = "ffi_java_ecc_edwards25519" crate-type = [ "cdylib", "staticlib" ] [dependencies] jni = "0.13.0" -ecc_ed25519 = { path = "../ecc_ed25519"} \ No newline at end of file +ecc_edwards25519 = { path = "../../../crypto/ecc/ecc_edwards25519" } \ No newline at end of file diff --git a/crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs b/ffi/ffi_java/ffi_java_ecc_edwards25519/src/lib.rs similarity index 96% rename from crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs rename to ffi/ffi_java/ffi_java_ecc_edwards25519/src/lib.rs index 981dc30..f07a4c1 100644 --- a/crypto/ecc/ffi_java_ecc_ed25519/src/lib.rs +++ b/ffi/ffi_java/ffi_java_ecc_edwards25519/src/lib.rs @@ -1,8 +1,6 @@ extern crate jni; -use ecc_ed25519::{ - hash_to_curve, point_scalar_multi, random_scalar, -}; +use ecc_edwards25519::{hash_to_curve, point_scalar_multi, random_scalar}; use jni::{objects::JClass, sys::jbyteArray, JNIEnv}; diff --git a/crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml b/ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/Cargo.toml similarity index 65% rename from crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml rename to ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/Cargo.toml index 89e608a..d866981 100644 --- a/crypto/ecc/ffi_wasm_ecc_ed25519/Cargo.toml +++ b/ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "ffi_wasm_ecc_ed25519" +name = "ffi_wasm_ecc_edwards25519" 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_ecc_ed25519" +name = "ffi_wasm_ecc_edwards25519" crate-type = ["rlib", "cdylib"] [dependencies] wasm-bindgen = "0.2" getrandom = { version = "0.2", features = ["js"] } -ecc_ed25519 = { path = "../ecc_ed25519"} +ecc_edwards25519 = { path = "../../../crypto/ecc/ecc_edwards25519" } diff --git a/crypto/ecc/ffi_wasm_ecc_ed25519/readme.md b/ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/readme.md similarity index 100% rename from crypto/ecc/ffi_wasm_ecc_ed25519/readme.md rename to ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/readme.md diff --git a/crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs b/ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/src/lib.rs similarity index 83% rename from crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs rename to ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/src/lib.rs index 904f9c8..a305055 100644 --- a/crypto/ecc/ffi_wasm_ecc_ed25519/src/lib.rs +++ b/ffi/ffi_wasm/ffi_wasm_ecc_edwards25519/src/lib.rs @@ -1,8 +1,6 @@ extern crate wasm_bindgen; -use ecc_ed25519::{ - hash_to_curve, point_scalar_multi, random_scalar, -}; +use ecc_edwards25519::{hash_to_curve, point_scalar_multi, random_scalar}; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] From a5c39b29fed4ee2803a3e14df22ff336362831b6 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Wed, 20 Sep 2023 17:25:35 +0800 Subject: [PATCH 6/8] add ffi c edwards25519 --- ffi/ffi_c/ffi_c_ecc_edwards25519/Cargo.toml | 18 ++++++++ ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs | 51 +++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 ffi/ffi_c/ffi_c_ecc_edwards25519/Cargo.toml create mode 100644 ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs diff --git a/ffi/ffi_c/ffi_c_ecc_edwards25519/Cargo.toml b/ffi/ffi_c/ffi_c_ecc_edwards25519/Cargo.toml new file mode 100644 index 0000000..c0b671c --- /dev/null +++ b/ffi/ffi_c/ffi_c_ecc_edwards25519/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "wedpr_ffi_c_edwards25519" +version = "1.0.0" +authors = [ "WeDPR " ] +edition = "2018" + +[lib] +name = "ffi_c_edwards25519" +crate-type = [ "cdylib", "staticlib" ] + +[dependencies] +libc = "0.2.60" +ecc_edwards25519 = { path = "../../../crypto/ecc/ecc_edwards25519" } +wedpr_ffi_common = { path = "../../ffi_common" } + +# This is required to generate C/C++ header files. +[build-dependencies] +cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs new file mode 100644 index 0000000..9e20389 --- /dev/null +++ b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs @@ -0,0 +1,51 @@ +//! Library of FFI of wedpr_crypto wrapper functions, targeting C/C++ +//! compatible architectures (including iOS), with fast binary interfaces. +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +use ecc_edwards25519::{hash_to_curve, point_scalar_multi, random_scalar}; + +use wedpr_ffi_common::utils::{ + c_read_raw_pointer, c_write_raw_pointer, CInputBuffer, COutputBuffer, + SUCCESS, +}; + +#[no_mangle] +/// C interface for 'wedpr_random_scalar'. +pub unsafe extern "C" fn wedpr_random_scalar( + output_ciphertext: &mut COutputBuffer, +) -> i8 { + let random_scalar = random_scalar(); + c_write_raw_pointer(&random_scalar, output_ciphertext); + SUCCESS +} + +#[no_mangle] +/// C interface for 'wedpr_hash_to_curve'. +pub unsafe extern "C" fn wedpr_hash_to_curve( + raw_message: &CInputBuffer, + output_ciphertext: &mut COutputBuffer, +) -> i8 { + let plaintext = c_read_raw_pointer(raw_message); + + let message = hash_to_curve(&plaintext); + std::mem::forget(raw_message); + + c_write_raw_pointer(&message, output_ciphertext); + SUCCESS +} + +#[no_mangle] +/// C interface for 'wedpr_point_scalar_multi'. +pub unsafe extern "C" fn wedpr_point_scalar_multi( + raw_point: &CInputBuffer, + raw_scalar: &CInputBuffer, + output_ciphertext: &mut COutputBuffer, +) -> i8 { + let num_point = c_read_raw_pointer(raw_point); + let num_scalar = c_read_raw_pointer(raw_scalar); + let result = point_scalar_multi(&num_point, &num_scalar); + std::mem::forget(raw_point); + std::mem::forget(raw_scalar); + c_write_raw_pointer(&result, output_ciphertext); + SUCCESS +} From 34d9485fc1bc9909ac8d2a0ead69b734e3332ba5 Mon Sep 17 00:00:00 2001 From: shareong <740310627@qq.com> Date: Tue, 10 Oct 2023 17:33:51 +0800 Subject: [PATCH 7/8] fix edwards ffi --- crypto/ecc/ecc_edwards25519/Cargo.toml | 3 +++ ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crypto/ecc/ecc_edwards25519/Cargo.toml b/crypto/ecc/ecc_edwards25519/Cargo.toml index efdaa6b..19b5fbd 100644 --- a/crypto/ecc/ecc_edwards25519/Cargo.toml +++ b/crypto/ecc/ecc_edwards25519/Cargo.toml @@ -11,3 +11,6 @@ sha2 = "0.10.7" rand = "0.8.4" rand_core = "0.6.3" curve25519-dalek = { version = "4", features = [ "digest" , "rand_core"] } + +[lib] +crate-type = ["cdylib", "rlib"] diff --git a/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs index 9e20389..af2c31b 100644 --- a/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs +++ b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs @@ -26,10 +26,8 @@ pub unsafe extern "C" fn wedpr_hash_to_curve( output_ciphertext: &mut COutputBuffer, ) -> i8 { let plaintext = c_read_raw_pointer(raw_message); - let message = hash_to_curve(&plaintext); - std::mem::forget(raw_message); - + std::mem::forget(plaintext); c_write_raw_pointer(&message, output_ciphertext); SUCCESS } @@ -44,8 +42,8 @@ pub unsafe extern "C" fn wedpr_point_scalar_multi( let num_point = c_read_raw_pointer(raw_point); let num_scalar = c_read_raw_pointer(raw_scalar); let result = point_scalar_multi(&num_point, &num_scalar); - std::mem::forget(raw_point); - std::mem::forget(raw_scalar); + std::mem::forget(num_point); + std::mem::forget(num_scalar); c_write_raw_pointer(&result, output_ciphertext); SUCCESS } From c569186dd4bb73c5348012e15b2db18f7f20c103 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Tue, 10 Oct 2023 19:53:21 +0800 Subject: [PATCH 8/8] fix error hash to curve --- crypto/ecc/ecc_edwards25519/src/lib.rs | 60 +++++++++++++++------ ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs | 8 +-- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/crypto/ecc/ecc_edwards25519/src/lib.rs b/crypto/ecc/ecc_edwards25519/src/lib.rs index 7eef815..753cc6e 100644 --- a/crypto/ecc/ecc_edwards25519/src/lib.rs +++ b/crypto/ecc/ecc_edwards25519/src/lib.rs @@ -1,8 +1,8 @@ -use sha2::Sha512; -// use sha2::Digest; +use curve25519_dalek::{ + ristretto::CompressedRistretto, RistrettoPoint, Scalar, +}; use rand::rngs::ThreadRng; -// use rand::RngCore; -use curve25519_dalek::{edwards::CompressedEdwardsY, Scalar}; +use sha2::Sha512; const SCALAR_SIZE: usize = 32; const POINT_SIZE: usize = 32; @@ -19,13 +19,8 @@ pub fn random_scalar() -> Vec { } pub fn hash_to_curve(message: &[u8]) -> Vec { - let hash_scalar = Scalar::hash_from_bytes::(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(); + let hash_point = RistrettoPoint::hash_from_bytes::(message); + return hash_point.compress().to_bytes().to_vec(); } pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { @@ -34,10 +29,12 @@ pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { return Vec::new(); // 如果大小不正确,返回空的 Vec } - // 将输入 &[u8] 转换成 CompressedEdwardsY 表示的点 - let mut point_bytes = [0u8; POINT_SIZE]; - point_bytes.copy_from_slice(point); - let compressed_point = match CompressedEdwardsY(point_bytes).decompress() { + // 将输入 &[u8] 转换成 CompressedRistretto 表示的点 + let compressed_point = match CompressedRistretto::from_slice(&point) { + Ok(point) => point, + Err(_) => return Vec::new(), // 解析点失败,返回空的 Vec + }; + let point = match compressed_point.decompress() { Some(point) => point, None => return Vec::new(), // 解析点失败,返回空的 Vec }; @@ -48,7 +45,7 @@ pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { let scalar = Scalar::from_bytes_mod_order(scalar_bytes); // 执行点乘操作 - let result_point = compressed_point * scalar; + let result_point = point * scalar; // 将结果转换成压缩格式的点 let compressed_result = result_point.compress(); @@ -56,3 +53,34 @@ pub fn point_scalar_multi(point: &[u8], scalar: &[u8]) -> Vec { // 将结果转换成 &[u8] compressed_result.as_bytes().to_vec() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_edwards25519() { + let message = "hello world".as_bytes(); + // let key = random_scalar(); + let key = [ + 125, 185, 175, 119, 127, 247, 65, 76, 146, 163, 142, 178, 247, 149, + 185, 187, 132, 19, 67, 161, 231, 145, 164, 133, 64, 64, 220, 138, + 248, 231, 43, 7, + ]; + let point = hash_to_curve(&message); + let result = point_scalar_multi(&point, &key); + let expected: Vec = [ + 74, 210, 113, 116, 176, 64, 232, 75, 240, 244, 198, 94, 19, 27, + 194, 225, 169, 80, 205, 176, 169, 190, 206, 56, 52, 218, 142, 79, + 28, 132, 70, 16, + ] + .to_vec(); + assert_eq!(expected, result); + } + + #[test] + fn test_empty_vector() { + let test_vector: Vec = Vec::new(); + assert_eq!(test_vector.is_empty(), true); + } +} diff --git a/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs index af2c31b..d4ef012 100644 --- a/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs +++ b/ffi/ffi_c/ffi_c_ecc_edwards25519/src/lib.rs @@ -4,10 +4,7 @@ use ecc_edwards25519::{hash_to_curve, point_scalar_multi, random_scalar}; -use wedpr_ffi_common::utils::{ - c_read_raw_pointer, c_write_raw_pointer, CInputBuffer, COutputBuffer, - SUCCESS, -}; +use wedpr_ffi_common::utils::{c_read_raw_pointer, c_write_raw_pointer, CInputBuffer, COutputBuffer, FAILURE, SUCCESS}; #[no_mangle] /// C interface for 'wedpr_random_scalar'. @@ -44,6 +41,9 @@ pub unsafe extern "C" fn wedpr_point_scalar_multi( let result = point_scalar_multi(&num_point, &num_scalar); std::mem::forget(num_point); std::mem::forget(num_scalar); + if result.is_empty() { + return FAILURE; + } c_write_raw_pointer(&result, output_ciphertext); SUCCESS }