Skip to content

Commit f637567

Browse files
authored
Merge pull request CS-3372-Anonymous-Credential-Experiment#2 from CS-3372-Anonymous-Credential-Experiment/adding_iss
adding iss
2 parents fef0011 + e85479a commit f637567

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/issuer.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use bbs_plus::prelude::SecretKey;
2+
use num_bigint::BigUint;
3+
use ark_bls12_381::{
4+
Fr,
5+
g1::{G1_GENERATOR_X, G1_GENERATOR_Y},
6+
G1Affine, G1Projective
7+
};
8+
use rand::thread_rng;
9+
use sha2::{Sha256};
10+
use num_bigint::RandBigInt;
11+
use ark_ec::AffineRepr;
12+
use ark_ff::PrimeField;
13+
use std::ops::Mul;
14+
15+
#[allow(dead_code)]
16+
pub struct Issuer {
17+
q: BigUint, // Security Parameter
18+
sk: SecretKey<Fr>,
19+
tau: BigUint, // Trapdoor values (secret)
20+
pub g1: G1Projective,
21+
22+
}
23+
24+
impl Issuer { // Assume the issuer can work with Groth-Sahai Commitment (which now is not support)
25+
// currently: all the secret x shall be stored off-chain & accepting the risk of linkability on user's identity trade-off
26+
// for revocability with perdersen commitment
27+
pub fn new() -> Self { // Initialization
28+
let g1_affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
29+
let g1 = g1_affine.into_group(); // Into G1Projective
30+
let q = BigUint::from(Fr::MODULUS); // get the security parameter = 2 * 128 = 256 bits
31+
let mut rng = thread_rng();
32+
let seed_big = rng.gen_biguint_below(&q);
33+
let seed_bytes = seed_big.to_bytes_le();
34+
let sk = SecretKey::<Fr>::generate_using_seed::<Sha256>(&seed_bytes);
35+
// geneerate the tau
36+
let tau = rng.gen_biguint_below(&q); // Sample from field Z_q
37+
38+
Self {
39+
q: q,
40+
sk: sk,
41+
tau: tau,
42+
g1:g1
43+
}
44+
45+
}
46+
pub fn get_com_key(&self) -> (G1Projective, G1Projective) {
47+
let g = self.g1;
48+
let tau_fr = Fr::from_le_bytes_mod_order(&self.tau.to_bytes_le());
49+
let h = g.mul(tau_fr);
50+
(g, h)
51+
}
52+
pub fn get_tau_fr(&self) -> Fr {
53+
Fr::from_le_bytes_mod_order(&self.tau.to_bytes_le())
54+
}
55+
}
56+
57+

0 commit comments

Comments
 (0)