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
9 changes: 7 additions & 2 deletions src/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::{
borrow::Borrow,
fmt,
iter::Sum,
mem::MaybeUninit,
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
};

Expand Down Expand Up @@ -752,8 +753,12 @@ impl From<G2Affine> for G2Prepared {
infinity: true,
}
} else {
let mut lines = vec![blst_fp6::default(); 68];
unsafe { blst_precompute_lines(lines.as_mut_ptr(), &affine.0) }
let mut lines = Vec::with_capacity(68);
let uninit_lines: &mut [MaybeUninit<blst_fp6>] = lines.spare_capacity_mut();
unsafe {
blst_precompute_lines(uninit_lines.as_mut_ptr().cast(), &affine.0);
lines.set_len(68);
}
G2Prepared {
lines,
infinity: false,
Expand Down
18 changes: 10 additions & 8 deletions src/pairing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{fp12::Fp12, G1Affine, G2Affine, Gt};
use core::ops::{Add, AddAssign};
use core::{
mem::MaybeUninit,
ops::{Add, AddAssign},
};
use ff::Field;
use subtle::{Choice, ConditionallySelectable};

Expand All @@ -21,14 +24,13 @@ macro_rules! impl_pairing {
/// Aggregate pairings efficiently.
#[derive(Debug)]
pub struct $name {
v: Box<[u64]>,
v: Box<[MaybeUninit<u64>]>,
}

impl $name {
pub fn new(hash_or_encode: bool, dst: &[u8]) -> Self {
let v: Vec<u64> = vec![0; unsafe { blst_pairing_sizeof() } / 8];
let mut obj = Self {
v: v.into_boxed_slice(),
v: Box::<[u64]>::new_uninit_slice(unsafe { blst_pairing_sizeof() } / 8),
};
obj.init(hash_or_encode, dst);
obj
Expand All @@ -39,11 +41,11 @@ macro_rules! impl_pairing {
}

fn ctx(&mut self) -> *mut blst_pairing {
self.v.as_mut_ptr() as *mut blst_pairing
self.v.as_mut_ptr().cast()
}

fn const_ctx(&self) -> *const blst_pairing {
self.v.as_ptr() as *const blst_pairing
self.v.as_ptr().cast()
}

pub fn aggregate(
Expand Down Expand Up @@ -131,8 +133,8 @@ pub fn unique_messages(msgs: &[&[u8]]) -> bool {
return msgs[0] != msgs[1];
}

let mut v: Vec<u64> = vec![0; unsafe { blst_uniq_sizeof(n_elems) } / 8];
let ctx = v.as_mut_ptr() as *mut blst_uniq;
let mut v = Box::<[u64]>::new_uninit_slice(unsafe { blst_uniq_sizeof(n_elems) } / 8);
let ctx = v.as_mut_ptr().cast();

unsafe { blst_uniq_init(ctx) };

Expand Down
Loading