Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add traces to fixtures #173

Open
wants to merge 5 commits into
base: vasilis/parameterize-proof-procedures
Choose a base branch
from
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
67 changes: 41 additions & 26 deletions .github/workflows/ci-detox-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ jobs:
android:
name: Detox Android E2E Testing
needs: [java-wrapper]
runs-on: ${{ matrix.runners }}
strategy:
matrix:
runners: [[self-hosted, macos, general, ARM64]]
concurrency:
group: ci-detox-android-${{ matrix.runners }}-${{ github.head_ref || github.run_id}}
cancel-in-progress: true
timeout-minutes: 60
runs-on: macos-latest
# strategy:
# matrix:
# runners: [[self-hosted, macos, general, ARM64]]
# concurrency:
# group: ci-detox-android-${{ matrix.runners }}-${{ github.head_ref || github.run_id}}
# cancel-in-progress: true
# timeout-minutes: 60

env:
NODE_OPTIONS: "--max-old-space-size=5120"
Expand Down Expand Up @@ -109,31 +109,46 @@ jobs:
working-directory: wrappers/react-native/example
run: yarn install --frozen-lockfile

- name: Config self hosted env
run: |
echo "ANDROID_HOME=/Users/runner/Library/Android/sdk" >> $GITHUB_ENV
echo "ANDROID_SDK_ROOT=/Users/runner/Library/Android/sdk" >> $GITHUB_ENV

- name: Download Android Build Tools
timeout-minutes: 5
run: |
echo "y" | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "build-tools;31.0.0"
cd $ANDROID_SDK_ROOT/build-tools/31.0.0/
ln -sf d8 dx
cd lib
ln -sf d8.jar dx.jar

- name: Use specific Java version for sdkmanager to work
uses: joschi/setup-jdk@v1
with:
java-version: 'openjdk8'
architecture: 'x64'

- name: Download Android Emulator Image
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name Nexus_5X_API_29 --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
$ANDROID_HOME/emulator/emulator -list-avds

- name: Setup Java
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"

# - name: Config self hosted env
# run: |
# echo "ANDROID_HOME=/Users/runner/Library/Android/sdk" >> $GITHUB_ENV
# echo "ANDROID_SDK_ROOT=/Users/runner/Library/Android/sdk" >> $GITHUB_ENV

# - name: Download Android Build Tools
# timeout-minutes: 5
# run: |
# echo "y" | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "build-tools;31.0.0"
# cd $ANDROID_SDK_ROOT/build-tools/31.0.0/
# ln -sf d8 dx
# cd lib
# ln -sf d8.jar dx.jar

# - name: Download Android Emulator Image
# run: |
# echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
# echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name Nexus_5X_API_29 --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
# $ANDROID_HOME/emulator/emulator -list-avds

# - name: Setup Java
# uses: actions/setup-java@v2
# with:
# java-version: "11"
# distribution: "adopt"

- name: Detox Build Android Configuration
working-directory: wrappers/react-native
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 mod bls12_381;
pub(crate) 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(crate) const OCTET_SCALAR_LENGTH: usize = 32;
pub const OCTET_SCALAR_LENGTH: usize = 32;

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

/// Number of bytes to store an element of G2 in affine and compressed form.
pub(crate) const OCTET_POINT_G2_LENGTH: usize = 96;
pub const OCTET_POINT_G2_LENGTH: usize = 96;
11 changes: 11 additions & 0 deletions src/schemes/bbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ 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
16 changes: 13 additions & 3 deletions src/schemes/bbs/api/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,20 @@ where
)
}

// Generate a BBS signature proof of knowledge with a given rng.
// 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"))
)]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub(crate) fn proof_gen_with_rng<T, R, C>(
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>(
request: &BbsProofGenRequest<'_, T>,
rng: R,
trace: Option<&mut ProofTrace>,
) -> Result<Vec<u8>, Error>
where
T: AsRef<[u8]>,
Expand All @@ -154,14 +163,15 @@ where
_parse_request_helper::<T, C>(request)?;

// Generate the proof
let proof = Proof::new_with_rng::<_, _, _, C>(
let proof = Proof::new_with_trace::<_, _, _, 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: 41 additions & 0 deletions src/schemes/bbs/api/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,44 @@ 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())
}
13 changes: 11 additions & 2 deletions src/schemes/bbs/ciphersuites/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ pub const BBS_BLS12381G1_PUBLIC_KEY_LENGTH: usize = OCTET_POINT_G2_LENGTH;
pub const BBS_BLS12381G1_SIGNATURE_LENGTH: usize =
OCTET_POINT_G1_LENGTH + OCTET_SCALAR_LENGTH;

/// Number of random bytes required when creating random scalars.
/// "Export" the suite specific constants for the fixtures generation tool.
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
pub const BBS_BLS12381G1_EXPAND_LEN: usize = 48usize;
pub mod suite_constants {
pub use crate::curves::bls12_381::{
OCTET_POINT_G1_LENGTH,
OCTET_POINT_G2_LENGTH,
OCTET_SCALAR_LENGTH,
};

/// Number of random bytes required when creating random scalars.
pub const BBS_BLS12381G1_EXPAND_LEN: usize = 48usize;
}
71 changes: 41 additions & 30 deletions src/schemes/bbs/ciphersuites/bls12_381_g1_sha_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,6 @@ where
)
}

/// Generate a BLS12-381-G1-Sha-256 BBS signature proof of knowledge with
/// a given rng.
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub fn proof_gen_with_rng<T, R>(
request: &BbsProofGenRequest<'_, T>,
rng: R,
) -> Result<Vec<u8>, Error>
where
T: AsRef<[u8]>,
R: RngCore + CryptoRng,
{
crate::bbs::api::proof::proof_gen_with_rng::<
_,
_,
Bls12381Sha256CipherSuiteParameter,
>(request, rng)
}

/// Verify a BLS12-381-G1-Sha-256 BBS signature proof of knowledge.
pub fn proof_verify<T>(
request: &BbsProofVerifyRequest<'_, T>,
Expand All @@ -123,17 +104,7 @@ pub fn create_generators(
}

#[cfg(feature = "__private_bbs_fixtures_generator_api")]
use crate::curves::bls12_381::{OCTET_POINT_G1_LENGTH, OCTET_SCALAR_LENGTH};

/// Point of G1 octets representation length
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
pub const POINT_G1_OCTETS_LENGTH: usize = OCTET_POINT_G1_LENGTH;

/// Scalar value octets representation length
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
pub const SCALAR_OCTETS_LENGTH: usize = OCTET_SCALAR_LENGTH;
use crate::curves::bls12_381::OCTET_SCALAR_LENGTH;

/// Hash to scalar.
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
Expand Down Expand Up @@ -189,3 +160,43 @@ pub fn default_map_message_to_scalar_as_hash_dst() -> Vec<u8> {
pub fn ciphersuite_id() -> Vec<u8> {
Bls12381Sha256CipherSuiteParameter::ID.as_octets().to_vec()
}

#[cfg(feature = "__private_bbs_fixtures_generator_api")]
use crate::schemes::bbs::core::types::{ProofTrace, SignatureTrace};

/// Generate a BLS12-381-G1-Sha-256 BBS signature using a trace
/// to populate the signature fixtures.
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub fn sign_with_trace<T>(
request: &BbsSignRequest<'_, T>,
trace: Option<&mut SignatureTrace>,
) -> Result<[u8; BBS_BLS12381G1_SIGNATURE_LENGTH], Error>
where
T: AsRef<[u8]>,
{
crate::bbs::api::signature::sign_with_trace::<
_,
Bls12381Sha256CipherSuiteParameter,
>(request, trace)
}

/// Generate a BLS12-381-G1-Sha-256 BBS signature proof of knowledge with
/// a given rng.
#[cfg_attr(docsrs, doc(cfg(feature = "__private_bbs_fixtures_generator_api")))]
#[cfg(feature = "__private_bbs_fixtures_generator_api")]
pub fn proof_with_rng_and_trace<T, R>(
request: &BbsProofGenRequest<'_, T>,
rng: R,
trace: Option<&mut ProofTrace>,
) -> Result<Vec<u8>, Error>
where
T: AsRef<[u8]>,
R: RngCore + CryptoRng,
{
crate::bbs::api::proof::proof_gen_with_rng_and_trace::<
_,
_,
Bls12381Sha256CipherSuiteParameter,
>(request, rng, trace)
}
Loading