Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ crate-type = ['cdylib']
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bulletproofs = "4.0.0"
curve25519-dalek-ng = "4.1.1"
bulletproofs = { git = "https://github.com/zkcrypto/bulletproofs" }
curve25519-dalek = { version = "4.1.2", features = ["digest", "rand_core"] }
merlin = "3.0.0"
rand = "0.8.5"
sha3 = "0.9"
sha3 = "0.10"
8 changes: 4 additions & 4 deletions src/Native/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use bulletproofs::PedersenGens;
use curve25519_dalek_ng::{ristretto::RistrettoPoint, scalar::Scalar};
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
use std::slice;

use crate::util::reref;


#[no_mangle]
pub extern "C" fn pedersen_gens_default() -> *mut PedersenGens {
Box::into_raw(Box::default())
Expand Down Expand Up @@ -46,7 +45,9 @@ pub unsafe extern "C" fn pedersen_gens_B(this: *const PedersenGens) -> *const Ri
}

#[no_mangle]
pub unsafe extern "C" fn pedersen_gens_B_blinding(this: *const PedersenGens) -> *const RistrettoPoint {
pub unsafe extern "C" fn pedersen_gens_B_blinding(
this: *const PedersenGens,
) -> *const RistrettoPoint {
let this = reref(this);
Box::into_raw(Box::new(this.B_blinding))
}
Expand All @@ -71,4 +72,3 @@ pub extern "C" fn pedersen_gens_free(this: *mut PedersenGens) {
drop(Box::from_raw(this));
}
}

4 changes: 2 additions & 2 deletions src/Native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use core::slice;

use util::{RawVec, reref};
use util::{reref, RawVec};
pub mod generator;
pub mod point;
pub mod rangeproof;
pub mod scalar;
mod util;
pub mod transscript;
mod util;

#[no_mangle]
pub unsafe extern "C" fn fill_bytes(raw: *const RawVec<u8>, dst: *mut u8) {
Expand Down
15 changes: 11 additions & 4 deletions src/Native/src/point.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use curve25519_dalek_ng::{
use curve25519_dalek::{
ristretto::{CompressedRistretto, RistrettoPoint},
scalar::Scalar,
};
Expand Down Expand Up @@ -31,7 +31,9 @@ pub unsafe extern "C" fn ristretto_point_compress(this: *const RistrettoPoint, d
#[no_mangle]
pub extern "C" fn ristretto_point_decompress(bytes: *const u8) -> *const RistrettoPoint {
let bytes = unsafe { slice::from_raw_parts(bytes, 32) };
let compressed = CompressedRistretto::from_slice(bytes);
let Ok(compressed) = CompressedRistretto::from_slice(bytes) else {
return ptr::null();
};
let Some(point) = compressed.decompress() else {
return ptr::null();
};
Expand Down Expand Up @@ -69,7 +71,9 @@ pub unsafe extern "C" fn ristretto_point_sub(
}

#[no_mangle]
pub unsafe extern "C" fn ristretto_point_negate(this: *const RistrettoPoint) -> *const RistrettoPoint {
pub unsafe extern "C" fn ristretto_point_negate(
this: *const RistrettoPoint,
) -> *const RistrettoPoint {
let this = reref(this);
Box::into_raw(Box::new(-this))
}
Expand Down Expand Up @@ -131,5 +135,8 @@ pub unsafe extern "C" fn compressed_ristretto_from_bytes(
bytes: *mut u8,
) -> *mut CompressedRistretto {
let bytes = slice::from_raw_parts(bytes, 32);
Box::into_raw(Box::new(CompressedRistretto::from_slice(bytes)))
let Ok(point) = CompressedRistretto::from_slice(bytes) else {
return ptr::null_mut();
};
Box::into_raw(Box::new(point))
}
2 changes: 1 addition & 1 deletion src/Native/src/rangeproof.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::slice;

use bulletproofs::{BulletproofGens, PedersenGens, RangeProof};
use curve25519_dalek_ng::{ristretto::CompressedRistretto, scalar::Scalar};
use curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar};
use merlin::Transcript;

use crate::{reref, util::RawVec};
Expand Down
2 changes: 1 addition & 1 deletion src/Native/src/scalar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::slice;

use curve25519_dalek_ng::scalar::Scalar;
use curve25519_dalek::scalar::Scalar;
use sha3::Sha3_512;

use crate::reref;
Expand Down
15 changes: 3 additions & 12 deletions src/Native/src/transscript.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
use core::slice;

use curve25519_dalek_ng::{ristretto::RistrettoPoint, scalar::Scalar};
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
use merlin::Transcript;

use crate::reref;


#[no_mangle]
pub unsafe extern "C" fn transcript_new(label: *const u8, len: usize) -> *const Transcript {
let label = slice::from_raw_parts(label, len);
Box::into_raw(Box::new(Transcript::new(label)))
}


#[no_mangle]
pub unsafe extern "C" fn transcript_append_point(
this: *mut Transcript,
label: *const u8,
len: usize,
point: *const RistrettoPoint
point: *const RistrettoPoint,
) {
let label = slice::from_raw_parts(label, len);
let point = reref(point);
(*this).append_message(label, point.compress().as_bytes());
}


#[no_mangle]
pub unsafe extern "C" fn transcript_domain(
this: *mut Transcript,
message: *const u8,
len: usize,
) {
pub unsafe extern "C" fn transcript_domain(this: *mut Transcript, message: *const u8, len: usize) {
let message = slice::from_raw_parts(message, len);
(*this).append_message(b"domain-sep", message)
}



#[no_mangle]
pub unsafe extern "C" fn transcript_challenge_scalar(
this: *mut Transcript,
Expand Down
4 changes: 4 additions & 0 deletions src/ProjectOrigin.PedersenCommitment/Ristretto/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public CompressedPoint(byte[] bytes)
_bytes = bytes;
}

/// <summary>
/// Creates a pointer to a CompressedRistretto point.
/// This pointer can be a null pointer if the bytes a invalid.
/// </summary>
[LibraryImport(LIBRARY, EntryPoint = "compressed_ristretto_from_bytes")]
internal static partial IntPtr FromBytes(byte[] bytes);

Expand Down
4 changes: 4 additions & 0 deletions src/ProjectOrigin.PedersenCommitment/Ristretto/RangeProof.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ byte[] label
)
{
var commit_ptr = CompressedPoint.FromBytes(commitment._bytes);
if (commit_ptr == IntPtr.Zero)
{
return false;
}
var res = Native.VerifySingle(
_ptr,
bp_gen._ptr,
Expand Down