Skip to content

Commit

Permalink
feat: allow utils to be used publicly
Browse files Browse the repository at this point in the history
This makes it easier to use the low level abstractions without needing
to import the pairing crate separately.
  • Loading branch information
iancoleman committed Aug 30, 2021
1 parent accbc85 commit ce8e969
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{PK_SIZE, SK_SIZE};
use ff::{Field, PrimeField};
use pairing::bls12_381::{Fr, FrRepr, G1Affine, G1};

pub(crate) fn fr_from_be_bytes(bytes: [u8; SK_SIZE]) -> FromBytesResult<Fr> {
pub fn fr_from_be_bytes(bytes: [u8; SK_SIZE]) -> FromBytesResult<Fr> {
let mut le_bytes = bytes;
le_bytes.reverse();
let mut fr_u64s = [0u64; 4];
Expand All @@ -33,7 +33,7 @@ pub(crate) fn fr_from_be_bytes(bytes: [u8; SK_SIZE]) -> FromBytesResult<Fr> {
Ok(Fr::from_repr(FrRepr(fr_u64s))?)
}

pub(crate) fn fr_to_be_bytes(fr: Fr) -> [u8; SK_SIZE] {
pub fn fr_to_be_bytes(fr: Fr) -> [u8; SK_SIZE] {
let mut bytes = [0u8; SK_SIZE];
// iterating 4 u64s which are in order suiting little endian bytes
// and must be reversed to get big endian bytes
Expand All @@ -46,15 +46,15 @@ pub(crate) fn fr_to_be_bytes(fr: Fr) -> [u8; SK_SIZE] {
bytes
}

pub(crate) fn g1_from_be_bytes(bytes: [u8; PK_SIZE]) -> FromBytesResult<G1> {
pub fn g1_from_be_bytes(bytes: [u8; PK_SIZE]) -> FromBytesResult<G1> {
let mut compressed: <G1Affine as CurveAffine>::Compressed = EncodedPoint::empty();
compressed.as_mut().copy_from_slice(&bytes);
let opt_affine = compressed.into_affine().ok();
let projective = opt_affine.ok_or(FromBytesError::Invalid)?.into_projective();
Ok(projective)
}

pub(crate) fn g1_to_be_bytes(g1: G1) -> [u8; PK_SIZE] {
pub fn g1_to_be_bytes(g1: G1) -> [u8; PK_SIZE] {
let mut bytes = [0u8; PK_SIZE];
bytes.copy_from_slice(g1.into_affine().into_compressed().as_ref());
bytes
Expand Down

0 comments on commit ce8e969

Please sign in to comment.