Skip to content

Commit

Permalink
Merge pull request #19 from sifraitech/feature/wrappers
Browse files Browse the repository at this point in the history
Feature/wrappers
  • Loading branch information
Stokalas authored Oct 19, 2021
2 parents 7f6c5cb + 2c5c957 commit 497a4df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
42 changes: 25 additions & 17 deletions kzg10-rust/kzg/src/data_converter/fr_converter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
use crate::data_types::fr::Fr;
use crate::BlstFr;

pub fn frFromBlst(fr: BlstFr) -> Fr {
let mut result = Fr::default();
for i in 0..4 {
result.d[i] = fr.l[i];
}
return result;
}

pub fn frToBlst(fr: Fr) -> BlstFr {
let mut result = BlstFr::default();
for i in 0..4 {
result.l[i] = fr.d[i];
}
return result;
use crate::data_types::fr::Fr;
use crate::BlstFr;

pub fn frFromBlst(fr: BlstFr) -> Fr {
let mut intValue: u64 = 0;
let frBlst = fr;
unsafe {
blst::blst_uint64_from_fr(&mut intValue, &frBlst);
}
let i32Value = intValue as i32;//could cause problems
return Fr::from_int(i32Value);

// let mut result = Fr::default();
// for i in 0..4 {
// result.d[i] = fr.l[i];
// }
// return result;
}

pub fn frToBlst(fr: Fr) -> BlstFr {
let mut result = BlstFr::default();
for i in 0..4 {
result.l[i] = fr.d[i];
}
return result;
}
2 changes: 1 addition & 1 deletion kzg10-rust/kzg/src/data_types/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" {
#[derive(Default, Debug, Clone)]
#[repr(C)]
pub struct Fr {
pub d: [u64; crate::MCLBN_FR_UNIT_SIZE],
d: [u64; crate::MCLBN_FR_UNIT_SIZE],
}
impl Fr {
pub fn get_order() -> String {
Expand Down
9 changes: 8 additions & 1 deletion kzg10-rust/kzg/src/kzg10.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{cmp::min, ops, iter};
use crate::data_types::{fr::*, g1::*, g2::*, gt::*};
use crate::{BlstFr};
use crate::data_converter::fr_converter::*;
use crate::mcl_methods::{pairing, final_exp, mclBn_FrEvaluatePolynomial};

const G1_GEN_X: &str = "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507";
Expand Down Expand Up @@ -199,7 +201,12 @@ impl Polynomial {
self.coeffs.len()
}

pub fn eval_at(&self, point: &Fr) -> Fr {
// pub fn eval_at(&self, point: &BlstFr) -> BlstFr {
// let pointFromBlst = frFromBlst(*point);
// return frToBlst(self.eval_at_mcl(&pointFromBlst));
// }

pub fn eval_at_mcl(&self, point: &Fr) -> Fr {
let mut result = Fr::default();
unsafe {
mclBn_FrEvaluatePolynomial(&mut result, self.coeffs.as_ptr(), self.order(), point)
Expand Down

0 comments on commit 497a4df

Please sign in to comment.