Skip to content

Commit 053cbcf

Browse files
committed
misc changes
Signed-off-by: lovesh <[email protected]>
1 parent 4c2f8ed commit 053cbcf

File tree

10 files changed

+201
-89
lines changed

10 files changed

+201
-89
lines changed

delg_cred_cdd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ serde = "1.0"
1212
serde_derive = "1.0"
1313

1414
[dependencies.amcl_wrapper]
15-
version = "0.1.5"
15+
version = "0.1.6"
1616
default-features = false
1717
features = ["bls381"]

delg_cred_cdd/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
### Brief description of the API
66
1. [Groth1 and Groth2 signatures](src/groth_sig.rs).
7-
- Parameters can be generated by calling `GrothS1::setup` or `GrothS2::setup`. `setup` takes the maximum number of attributes that need to be supported. Keep it one more than the number you want to support to accomodate the public key.
7+
- Parameters can be generated by calling `GrothS1::setup` or `GrothS2::setup`. `setup` takes the maximum number of attributes that need to be supported. Keep it one more than the number you want to support to accommodate the public key.
88
- Signing keys can be generated by calling `GrothS1::keygen` or `GrothS2::keygen`. Takes the corresponding setup parameters.
99
- A new signature can be created by calling `Groth1Sig:new` or `Groth2Sig:new`. An existing signature can be randomized by calling `randomize` on the siganture.
1010
- 2 methods for signature verification, `verify` and `verify_fast`, both with the same API. `verify` computes several pairings to verify the signature whereas `verify_fast` does only 1 big multi-pairing. Applies this observation to pairings: if it needs to be cheched that a == b and c == d and e == f, then choose a random number `r` and check whether (a-b) + (c-d)*r + (e-f)*r<sup>2</sup> == 0. Refer the docs for the method for more details
1111
2. [Issuers and delegation](src/issuer.rs).
1212
- Issuers are instantiated by calling `EvenLevelIssuer::new` or `OddLevelIssuer::new` by passing their level to the `new` function. Root issuers is at level 0 so always instantiated by `EvenLevelIssuer::new(0)`.
1313
- Issuers generate their keys with `EvenLevelIssuer::keygen` or `OddLevelIssuer::keygen`.
1414
- Issuers can delegate by calling `delegate` method that takes the attributes to sign, who to delegate to etc resulting in a credential.
15-
- A credential is a called a link and there credentials issued by `EvenLevelIssuer`s are called `CredLinkOdd` and credentials issued by `OddLevelIssuer`s are called `CredLinkEven`.
15+
- A credential is a called a link and the credentials issued by `EvenLevelIssuer`s are called `CredLinkOdd` and credentials issued by `OddLevelIssuer`s are called `CredLinkEven`.
1616
- A link stores its associated `level`, `attributes` and `signature`. The last element of `attributes` is the verification key of the delegatee and the signature is on `attributes`.
17-
- To verify the correctness of link, call `verify` on it with delegator public key, delegatee public key ans setup params.
17+
- To verify the correctness of link, call `verify` on it with delegator public key, delegatee public key and setup params.
1818
- The chain of credentials is kept in `CredChain` which internally has 2 lists, 1 for odd level links and 1 for even. Even or odd level links can be added by calling `extend_with_even` or `extend_with_odd` on the chain.
1919
- To verify that all delegations are valid in the chain, call `verify_delegations` on the chain.
2020
3. [Attribute tokens](src/attribute_token.rs)

delg_cred_cdd/src/attribute_token.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,15 @@ impl<'a> AttributeToken<'a> {
363363
})
364364
}
365365

366-
// XXX: Add other instance data
367-
pub fn gen_challenge(at: &AttributeTokenComm, ipk: &Groth1Verkey) -> FieldElement {
366+
pub fn gen_challenge(
367+
at: &AttributeTokenComm,
368+
ipk: &Groth1Verkey,
369+
mut extra: Vec<u8>,
370+
) -> FieldElement {
368371
let mut bytes = Vec::<u8>::new();
369372
bytes.extend_from_slice(&ipk.0.to_bytes());
370373
bytes.extend_from_slice(&at.to_bytes());
374+
bytes.append(&mut extra);
371375
FieldElement::from_msg_hash(&bytes)
372376
}
373377

@@ -1398,7 +1402,7 @@ mod tests {
13981402

13991403
assert!(com_1.odd_level_revealed_attributes[0].is_empty());
14001404

1401-
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk);
1405+
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk, vec![]);
14021406

14031407
let start_resp = Instant::now();
14041408
let resp_1 = at_1
@@ -1421,7 +1425,7 @@ mod tests {
14211425
.unwrap();
14221426
let recon_duration = start_recon.elapsed();
14231427

1424-
let recon_c_1 = AttributeToken::gen_challenge(&recon_com_1, &l_0_issuer_vk);
1428+
let recon_c_1 = AttributeToken::gen_challenge(&recon_com_1, &l_0_issuer_vk, vec![]);
14251429
assert_eq!(c_1, recon_c_1);
14261430
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
14271431
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1449,7 +1453,7 @@ mod tests {
14491453
assert!(com_2.odd_level_revealed_attributes[0].is_empty());
14501454
assert!(com_2.even_level_revealed_attributes[0].is_empty());
14511455

1452-
let c_2 = AttributeToken::gen_challenge(&com_2, &l_0_issuer_vk);
1456+
let c_2 = AttributeToken::gen_challenge(&com_2, &l_0_issuer_vk, vec![]);
14531457

14541458
let start_resp = Instant::now();
14551459
let resp_2 = at_2
@@ -1478,7 +1482,7 @@ mod tests {
14781482
.unwrap();
14791483
let recon_duration = start_recon.elapsed();
14801484

1481-
let recon_c_2 = AttributeToken::gen_challenge(&recon_com_2, &l_0_issuer_vk);
1485+
let recon_c_2 = AttributeToken::gen_challenge(&recon_com_2, &l_0_issuer_vk, vec![]);
14821486
assert_eq!(c_2, recon_c_2);
14831487
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
14841488
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1508,7 +1512,7 @@ mod tests {
15081512
assert!(com_3.odd_level_revealed_attributes[1].is_empty());
15091513
assert!(com_3.even_level_revealed_attributes[0].is_empty());
15101514

1511-
let c_3 = AttributeToken::gen_challenge(&com_3, &l_0_issuer_vk);
1515+
let c_3 = AttributeToken::gen_challenge(&com_3, &l_0_issuer_vk, vec![]);
15121516

15131517
let start_resp = Instant::now();
15141518
let resp_3 = at_3
@@ -1536,7 +1540,7 @@ mod tests {
15361540
)
15371541
.unwrap();
15381542
let recon_duration = start_recon.elapsed();
1539-
let recon_c_3 = AttributeToken::gen_challenge(&recon_com_3, &l_0_issuer_vk);
1543+
let recon_c_3 = AttributeToken::gen_challenge(&recon_com_3, &l_0_issuer_vk, vec![]);
15401544
assert_eq!(c_3, recon_c_3);
15411545

15421546
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
@@ -1568,7 +1572,7 @@ mod tests {
15681572
assert!(com_4.even_level_revealed_attributes[0].is_empty());
15691573
assert!(com_4.even_level_revealed_attributes[1].is_empty());
15701574

1571-
let c_4 = AttributeToken::gen_challenge(&com_4, &l_0_issuer_vk);
1575+
let c_4 = AttributeToken::gen_challenge(&com_4, &l_0_issuer_vk, vec![]);
15721576

15731577
let start_resp = Instant::now();
15741578
let resp_4 = at_4
@@ -1597,7 +1601,7 @@ mod tests {
15971601
.unwrap();
15981602
let recon_duration = start_recon.elapsed();
15991603

1600-
let recon_c_4 = AttributeToken::gen_challenge(&recon_com_4, &l_0_issuer_vk);
1604+
let recon_c_4 = AttributeToken::gen_challenge(&recon_com_4, &l_0_issuer_vk, vec![]);
16011605
assert_eq!(c_4, recon_c_4);
16021606
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
16031607
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1629,7 +1633,7 @@ mod tests {
16291633
assert!(com_5.even_level_revealed_attributes[0].is_empty());
16301634
assert!(com_5.even_level_revealed_attributes[1].is_empty());
16311635

1632-
let c_5 = AttributeToken::gen_challenge(&com_5, &l_0_issuer_vk);
1636+
let c_5 = AttributeToken::gen_challenge(&com_5, &l_0_issuer_vk, vec![]);
16331637

16341638
let start_resp = Instant::now();
16351639
let resp_5 = at_5
@@ -1658,7 +1662,7 @@ mod tests {
16581662
.unwrap();
16591663
let recon_duration = start_recon.elapsed();
16601664

1661-
let recon_c_5 = AttributeToken::gen_challenge(&recon_com_5, &l_0_issuer_vk);
1665+
let recon_c_5 = AttributeToken::gen_challenge(&recon_com_5, &l_0_issuer_vk, vec![]);
16621666
assert_eq!(c_5, recon_c_5);
16631667
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
16641668
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1691,7 +1695,7 @@ mod tests {
16911695
assert!(com_6.even_level_revealed_attributes[1].is_empty());
16921696
assert!(com_6.even_level_revealed_attributes[2].is_empty());
16931697

1694-
let c_6 = AttributeToken::gen_challenge(&com_6, &l_0_issuer_vk);
1698+
let c_6 = AttributeToken::gen_challenge(&com_6, &l_0_issuer_vk, vec![]);
16951699

16961700
let start_resp = Instant::now();
16971701
let resp_6 = at_6
@@ -1720,7 +1724,7 @@ mod tests {
17201724
.unwrap();
17211725
let recon_duration = start_recon.elapsed();
17221726

1723-
let recon_c_6 = AttributeToken::gen_challenge(&recon_com_6, &l_0_issuer_vk);
1727+
let recon_c_6 = AttributeToken::gen_challenge(&recon_com_6, &l_0_issuer_vk, vec![]);
17241728
assert_eq!(c_6, recon_c_6);
17251729
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
17261730
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1780,7 +1784,7 @@ mod tests {
17801784
assert_eq!(com_1.odd_level_revealed_attributes[0][&1], attributes_1[1]);
17811785
assert_eq!(com_1.odd_level_revealed_attributes[0][&3], attributes_1[3]);
17821786

1783-
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk);
1787+
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk, vec![]);
17841788

17851789
let start_resp = Instant::now();
17861790
let resp_1 = at_1
@@ -1803,7 +1807,7 @@ mod tests {
18031807
.unwrap();
18041808
let recon_duration = start_recon.elapsed();
18051809

1806-
let recon_c_1 = AttributeToken::gen_challenge(&recon_com_1, &l_0_issuer_vk);
1810+
let recon_c_1 = AttributeToken::gen_challenge(&recon_com_1, &l_0_issuer_vk, vec![]);
18071811
assert_eq!(c_1, recon_c_1);
18081812
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
18091813
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1849,7 +1853,7 @@ mod tests {
18491853
assert_eq!(com_2.even_level_revealed_attributes[0][&3], attributes_2[3]);
18501854
assert_eq!(com_2.even_level_revealed_attributes[0][&4], attributes_2[4]);
18511855

1852-
let c_2 = AttributeToken::gen_challenge(&com_2, &l_0_issuer_vk);
1856+
let c_2 = AttributeToken::gen_challenge(&com_2, &l_0_issuer_vk, vec![]);
18531857

18541858
let start_resp = Instant::now();
18551859
let resp_2 = at_2
@@ -1881,7 +1885,7 @@ mod tests {
18811885
.unwrap();
18821886
let recon_duration = start_recon.elapsed();
18831887

1884-
let recon_c_2 = AttributeToken::gen_challenge(&recon_com_2, &l_0_issuer_vk);
1888+
let recon_c_2 = AttributeToken::gen_challenge(&recon_com_2, &l_0_issuer_vk, vec![]);
18851889
assert_eq!(c_2, recon_c_2);
18861890
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
18871891
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -1930,7 +1934,7 @@ mod tests {
19301934
assert_eq!(com_3.even_level_revealed_attributes[0][&4], attributes_2[4]);
19311935
assert_eq!(com_3.odd_level_revealed_attributes[1][&1], attributes_3[1]);
19321936

1933-
let c_3 = AttributeToken::gen_challenge(&com_3, &l_0_issuer_vk);
1937+
let c_3 = AttributeToken::gen_challenge(&com_3, &l_0_issuer_vk, vec![]);
19341938

19351939
let start_resp = Instant::now();
19361940
let resp_3 = at_3
@@ -1962,7 +1966,7 @@ mod tests {
19621966
)
19631967
.unwrap();
19641968
let recon_duration = start_recon.elapsed();
1965-
let recon_c_3 = AttributeToken::gen_challenge(&recon_com_3, &l_0_issuer_vk);
1969+
let recon_c_3 = AttributeToken::gen_challenge(&recon_com_3, &l_0_issuer_vk, vec![]);
19661970
assert_eq!(c_3, recon_c_3);
19671971

19681972
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
@@ -2019,7 +2023,7 @@ mod tests {
20192023
assert_eq!(com_4.even_level_revealed_attributes[1][&1], attributes_4[1]);
20202024
assert_eq!(com_4.even_level_revealed_attributes[1][&4], attributes_4[4]);
20212025

2022-
let c_4 = AttributeToken::gen_challenge(&com_4, &l_0_issuer_vk);
2026+
let c_4 = AttributeToken::gen_challenge(&com_4, &l_0_issuer_vk, vec![]);
20232027

20242028
let start_resp = Instant::now();
20252029
let resp_4 = at_4
@@ -2053,7 +2057,7 @@ mod tests {
20532057
.unwrap();
20542058
let recon_duration = start_recon.elapsed();
20552059

2056-
let recon_c_4 = AttributeToken::gen_challenge(&recon_com_4, &l_0_issuer_vk);
2060+
let recon_c_4 = AttributeToken::gen_challenge(&recon_com_4, &l_0_issuer_vk, vec![]);
20572061
assert_eq!(c_4, recon_c_4);
20582062
println!("For delegation chain of length {}, commitment takes {:?}, response takes {:?}, commitment reconstitution takes {:?}. Total time taken by commitment and response is {:?}", L,
20592063
com_duration, resp_duration, recon_duration, com_duration + resp_duration);
@@ -2191,9 +2195,10 @@ mod tests {
21912195
.unwrap();
21922196
let com_precomp_duration = start.elapsed();
21932197

2194-
let c = AttributeToken::gen_challenge(&com, &l_0_issuer_vk);
2195-
let c_precomp_setup = AttributeToken::gen_challenge(&com_precomp_setup, &l_0_issuer_vk);
2196-
let c_precomp = AttributeToken::gen_challenge(&com_precomp, &l_0_issuer_vk);
2198+
let c = AttributeToken::gen_challenge(&com, &l_0_issuer_vk, vec![]);
2199+
let c_precomp_setup =
2200+
AttributeToken::gen_challenge(&com_precomp_setup, &l_0_issuer_vk, vec![]);
2201+
let c_precomp = AttributeToken::gen_challenge(&com_precomp, &l_0_issuer_vk, vec![]);
21972202

21982203
let sk = if i % 2 == 1 {
21992204
let sk = &odd_level_issuer_keys[i / 2].0;
@@ -2243,7 +2248,7 @@ mod tests {
22432248
.unwrap();
22442249
let recon_duration = start.elapsed();
22452250

2246-
let recon_c = AttributeToken::gen_challenge(&recon_com, &l_0_issuer_vk);
2251+
let recon_c = AttributeToken::gen_challenge(&recon_com, &l_0_issuer_vk, vec![]);
22472252
assert_eq!(c, recon_c);
22482253

22492254
let start = Instant::now();
@@ -2263,7 +2268,7 @@ mod tests {
22632268
let recon_precomp_duration = start.elapsed();
22642269

22652270
let recon_c_precomp_setup_com =
2266-
AttributeToken::gen_challenge(&recon_precomp_setup_com, &l_0_issuer_vk);
2271+
AttributeToken::gen_challenge(&recon_precomp_setup_com, &l_0_issuer_vk, vec![]);
22672272
assert_eq!(c_precomp_setup, recon_c_precomp_setup_com);
22682273

22692274
let recon_precomp_com = AttributeToken::reconstruct_commitment_with_precomputed_vals(
@@ -2280,7 +2285,7 @@ mod tests {
22802285
.unwrap();
22812286

22822287
let recon_c_precomp_com =
2283-
AttributeToken::gen_challenge(&recon_precomp_com, &l_0_issuer_vk);
2288+
AttributeToken::gen_challenge(&recon_precomp_com, &l_0_issuer_vk, vec![]);
22842289
assert_eq!(c_precomp, recon_c_precomp_com);
22852290

22862291
println!("For delegation chain of length {}", L);
@@ -2351,7 +2356,7 @@ mod tests {
23512356
// Supplying same number of collections of revealed attributes as the chain size
23522357
let com_1 = at_1.commitment(vec![HashSet::<usize>::new(); 1]).unwrap();
23532358

2354-
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk);
2359+
let c_1 = AttributeToken::gen_challenge(&com_1, &l_0_issuer_vk, vec![]);
23552360

23562361
let mut morphed_commitment = com_1.clone();
23572362
// Adding an element of comms_s to increase its size

delg_cred_cdd/src/issuer.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ pub struct OddLevelIssuer {
4242
pub level: usize,
4343
}
4444

45+
pub struct RootIssuer {}
46+
47+
pub type RootIssuerVerkey = EvenLevelVerkey;
48+
4549
impl CredLinkOdd {
4650
pub fn attribute_count(&self) -> usize {
4751
self.attributes.len()
@@ -375,6 +379,22 @@ impl OddLevelIssuer {
375379
}
376380
}
377381

382+
impl RootIssuer {
383+
pub fn keygen(setup_params: &Groth1SetupParams) -> (Sigkey, RootIssuerVerkey) {
384+
GrothS1::keygen(setup_params)
385+
}
386+
387+
pub fn delegate(
388+
mut delegatee_attributes: G1Vector,
389+
delegatee_vk: OddLevelVerkey,
390+
sk: &Sigkey,
391+
setup_params: &Groth1SetupParams,
392+
) -> DelgResult<CredLinkOdd> {
393+
let issuer = EvenLevelIssuer::new(0)?;
394+
issuer.delegate(delegatee_attributes, delegatee_vk, sk, setup_params)
395+
}
396+
}
397+
378398
#[cfg(test)]
379399
mod tests {
380400
use super::*;
@@ -452,6 +472,57 @@ mod tests {
452472
.unwrap());
453473
}
454474

475+
#[test]
476+
fn test_root_issuer() {
477+
let max_attributes = 5;
478+
let label = "test".as_bytes();
479+
let params1 = GrothS1::setup(max_attributes, label);
480+
let params2 = GrothS2::setup(max_attributes, label);
481+
482+
let l_1_issuer = OddLevelIssuer::new(1).unwrap();
483+
let l_2_issuer = EvenLevelIssuer::new(2).unwrap();
484+
485+
let (root_issuer_sk, root_issuer_vk) = RootIssuer::keygen(&params1);
486+
let (l_1_issuer_sk, l_1_issuer_vk) = OddLevelIssuer::keygen(&params2);
487+
let (l_2_issuer_sk, l_2_issuer_vk) = EvenLevelIssuer::keygen(&params1);
488+
489+
let attributes_1: G1Vector = (0..max_attributes - 1)
490+
.map(|_| G1::random())
491+
.collect::<Vec<G1>>()
492+
.into();
493+
let cred_link_1 = RootIssuer::delegate(
494+
attributes_1.clone(),
495+
l_1_issuer_vk.clone(),
496+
&root_issuer_sk,
497+
&params1,
498+
)
499+
.unwrap();
500+
501+
assert!(cred_link_1
502+
.verify(&l_1_issuer_vk, &root_issuer_vk, &params1)
503+
.unwrap());
504+
505+
let mut chain_1 = CredChain::new();
506+
chain_1.extend_with_odd(cred_link_1).unwrap();
507+
508+
let attributes_2: G2Vector = (0..max_attributes - 1)
509+
.map(|_| G2::random())
510+
.collect::<Vec<G2>>()
511+
.into();
512+
let cred_link_2 = l_1_issuer
513+
.delegate(
514+
attributes_2.clone(),
515+
l_2_issuer_vk.clone(),
516+
&l_1_issuer_sk,
517+
&params2,
518+
)
519+
.unwrap();
520+
521+
assert!(cred_link_2
522+
.verify(&l_2_issuer_vk, &l_1_issuer_vk, &params2)
523+
.unwrap());
524+
}
525+
455526
#[test]
456527
fn test_delegation_chain_verification() {
457528
let max_attributes = 3;

ps/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
[package]
2-
name = "ps"
2+
name = "ps_sig"
33
version = "0.1.0"
44
authors = ["lovesh <[email protected]>"]
55
edition = "2018"
6+
description = "Pointcheval Sanders signatures"
7+
license = "Apache-2.0"
68

79
[dependencies]
810
rand = "0.6"
9-
lazy_static = "1.3.0"
10-
log = "*"
11-
merlin = "1.2.0"
1211
failure = "0.1.5"
1312
serde = "1.0"
1413
serde_derive = "1.0"
1514

1615
[dependencies.amcl_wrapper]
17-
version = "0.1.1"
16+
version = "0.1.6"
1817
default-features = false
1918
features = ["bls381"]
2019

0 commit comments

Comments
 (0)