pub fn kp_keygen(msk: &Ac17MasterKey, policy: &String) -> Option<Ac17KpSecretKey> {
    // random number generator
    let mut _rng = rand::thread_rng();
    // an msp policy from the given String
    let msp: AbePolicy = AbePolicy::from_string(&policy).unwrap();
    let _num_cols = msp._m[0].len();
    let _num_rows = msp._m.len();
    // 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])
    }
    let mut _sigma_prime: Vec<Fr> = Vec::new();
    for _i in 0usize..(_num_cols - 1) {
        _sigma_prime.push(_rng.gen())
    }
    // 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 _i in 0usize.._num_rows {
        let mut _key: Vec<G1> = Vec::new();
        let _sigma_attr:Fr = _rng.gen();
        // calculate _sk_i1 and _sk_i2 terms
        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(&msp._pi[_i]);
                _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));
            if msp._m[_i][0] == 1 {
                _prod = _prod + (msk._g_k[_t]);
            } else if msp._m[_i][0] == -1 {
                _prod = _prod - (msk._g_k[_t]);
            }
            let mut _temp = G1::zero();
            for _j in 1usize.._num_cols {
                // sum term of _sk_it
                let mut _hash0 = String::new();
                _hash0.push_str(&String::from("0"));
                _hash0.push_str(&_j.to_string());
                for _l in 0usize..(ASSUMPTION_SIZE + 1) {
                    let mut _hash1 = String::new();
                    _hash1.push_str(&_hash0);
                    _hash1.push_str(&_l.to_string());
                    _hash1.push_str(&_t.to_string());
                    _temp = _temp + (blake2b_hash_g1(msk._g, &_hash1) * (_br[_l] * _a_t));
                }
                _temp = _temp + (msk._g * _sigma_prime[_j - 1].neg());
                if msp._m[_i][_j] == 1 {
                    _prod = _prod + _temp;
                } else if msp._m[_i][_j] == -1 {
                    _prod = _prod - _temp;
                }
            }
            _key.push(_prod);
        }
        // calculate _sk_i3 term
        let mut _sk_i3 = msk._g * _sigma_attr.neg();
        if msp._m[_i][0] == 1 {
            _sk_i3 = _sk_i3 + (msk._g_k[ASSUMPTION_SIZE]);
        } else if msp._m[_i][0] == -1 {
            _sk_i3 = _sk_i3 - (msk._g_k[ASSUMPTION_SIZE]);
        }
        // sum term of _sk_i3
        for _j in 1usize.._num_cols {
            if msp._m[_i][_j] == 1 {
                _sk_i3 = _sk_i3 + (msk._g * _sigma_prime[_j - 1].neg());
            } else if msp._m[_i][_j] == -1 {
                _sk_i3 = _sk_i3 - (msk._g * _sigma_prime[_j - 1].neg());
            }
        }
        _key.push(_sk_i3);
        _k.push((msp._pi[_i].to_string(), _key));
    }
    return Some(Ac17KpSecretKey {
        _policy: policy.clone(),
        _sk: Ac17SecretKey { _k_0, _k, _k_p: Vec::new()},
    });
}
/// The key generation algorithm of AC17KP. Generates an Ac17KpSecretKey using an Ac17MasterKey and a policy given as String.
///
/// # Arguments
///
///	* `msk` - A Master Key (MSK), generated by the function setup()
///	* `policy` - An access policy given as JSON String
///
The key generation algorithm of AC17KP. Generates an Ac17KpSecretKey using an Ac17MasterKey and a policy given as String.
The key generation algorithm of AC17KP . Generates an Ac17KpSecretKey using an Ac17MasterKey and a policy given as String .
pub fn kp_keygen(msk: &Ac17MasterKey, policy: &String) -> Option<Ac17KpSecretKey> {
    // random number generator
    let mut _rng = rand::thread_rng();
    // an msp policy from the given String
    let msp: AbePolicy = AbePolicy::from_string(&policy).unwrap();
    let _num_cols = msp._m[0].len();
    let _num_rows = msp._m.len();
    // 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])
    }
    let mut _sigma_prime: Vec<Fr> = Vec::new();
    for _i in 0usize..(_num_cols - 1) {
        _sigma_prime.push(_rng.gen())
    }
    // 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 _i in 0usize.._num_rows {
        let mut _key: Vec<G1> = Vec::new();
        let _sigma_attr:Fr = _rng.gen();
        // calculate _sk_i1 and _sk_i2 terms
        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(&msp._pi[_i]);
                _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));
            if msp._m[_i][0] == 1 {
                _prod = _prod + (msk._g_k[_t]);
            } else if msp._m[_i][0] == -1 {
                _prod = _prod - (msk._g_k[_t]);
            }
            let mut _temp = G1::zero();
            for _j in 1usize.._num_cols {
                // sum term of _sk_it
                let mut _hash0 = String::new();
                _hash0.push_str(&String::from("0"));
                _hash0.push_str(&_j.to_string());
                for _l in 0usize..(ASSUMPTION_SIZE + 1) {
                    let mut _hash1 = String::new();
                    _hash1.push_str(&_hash0);
                    _hash1.push_str(&_l.to_string());
                    _hash1.push_str(&_t.to_string());
                    _temp = _temp + (blake2b_hash_g1(msk._g, &_hash1) * (_br[_l] * _a_t));
                }
                _temp = _temp + (msk._g * _sigma_prime[_j - 1].neg());
                if msp._m[_i][_j] == 1 {
                    _prod = _prod + _temp;
                } else if msp._m[_i][_j] == -1 {
                    _prod = _prod - _temp;
                }
            }
            _key.push(_prod);
        }
        // calculate _sk_i3 term
        let mut _sk_i3 = msk._g * _sigma_attr.neg();
        if msp._m[_i][0] == 1 {
            _sk_i3 = _sk_i3 + (msk._g_k[ASSUMPTION_SIZE]);
        } else if msp._m[_i][0] == -1 {
            _sk_i3 = _sk_i3 - (msk._g_k[ASSUMPTION_SIZE]);
        }
        // sum term of _sk_i3
        for _j in 1usize.._num_cols {
            if msp._m[_i][_j] == 1 {
                _sk_i3 = _sk_i3 + (msk._g * _sigma_prime[_j - 1].neg());
            } else if msp._m[_i][_j] == -1 {
                _sk_i3 = _sk_i3 - (msk._g * _sigma_prime[_j - 1].neg());
            }
        }
        _key.push(_sk_i3);
        _k.push((msp._pi[_i].to_string(), _key));
    }
    return Some(Ac17KpSecretKey {
        _policy: policy.clone(),
        _sk: Ac17SecretKey { _k_0, _k, _k_p: Vec::new()},
    });
}
pub fn kp_keygen ( msk : & Ac17MasterKey , policy : & String ) -> Option < Ac17KpSecretKey > { // random number generator let mut _rng = rand :: thread_rng ( ) ; // an msp policy from the given String let msp : AbePolicy = AbePolicy :: from_string ( & policy ) . unwrap ( ) ; let _num_cols = msp . _m [ 0 ] . len ( ) ; let _num_rows = msp . _m . len ( ) ; // 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 ] ) } let mut _sigma_prime : Vec < Fr > = Vec :: new ( ) ; for _i in 0usize .. ( _num_cols - 1 ) { _sigma_prime . push ( _rng . gen ( ) ) } // 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 _i in 0usize .. _num_rows { let mut _key : Vec < G1 > = Vec :: new ( ) ; let _sigma_attr : Fr = _rng . gen ( ) ; // calculate _sk_i1 and _sk_i2 terms 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 ( & msp . _pi [ _i ] ) ; _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 ) ) ; if msp . _m [ _i ] [ 0 ] == 1 { _prod = _prod + ( msk . _g_k [ _t ] ) ; } else if msp . _m [ _i ] [ 0 ] == - 1 { _prod = _prod - ( msk . _g_k [ _t ] ) ; } let mut _temp = G1 :: zero ( ) ; for _j in 1usize .. _num_cols { // sum term of _sk_it let mut _hash0 = String :: new ( ) ; _hash0 . push_str ( & String :: from ( " " ) ) ; _hash0 . push_str ( & _j . to_string ( ) ) ; for _l in 0usize .. ( ASSUMPTION_SIZE + 1 ) { let mut _hash1 = String :: new ( ) ; _hash1 . push_str ( & _hash0 ) ; _hash1 . push_str ( & _l . to_string ( ) ) ; _hash1 . push_str ( & _t . to_string ( ) ) ; _temp = _temp + ( blake2b_hash_g1 ( msk . _g , & _hash1 ) * ( _br [ _l ] * _a_t ) ) ; } _temp = _temp + ( msk . _g * _sigma_prime [ _j - 1 ] . neg ( ) ) ; if msp . _m [ _i ] [ _j ] == 1 { _prod = _prod + _temp ; } else if msp . _m [ _i ] [ _j ] == - 1 { _prod = _prod - _temp ; } } _key . push ( _prod ) ; } // calculate _sk_i3 term let mut _sk_i3 = msk . _g * _sigma_attr . neg ( ) ; if msp . _m [ _i ] [ 0 ] == 1 { _sk_i3 = _sk_i3 + ( msk . _g_k [ ASSUMPTION_SIZE ] ) ; } else if msp . _m [ _i ] [ 0 ] == - 1 { _sk_i3 = _sk_i3 - ( msk . _g_k [ ASSUMPTION_SIZE ] ) ; } // sum term of _sk_i3 for _j in 1usize .. _num_cols { if msp . _m [ _i ] [ _j ] == 1 { _sk_i3 = _sk_i3 + ( msk . _g * _sigma_prime [ _j - 1 ] . neg ( ) ) ; } else if msp . _m [ _i ] [ _j ] == - 1 { _sk_i3 = _sk_i3 - ( msk . _g * _sigma_prime [ _j - 1 ] . neg ( ) ) ; } } _key . push ( _sk_i3 ) ; _k . push ( ( msp . _pi [ _i ] . to_string ( ) , _key ) ) ; } return Some ( Ac17KpSecretKey { _policy : policy . clone ( ) , _sk : Ac17SecretKey { _k_0 , _k , _k_p : Vec :: new ( ) } , } ) ; }
The key generation algorithm of AC17KP.
The key generation algorithm of AC17KP .
msk
&Ac17MasterKey
policy
&String
msk
&Ac17MasterKey
policy
&String