Skip to content

Commit 6f59c4f

Browse files
committed
refacor: fix failing test
1 parent fa2c1dc commit 6f59c4f

File tree

8 files changed

+50
-84
lines changed

8 files changed

+50
-84
lines changed

src/schemes/bbs/core/proof.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,8 @@ impl Proof {
252252
// cv_for_hash = encode_for_hash(cv_array)
253253
// if cv_for_hash is INVALID, return INVALID
254254
// cv = hash_to_scalar(cv_for_hash, 1)
255-
let cv = compute_challenge::<_, I>(
256-
&init_res,
257-
disclosed_messages,
258-
ph,
259-
None
260-
)?;
255+
let cv =
256+
compute_challenge::<_, I>(&init_res, disclosed_messages, ph, None)?;
261257

262258
// Check the selective disclosure proof
263259
// if c != cv, return INVALID

src/schemes/bbs/interface.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,9 @@ pub(crate) trait BbsInterfaceParameter: InterfaceParameter {
103103
[&Self::api_id(), DEFAULT_DST_SUFFIX_H2S.as_bytes()].concat();
104104
Self::Ciphersuite::hash_to_scalar(data_to_hash, &e_dst)
105105
}
106+
107+
// Hash to curve function, using the Interface's identifier as a dst
108+
fn hash_to_curve(message: &[u8]) -> Result<G1Projective, Error> {
109+
Self::Ciphersuite::hash_to_curve(message, &Self::api_id())
110+
}
106111
}

src/schemes/pseudonym/api/proof.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,17 @@ where
4747

4848
let verify_signature = request.verify_signature.unwrap_or(true);
4949
if verify_signature
50-
&& !(signature.verify::<_, _, _, I::Ciphersuite>(
50+
&& !(signature.verify::<_, _, _, I>(
5151
&pk,
5252
request.header.as_ref(),
5353
&generators,
5454
&digested_messages,
55-
Some(I::api_id()),
5655
)?)
5756
{
5857
return Err(Error::SignatureVerification);
5958
};
6059

61-
let proof = ProofWithNym::new::<_, _, I::Ciphersuite>(
60+
let proof = ProofWithNym::new::<_, _, I>(
6261
&pk,
6362
&signature,
6463
&pseudonym,
@@ -68,7 +67,6 @@ where
6867
request.presentation_header.as_ref(),
6968
&generators,
7069
&proof_messages,
71-
Some(I::api_id()),
7270
)?;
7371

7472
Ok(proof.to_octets())
@@ -97,14 +95,13 @@ where
9795
let generators =
9896
MemoryCachedGenerators::<I>::new(total_message_count, None)?;
9997

100-
proof.verify::<_, _, I::Ciphersuite>(
98+
proof.verify::<_, _, I>(
10199
&pk,
102100
&pseudonym,
103101
&request.verifier_id,
104102
request.header.as_ref(),
105103
request.presentation_header.as_ref(),
106104
&generators,
107105
&messages,
108-
Some(I::api_id()),
109106
)
110107
}

src/schemes/pseudonym/api/pseudonym.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ where
1414
T: AsRef<[u8]>,
1515
I: BbsInterfaceParameter,
1616
{
17-
let pseudonym = Pseudonym::new::<_, I>(
18-
&request.verifier_id,
19-
&request.prover_id,
20-
Some(I::api_id()),
21-
)?;
17+
let pseudonym =
18+
Pseudonym::new::<_, I>(&request.verifier_id, &request.prover_id)?;
2219

2320
Ok(pseudonym.to_octets())
2421
}

src/schemes/pseudonym/api/signature.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ where
3030

3131
let generators = MemoryCachedGenerators::<I>::new(messages.len(), None)?;
3232

33-
Signature::new::<_, _, _, I::Ciphersuite>(
33+
Signature::new::<_, _, _, I>(
3434
&sk,
3535
&pk,
3636
request.header.as_ref(),
3737
&generators,
3838
&messages,
39-
Some(I::api_id()),
4039
)
4140
.map(|sig| sig.to_octets())
4241
}
@@ -57,11 +56,10 @@ where
5756
let generators = MemoryCachedGenerators::<I>::new(messages.len(), None)?;
5857
let signature = Signature::from_octets(request.signature)?;
5958

60-
signature.verify::<_, _, _, I::Ciphersuite>(
59+
signature.verify::<_, _, _, I>(
6160
&pk,
6261
request.header.as_ref(),
6362
&generators,
6463
&messages,
65-
Some(I::api_id()),
6664
)
6765
}

src/schemes/pseudonym/core/proof.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
types::{CommitProofInitResult, Message, ProofMessage},
1717
utils::compute_challenge,
1818
},
19+
interface::BbsInterfaceParameter,
1920
},
2021
common::util::create_random_scalar,
2122
curves::bls12_381::{Bls12, G2Prepared},
@@ -37,7 +38,7 @@ impl core::fmt::Display for ProofWithNym {
3738
impl ProofWithNym {
3839
// TODO: remove the clippy warning de-activation
3940
#[allow(clippy::too_many_arguments)]
40-
pub fn new<T, G, C>(
41+
pub fn new<T, G, I>(
4142
PK: &PublicKey,
4243
signature: &Signature,
4344
pseudonym: &Pseudonym,
@@ -47,14 +48,13 @@ impl ProofWithNym {
4748
ph: Option<T>,
4849
generators: &G,
4950
messages: &[ProofMessage],
50-
api_id: Option<Vec<u8>>,
5151
) -> Result<Self, Error>
5252
where
5353
T: AsRef<[u8]>,
5454
G: Generators,
55-
C: BbsCiphersuiteParameters,
55+
I: BbsInterfaceParameter,
5656
{
57-
Self::new_with_rng::<_, _, _, C>(
57+
Self::new_with_rng::<_, _, _, I>(
5858
PK,
5959
signature,
6060
pseudonym,
@@ -64,14 +64,13 @@ impl ProofWithNym {
6464
ph,
6565
generators,
6666
messages,
67-
api_id,
6867
OsRng,
6968
)
7069
}
7170

7271
// TODO: remove the clippy warning de-activation
7372
#[allow(clippy::too_many_arguments)]
74-
pub fn new_with_rng<T, R, G, C>(
73+
pub fn new_with_rng<T, R, G, I>(
7574
PK: &PublicKey,
7675
signature: &Signature,
7776
pseudonym: &Pseudonym,
@@ -81,17 +80,14 @@ impl ProofWithNym {
8180
ph: Option<T>,
8281
generators: &G,
8382
messages: &[ProofMessage],
84-
api_id: Option<Vec<u8>>,
8583
mut rng: R,
8684
) -> Result<Self, Error>
8785
where
8886
T: AsRef<[u8]>,
8987
R: RngCore + CryptoRng,
9088
G: Generators,
91-
C: BbsCiphersuiteParameters,
89+
I: BbsInterfaceParameter,
9290
{
93-
let api_id = api_id.unwrap_or([].to_vec());
94-
9591
// (r1, r2, r3, m~_j1, ..., m~_jU) = calculate_random_scalars(3+U)
9692
let mut random_scalars = RandomScalars {
9793
r1: create_random_scalar(&mut rng)?,
@@ -134,19 +130,18 @@ impl ProofWithNym {
134130
}
135131
}
136132

137-
let init_result = Proof::proof_init::<T, G, C>(
133+
let init_result = Proof::proof_init::<T, G, I>(
138134
PK,
139135
signature,
140136
generators,
141137
&random_scalars,
142138
header,
143139
message_scalars,
144140
undisclosed_indexes,
145-
&api_id,
146141
)?;
147142

148143
// Pseudonym correctness proof init
149-
let OP = C::hash_to_curve(verifier_id.as_ref(), &api_id)?;
144+
let OP = I::hash_to_curve(verifier_id.as_ref())?;
150145

151146
let pid_tilde = random_scalars.m_tilde_scalars.last().unwrap();
152147
let pseudonym_proof_init = CommitProofInitResult {
@@ -156,11 +151,10 @@ impl ProofWithNym {
156151
};
157152

158153
// challenge calculation
159-
let challenge = compute_challenge::<_, C>(
154+
let challenge = compute_challenge::<_, I>(
160155
&init_result,
161156
&disclosed_messages,
162157
ph,
163-
api_id,
164158
Some(pseudonym_proof_init),
165159
)?;
166160

@@ -181,7 +175,7 @@ impl ProofWithNym {
181175

182176
// TODO: Remove this clippy warning de-activation
183177
#[allow(clippy::too_many_arguments)]
184-
pub fn verify<T, G, C>(
178+
pub fn verify<T, G, I>(
185179
&self,
186180
PK: &PublicKey,
187181
pseudonym: &Pseudonym,
@@ -190,12 +184,11 @@ impl ProofWithNym {
190184
ph: Option<T>,
191185
generators: &G,
192186
disclosed_messages: &BTreeMap<usize, Message>,
193-
api_id: Option<Vec<u8>>,
194187
) -> Result<bool, Error>
195188
where
196189
T: AsRef<[u8]>,
197190
G: Generators,
198-
C: BbsCiphersuiteParameters,
191+
I: BbsInterfaceParameter,
199192
{
200193
// if KeyValidate(PK) is INVALID, return INVALID
201194
// `PK` should not be an identity and should belong to subgroup G2
@@ -206,7 +199,7 @@ impl ProofWithNym {
206199
// the pseudonym should be a point of G1 but not any of the constant
207200
// "reserved" points (i.e., the identity of G1 or the base
208201
// generator and the base point of G1).
209-
if pseudonym.is_valid::<C>().unwrap_u8() == 0u8 {
202+
if pseudonym.is_valid::<I::Ciphersuite>().unwrap_u8() == 0u8 {
210203
return Err(Error::InvalidPseudonym);
211204
}
212205

@@ -228,19 +221,16 @@ impl ProofWithNym {
228221
}
229222
}
230223

231-
let api_id = api_id.unwrap_or([].to_vec());
232-
233224
// initialize the proof verification procedure
234-
let init_res = self.0.proof_verify_init::<T, G, C>(
225+
let init_res = self.0.proof_verify_init::<T, G, I>(
235226
PK,
236227
header,
237228
generators,
238229
disclosed_messages,
239-
&api_id,
240230
)?;
241231

242232
// initialize the pseudonym correctness proof verification procedure
243-
let OP = C::hash_to_curve(verifier_id.as_ref(), &api_id)?;
233+
let OP = I::hash_to_curve(verifier_id.as_ref())?;
244234
let pseudonym_point = pseudonym.as_point();
245235
let proof_challenge = self.0.c;
246236

@@ -256,11 +246,10 @@ impl ProofWithNym {
256246
blind_commit: Uv,
257247
};
258248

259-
let challenge = compute_challenge::<_, C>(
249+
let challenge = compute_challenge::<_, I>(
260250
&init_res,
261251
disclosed_messages,
262252
ph,
263-
api_id,
264253
Some(pseudonym_proof_verify_init),
265254
)?;
266255

@@ -279,7 +268,7 @@ impl ProofWithNym {
279268
// Check the signature proof
280269
// if e(Abar, W) * e(Abar, -P2) != 1, return INVALID
281270
// else return VALID
282-
let P2 = C::p2().to_affine();
271+
let P2 = I::Ciphersuite::p2().to_affine();
283272
Ok(Bls12::multi_miller_loop(&[
284273
(
285274
&self.0.A_bar.to_affine(),

src/schemes/pseudonym/core/pseudonym.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ pub(crate) struct Pseudonym(G1Projective);
1919

2020
// TODO: Use ct to check equalities bellow
2121
impl Pseudonym {
22-
pub fn new<T, I>(
23-
verifier_id: &T,
24-
prover_id: &T,
25-
api_id: Option<Vec<u8>>,
26-
) -> Result<Self, Error>
22+
pub fn new<T, I>(verifier_id: &T, prover_id: &T) -> Result<Self, Error>
2723
where
2824
T: AsRef<[u8]>,
2925
I: BbsInterfaceParameter,
@@ -40,8 +36,7 @@ impl Pseudonym {
4036
});
4137
}
4238

43-
let api_id = api_id.as_ref().map_or(&[] as &[u8], |v| v.as_ref());
44-
let OP = I::Ciphersuite::hash_to_curve(verifier_id, api_id)?;
39+
let OP = I::hash_to_curve(verifier_id)?;
4540

4641
// Check that OP is not the identity, the base point of G1 or P1.
4742
if OP.is_identity().unwrap_u8() == 1u8

0 commit comments

Comments
 (0)