-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b6a338
commit a5c39b2
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "wedpr_ffi_c_edwards25519" | ||
version = "1.0.0" | ||
authors = [ "WeDPR <[email protected]>" ] | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |