pub fn cp_keygen(msk: &Ac17MasterKey, attributes: &Vec<String>) -> Option<Ac17CpSecretKey> {
    // if no attibutes or an empty policy
    // maybe add empty msk also here
    if attributes.is_empty() {
        return None;
    }
    // random number generator
    let mut _rng = rand::thread_rng();
    // pick randomness
    let mut _r: Vec<Fr> = Vec::new();
    let mut _sum = Fr::zero();
    for _i in 0usize..ASSUMPTION_SIZE {
        let _rand:Fr = _rng.gen();
        _r.push(_rand);
        _sum = _sum + _rand;
    }
    // first compute Br as it will be used later
    let mut _br: Vec<Fr> = Vec::new();
    for _i in 0usize..ASSUMPTION_SIZE {
        _br.push(msk._b[_i] * _r[_i])
    }
    _br.push(_sum);
    // now computer [Br]_2
    let mut _k_0: Vec<G2> = Vec::new();
    for _i in 0usize..(ASSUMPTION_SIZE + 1) {
        _k_0.push(msk._h * _br[_i])
    }
    // compute [W_1 Br]_1, ...
    let mut _k: Vec<(String, Vec<G1>)> = Vec::new();
    let _a = msk._a.clone();
    let _g = msk._g.clone();
    for _attr in attributes {
        let mut _key: Vec<G1> = Vec::new();
        let _sigma_attr:Fr = _rng.gen();
        for _t in 0usize..ASSUMPTION_SIZE {
            let mut _prod = G1::zero();
            let _a_t = _a[_t].inverse().unwrap();
            for _l in 0usize..(ASSUMPTION_SIZE + 1) {
                let mut _hash = String::new();
                _hash.push_str(&_attr);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());
                _prod = _prod + (blake2b_hash_g1(msk._g, &_hash) * (_br[_l] * _a_t));
            }
            _prod = _prod + (msk._g * (_sigma_attr * _a_t));
            _key.push(_prod);
        }
        _key.push(msk._g * _sigma_attr.neg());
        _k.push((_attr.to_string(), _key));
    }
    // compute [k + VBr]_1
    let mut _k_p: Vec<G1> = Vec::new();
    let _g_k = msk._g_k.clone();
    let _sigma:Fr = _rng.gen();
    for _t in 0usize..ASSUMPTION_SIZE {
        let mut _prod = _g_k[_t];
        let _a_t = _a[_t].inverse().unwrap();
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _hash = String::new();
            _hash.push_str(&String::from("01"));
            _hash.push_str(&_l.to_string());
            _hash.push_str(&_t.to_string());
            _prod = _prod + (blake2b_hash_g1(msk._g, &_hash) * (_br[_l] * _a_t));
        }
        _prod = _prod + (msk._g * (_sigma * _a_t));
        _k_p.push(_prod);
    }
    _k_p.push(_g_k[ASSUMPTION_SIZE] + (msk._g * _sigma.neg()));
    let _attr = attributes.clone();
    let _sk = Ac17SecretKey {_k_0, _k, _k_p};
    return Some(Ac17CpSecretKey {_attr, _sk});
}
/// The key generation algorithm of AC17CP. Generates an Ac17CpSecretKey using a Ac17MasterKey and a set of attributes given as Vec<String>.
///
/// # Arguments
///
///	* `msk` - A Master Key (MSK), generated by the function setup()
///	* `attributes` - A Vector of String attributes assigned to this user key
///
The key generation algorithm of AC17CP. Generates an Ac17CpSecretKey using a Ac17MasterKey and a set of attributes given as Vec.
The key generation algorithm of AC17CP . Generates an Ac17CpSecretKey using a Ac17MasterKey and a set of attributes given as Vec .
pub fn cp_keygen(msk: &Ac17MasterKey, attributes: &Vec<String>) -> Option<Ac17CpSecretKey> {
    // if no attibutes or an empty policy
    // maybe add empty msk also here
    if attributes.is_empty() {
        return None;
    }
    // random number generator
    let mut _rng = rand::thread_rng();
    // pick randomness
    let mut _r: Vec<Fr> = Vec::new();
    let mut _sum = Fr::zero();
    for _i in 0usize..ASSUMPTION_SIZE {
        let _rand:Fr = _rng.gen();
        _r.push(_rand);
        _sum = _sum + _rand;
    }
    // first compute Br as it will be used later
    let mut _br: Vec<Fr> = Vec::new();
    for _i in 0usize..ASSUMPTION_SIZE {
        _br.push(msk._b[_i] * _r[_i])
    }
    _br.push(_sum);
    // now computer [Br]_2
    let mut _k_0: Vec<G2> = Vec::new();
    for _i in 0usize..(ASSUMPTION_SIZE + 1) {
        _k_0.push(msk._h * _br[_i])
    }
    // compute [W_1 Br]_1, ...
    let mut _k: Vec<(String, Vec<G1>)> = Vec::new();
    let _a = msk._a.clone();
    let _g = msk._g.clone();
    for _attr in attributes {
        let mut _key: Vec<G1> = Vec::new();
        let _sigma_attr:Fr = _rng.gen();
        for _t in 0usize..ASSUMPTION_SIZE {
            let mut _prod = G1::zero();
            let _a_t = _a[_t].inverse().unwrap();
            for _l in 0usize..(ASSUMPTION_SIZE + 1) {
                let mut _hash = String::new();
                _hash.push_str(&_attr);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());
                _prod = _prod + (blake2b_hash_g1(msk._g, &_hash) * (_br[_l] * _a_t));
            }
            _prod = _prod + (msk._g * (_sigma_attr * _a_t));
            _key.push(_prod);
        }
        _key.push(msk._g * _sigma_attr.neg());
        _k.push((_attr.to_string(), _key));
    }
    // compute [k + VBr]_1
    let mut _k_p: Vec<G1> = Vec::new();
    let _g_k = msk._g_k.clone();
    let _sigma:Fr = _rng.gen();
    for _t in 0usize..ASSUMPTION_SIZE {
        let mut _prod = _g_k[_t];
        let _a_t = _a[_t].inverse().unwrap();
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _hash = String::new();
            _hash.push_str(&String::from("01"));
            _hash.push_str(&_l.to_string());
            _hash.push_str(&_t.to_string());
            _prod = _prod + (blake2b_hash_g1(msk._g, &_hash) * (_br[_l] * _a_t));
        }
        _prod = _prod + (msk._g * (_sigma * _a_t));
        _k_p.push(_prod);
    }
    _k_p.push(_g_k[ASSUMPTION_SIZE] + (msk._g * _sigma.neg()));
    let _attr = attributes.clone();
    let _sk = Ac17SecretKey {_k_0, _k, _k_p};
    return Some(Ac17CpSecretKey {_attr, _sk});
}
pub fn cp_keygen ( msk : & Ac17MasterKey , attributes : & Vec < String > ) -> Option < Ac17CpSecretKey > { // if no attibutes or an empty policy // maybe add empty msk also here if attributes . is_empty ( ) { return None ; } // random number generator let mut _rng = rand :: thread_rng ( ) ; // pick randomness let mut _r : Vec < Fr > = Vec :: new ( ) ; let mut _sum = Fr :: zero ( ) ; for _i in 0usize .. ASSUMPTION_SIZE { let _rand : Fr = _rng . gen ( ) ; _r . push ( _rand ) ; _sum = _sum + _rand ; } // first compute Br as it will be used later let mut _br : Vec < Fr > = Vec :: new ( ) ; for _i in 0usize .. ASSUMPTION_SIZE { _br . push ( msk . _b [ _i ] * _r [ _i ] ) } _br . push ( _sum ) ; // now computer [Br]_2 let mut _k_0 : Vec < G2 > = Vec :: new ( ) ; for _i in 0usize .. ( ASSUMPTION_SIZE + 1 ) { _k_0 . push ( msk . _h * _br [ _i ] ) } // compute [W_1 Br]_1, ... let mut _k : Vec < ( String , Vec < G1 > ) > = Vec :: new ( ) ; let _a = msk . _a . clone ( ) ; let _g = msk . _g . clone ( ) ; for _attr in attributes { let mut _key : Vec < G1 > = Vec :: new ( ) ; let _sigma_attr : Fr = _rng . gen ( ) ; for _t in 0usize .. ASSUMPTION_SIZE { let mut _prod = G1 :: zero ( ) ; let _a_t = _a [ _t ] . inverse ( ) . unwrap ( ) ; for _l in 0usize .. ( ASSUMPTION_SIZE + 1 ) { let mut _hash = String :: new ( ) ; _hash . push_str ( & _attr ) ; _hash . push_str ( & _l . to_string ( ) ) ; _hash . push_str ( & _t . to_string ( ) ) ; _prod = _prod + ( blake2b_hash_g1 ( msk . _g , & _hash ) * ( _br [ _l ] * _a_t ) ) ; } _prod = _prod + ( msk . _g * ( _sigma_attr * _a_t ) ) ; _key . push ( _prod ) ; } _key . push ( msk . _g * _sigma_attr . neg ( ) ) ; _k . push ( ( _attr . to_string ( ) , _key ) ) ; } // compute [k + VBr]_1 let mut _k_p : Vec < G1 > = Vec :: new ( ) ; let _g_k = msk . _g_k . clone ( ) ; let _sigma : Fr = _rng . gen ( ) ; for _t in 0usize .. ASSUMPTION_SIZE { let mut _prod = _g_k [ _t ] ; let _a_t = _a [ _t ] . inverse ( ) . unwrap ( ) ; for _l in 0usize .. ( ASSUMPTION_SIZE + 1 ) { let mut _hash = String :: new ( ) ; _hash . push_str ( & String :: from ( " " ) ) ; _hash . push_str ( & _l . to_string ( ) ) ; _hash . push_str ( & _t . to_string ( ) ) ; _prod = _prod + ( blake2b_hash_g1 ( msk . _g , & _hash ) * ( _br [ _l ] * _a_t ) ) ; } _prod = _prod + ( msk . _g * ( _sigma * _a_t ) ) ; _k_p . push ( _prod ) ; } _k_p . push ( _g_k [ ASSUMPTION_SIZE ] + ( msk . _g * _sigma . neg ( ) ) ) ; let _attr = attributes . clone ( ) ; let _sk = Ac17SecretKey { _k_0 , _k , _k_p } ; return Some ( Ac17CpSecretKey { _attr , _sk } ) ; }
The key generation algorithm of AC17CP.
The key generation algorithm of AC17CP .
msk
&Ac17MasterKey
attributes
&Vec<String>
msk
&Ac17MasterKey
attributes
&Vec<String>