Skip to content
Open
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
42 changes: 21 additions & 21 deletions .github/workflows/ci-obj-c.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# name: ci-obj-c
name: ci-obj-c

# on:
# pull_request:
# branches:
# - master
# push:
# branches:
# - master
on:
pull_request:
branches:
- master
push:
branches:
- master

# jobs:
# build_test:
# name: Build & Test Objective-C Wrapper
# runs-on: macos-latest
# defaults:
# run:
# working-directory: ./wrappers/obj-c
# steps:
# - name: Checkout
# uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247 # pin@v3.5.1
jobs:
build_test:
name: Build & Test Objective-C Wrapper
runs-on: macos-latest
defaults:
run:
working-directory: ./wrappers/obj-c
steps:
- name: Checkout
uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247 # pin@v3.5.1

# - name: Build binary
# run: ./scripts/update-libraries.sh
# shell: bash

# - name: Verify podspec
# working-directory: ./
# run: pod lib lint --allow-warnings --verbose
- name: Verify podspec
working-directory: ./
run: pod lib lint --allow-warnings --verbose
3 changes: 0 additions & 3 deletions .github/workflows/ci-wrapper-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
toolchain: stable
override: true

- name: Export Clang
run: export CC=/usr/bin/clang

- name: Run yarn install
run: yarn install --frozen-lockfile

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sha2 = "0.9"
sha3 = "0.9"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
criterion = { version = "0.4.0", features = ["html_reports"] }
hex = "0.4"
rand_xorshift = "0.3"
bbs-fixtures-generator = {version = "0.1.0", path = "tools/bbs-fixtures-generator"}
Expand Down
2 changes: 0 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ pub(crate) mod key_pair;
// Common utilities functions.
pub(crate) mod util;

pub use util::vec_to_byte_array;

// Common serialization utils.
pub(crate) mod serialization;
81 changes: 7 additions & 74 deletions src/common/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! bbs_bls_key_pair_impl {

/// Convert a vector of bytes of big-endian representation of the
/// secret key.
pub fn from_vec(bytes: &[u8]) -> Result<Self, Error> {
pub fn from_vec(bytes: &Vec<u8>) -> Result<Self, Error> {
match vec_to_byte_array::<{ Self::SIZE_BYTES }>(bytes) {
Ok(result) => Self::from_bytes(&result),
Err(e) => Err(e),
Expand Down Expand Up @@ -179,9 +179,6 @@ macro_rules! bbs_bls_key_pair_impl {
/// Number of bytes needed to represent the public key in compressed
/// form.
pub const SIZE_BYTES: usize = $octet_point_length;
/// Number of bytes needed to represent the public key in
/// uncompressed form.
pub const SIZE_BYTES_UNCOMPRESSED: usize = 2 * Self::SIZE_BYTES;

/// Check if the `PublicKey` is valid.
pub fn is_valid(&self) -> Choice {
Expand All @@ -196,43 +193,17 @@ macro_rules! bbs_bls_key_pair_impl {
self.0.to_affine().to_compressed()
}

/// Get the G2 representation in affine, uncompressed and big-endian
/// form of PublicKey.
pub fn to_octets_uncompressed(
&self,
) -> [u8; Self::SIZE_BYTES_UNCOMPRESSED] {
self.0.to_uncompressed()
}

/// Convert a vector of bytes of big-endian representation of the
/// public key.
pub fn from_vec(bytes: &[u8]) -> Result<Self, Error> {
let data_len = bytes.len();
match data_len {
Self::SIZE_BYTES => {
let byte_array =
vec_to_byte_array::<{ Self::SIZE_BYTES }>(bytes)?;
Self::from_octets(&byte_array)
}
Self::SIZE_BYTES_UNCOMPRESSED => {
let byte_array = vec_to_byte_array::<
{ Self::SIZE_BYTES_UNCOMPRESSED },
>(bytes)?;
Self::from_octets_uncompressed(&byte_array)
}
_ => Err(Error::Conversion {
cause: format!(
"source vector size {data_len}, expected \
destination byte array size of either {} or {}",
Self::SIZE_BYTES,
Self::SIZE_BYTES_UNCOMPRESSED
),
}),
pub fn from_vec(bytes: &Vec<u8>) -> Result<Self, Error> {
match vec_to_byte_array::<{ Self::SIZE_BYTES }>(bytes) {
Ok(result) => Self::from_octets(&result),
Err(e) => Err(e),
}
}

/// Convert from G2 point in affine, compressed and big-endian
/// form to PublicKey.
/// Convert from G2 point in affine, compressed and big-endian form
/// to PublicKey.
pub fn from_octets(
bytes: &[u8; Self::SIZE_BYTES],
) -> Result<Self, Error> {
Expand All @@ -245,44 +216,6 @@ macro_rules! bbs_bls_key_pair_impl {
Err(Error::BadEncoding)
}
}

/// Convert from G2 point in affine, uncompressed and big-endian
/// form to PublicKey.
pub fn from_octets_uncompressed(
bytes: &[u8; Self::SIZE_BYTES_UNCOMPRESSED],
) -> Result<Self, Error> {
let result = $point_projective_type::from_uncompressed(bytes);

if result.is_some().unwrap_u8() == 1u8 {
Ok(Self(result.unwrap()))
} else {
Err(Error::BadEncoding)
}
}

/// Convert a public key from compressed to uncompressed
/// representation
pub fn compressed_to_uncompressed(
bytes: &[u8],
) -> Result<[u8; Self::SIZE_BYTES_UNCOMPRESSED], Error> {
match Self::from_vec(bytes) {
Ok(public_key) => {
Ok(Self::to_octets_uncompressed(&public_key))
}
Err(e) => Err(e),
}
}

/// Convert a public key from uncompressed to compressed
/// representation
pub fn uncompressed_to_compressed(
bytes: &[u8],
) -> Result<[u8; Self::SIZE_BYTES], Error> {
match Self::from_vec(bytes) {
Ok(public_key) => Ok(Self::to_octets(&public_key)),
Err(e) => Err(e),
}
}
}

/// A BBS key pair.
Expand Down
7 changes: 4 additions & 3 deletions src/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ macro_rules! print_byte_array {

pub(crate) use print_byte_array;

/// Convert a vec to a byte array
pub fn vec_to_byte_array<const N: usize>(vec: &[u8]) -> Result<[u8; N], Error> {
pub fn vec_to_byte_array<const N: usize>(
vec: &Vec<u8>,
) -> Result<[u8; N], Error> {
let data_len = vec.len();
match <[u8; N]>::try_from(vec.to_owned()) {
match <[u8; N]>::try_from(vec.clone()) {
Ok(result) => Ok(result),
Err(_) => Err(Error::Conversion {
cause: format!(
Expand Down
2 changes: 1 addition & 1 deletion src/curves.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Curve specific structures for BLS12-381
pub(crate) mod bls12_381;
pub mod bls12_381;

// Serialization of group points
pub(crate) mod point_serde;
Expand Down
6 changes: 3 additions & 3 deletions src/curves/bls12_381.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub use blstrs::*;

/// Number of bytes to store a scalar.
pub const OCTET_SCALAR_LENGTH: usize = 32;
pub(crate) const OCTET_SCALAR_LENGTH: usize = 32;

/// Number of bytes to store an element of G1 in affine and compressed form.
pub const OCTET_POINT_G1_LENGTH: usize = 48;
pub(crate) const OCTET_POINT_G1_LENGTH: usize = 48;

/// Number of bytes to store an element of G2 in affine and compressed form.
pub const OCTET_POINT_G2_LENGTH: usize = 96;
pub(crate) const OCTET_POINT_G2_LENGTH: usize = 96;
18 changes: 0 additions & 18 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ pub enum Error {
messages: usize,
},

/// Not enough random scalars during Proof initialization.
UndisclosedIndexesRandomScalarsLengthMismatch {
/// Number of random scalars.
random_scalars: usize,
/// Number of messages.
undisclosed_indexes: usize,
},

/// The given point(from `G1` or `G2`) is an `Identity` element of
/// respective subgroup.
PointIsIdentity,
Expand Down Expand Up @@ -143,16 +135,6 @@ impl core::fmt::Debug for Error {
#messages: {messages}."
)
}
Error::UndisclosedIndexesRandomScalarsLengthMismatch {
random_scalars,
undisclosed_indexes,
} => {
write!(
f,
"length mismatch #random_scalars: {random_scalars}, \
#undisclosed_indexes: {undisclosed_indexes}."
)
}
Error::PointIsIdentity => {
write!(f, "unexpected `Identity` element.")
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ extern crate alloc;
/// Error types
mod error;

/// Common types and utilities
pub mod common;
// Common types and utilities
mod common;

// Supported Curves
mod curves;
Expand Down
11 changes: 0 additions & 11 deletions src/schemes/bbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ pub use crate::schemes::bbs::api::dtos::{
BbsVerifyRequest,
};

// namespace bbs types
/// BBS related types
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub mod types {
pub use crate::schemes::bbs::core::types::{
ProofTrace,
RandomScalars,
SignatureTrace,
};
}

// Core implementation of BBS scheme.
pub(crate) mod core;

Expand Down
17 changes: 4 additions & 13 deletions src/schemes/bbs/api/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,15 @@ where
request.presentation_header.as_ref(),
&generators,
&messages,
Some(total_message_count),
)
}

// Generate a BBS signature proof of knowledge with a given rng and a trace.
#[cfg_attr(
docsrs,
doc(cfg(feature = "__private_bbs_fixtures_generator_api"))
)]
// Generate a BBS signature proof of knowledge with a given rng.
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
use crate::schemes::bbs::core::types::ProofTrace;

#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub(crate) fn proof_gen_with_rng_and_trace<T, R, C>(
pub(crate) fn proof_gen_with_rng<T, R, C>(
request: &BbsProofGenRequest<'_, T>,
rng: R,
trace: Option<&mut ProofTrace>,
) -> Result<Vec<u8>, Error>
where
T: AsRef<[u8]>,
Expand All @@ -163,15 +155,14 @@ where
_parse_request_helper::<T, C>(request)?;

// Generate the proof
let proof = Proof::new_with_trace::<_, _, _, C>(
let proof = Proof::new_with_rng::<_, _, _, C>(
&pk,
&signature,
request.header.as_ref(),
request.presentation_header.as_ref(),
&generators,
&proof_messages,
rng,
trace,
)?;

Ok(proof.to_octets())
Expand Down
41 changes: 0 additions & 41 deletions src/schemes/bbs/api/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,3 @@ where
&messages,
)
}

#[cfg_attr(
docsrs,
doc(cfg(feature = "__private_bbs_fixtures_generator_api"))
)]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
use crate::bbs::core::types::SignatureTrace;

#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub(crate) fn sign_with_trace<T, C>(
request: &BbsSignRequest<'_, T>,
trace: Option<&mut SignatureTrace>,
) -> Result<[u8; BBS_BLS12381G1_SIGNATURE_LENGTH], Error>
where
T: AsRef<[u8]>,
C: BbsCiphersuiteParameters,
{
// Parse the secret key
let sk = SecretKey::from_bytes(request.secret_key)?;

// Parse public key from request
let pk = PublicKey::from_octets(request.public_key)?;

// Digest the supplied messages
let messages: Vec<Message> = digest_messages::<_, C>(request.messages)?;

// Derive generators
let generators = MemoryCachedGenerators::<C>::new(messages.len(), None)?;

// Produce the signature and return
Signature::new_with_trace::<_, _, _, C>(
&sk,
&pk,
request.header.as_ref(),
&generators,
&messages,
trace,
)
.map(|sig| sig.to_octets())
}
2 changes: 1 addition & 1 deletion src/schemes/bbs/ciphersuites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) trait BbsCiphersuiteParameters:
}

/// Point on G2 to be used during signature and proof verification.
fn bp2() -> G2Projective {
fn p2() -> G2Projective {
G2Projective::generator()
}

Expand Down
Loading
Loading