pub fn keygen(
    _pk: &KpAbePublicKey,
    _msk: &KpAbeMasterKey,
    _policy: &String,
) -> Option<KpAbeSecretKey> {
    // random number generator
    let mut _rng = rand::thread_rng();
    let _shares = gen_shares_str(_msk._alpha1, _policy).unwrap();
    let mut _d: Vec<(String, G1, G2, G1, G1, G1)> = Vec::new();
    for (_share_str, _share_value) in _shares.into_iter() {
        let _r:Fr = _rng.gen();
        if is_negative(&_share_str) {
            _d.push((
                _share_str.to_string(),
                G1::zero(),
                G2::zero(),
                (_pk._g_g1 * _share_value) + (_pk._g_g1_b2 * _r),
                _pk._g_g1_b * (blake2b_hash_fr(&_share_str) * _r) + (_msk._h_g1 * _r),
                _pk._g_g1 * _r.neg(),
            ));
        } else {
            _d.push((
                _share_str.to_string(),
                (_pk._g_g1 * (_msk._alpha2 * _share_value))
                    + (blake2b_hash_g1(_pk._g_g1, &_share_str) * _r),
                _pk._g_g2 * _r,
                G1::zero(),
                G1::zero(),
                G1::zero(),
            ));
        }
    }
    return Some(KpAbeSecretKey {
        _policy: _policy.clone(),
        _dj: _d,
    });
}
/// The key generation algorithm of LSW KP-ABE.
/// Generates a KpAbeSecretKey using a KpAbePublicKey, a KpAbeMasterKey and a policy given as JSON String.
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_msk` - A Master Key (MSK), generated by the function setup()
///	* `_policy` - An access policy given as JSON String
///
The key generation algorithm of LSW KP-ABE.
Generates a KpAbeSecretKey using a KpAbePublicKey, a KpAbeMasterKey and a policy given as JSON String.
The key generation algorithm of LSW KP - ABE . Generates a KpAbeSecretKey using a KpAbePublicKey a KpAbeMasterKey and a policy given as JSON String .
pub fn keygen(
    _pk: &KpAbePublicKey,
    _msk: &KpAbeMasterKey,
    _policy: &String,
) -> Option<KpAbeSecretKey> {
    // random number generator
    let mut _rng = rand::thread_rng();
    let _shares = gen_shares_str(_msk._alpha1, _policy).unwrap();
    let mut _d: Vec<(String, G1, G2, G1, G1, G1)> = Vec::new();
    for (_share_str, _share_value) in _shares.into_iter() {
        let _r:Fr = _rng.gen();
        if is_negative(&_share_str) {
            _d.push((
                _share_str.to_string(),
                G1::zero(),
                G2::zero(),
                (_pk._g_g1 * _share_value) + (_pk._g_g1_b2 * _r),
                _pk._g_g1_b * (blake2b_hash_fr(&_share_str) * _r) + (_msk._h_g1 * _r),
                _pk._g_g1 * _r.neg(),
            ));
        } else {
            _d.push((
                _share_str.to_string(),
                (_pk._g_g1 * (_msk._alpha2 * _share_value))
                    + (blake2b_hash_g1(_pk._g_g1, &_share_str) * _r),
                _pk._g_g2 * _r,
                G1::zero(),
                G1::zero(),
                G1::zero(),
            ));
        }
    }
    return Some(KpAbeSecretKey {
        _policy: _policy.clone(),
        _dj: _d,
    });
}
pub fn keygen ( _pk : & KpAbePublicKey , _msk : & KpAbeMasterKey , _policy : & String , ) -> Option < KpAbeSecretKey > { // random number generator let mut _rng = rand :: thread_rng ( ) ; let _shares = gen_shares_str ( _msk . _alpha1 , _policy ) . unwrap ( ) ; let mut _d : Vec < ( String , G1 , G2 , G1 , G1 , G1 ) > = Vec :: new ( ) ; for ( _share_str , _share_value ) in _shares . into_iter ( ) { let _r : Fr = _rng . gen ( ) ; if is_negative ( & _share_str ) { _d . push ( ( _share_str . to_string ( ) , G1 :: zero ( ) , G2 :: zero ( ) , ( _pk . _g_g1 * _share_value ) + ( _pk . _g_g1_b2 * _r ) , _pk . _g_g1_b * ( blake2b_hash_fr ( & _share_str ) * _r ) + ( _msk . _h_g1 * _r ) , _pk . _g_g1 * _r . neg ( ) , ) ) ; } else { _d . push ( ( _share_str . to_string ( ) , ( _pk . _g_g1 * ( _msk . _alpha2 * _share_value ) ) + ( blake2b_hash_g1 ( _pk . _g_g1 , & _share_str ) * _r ) , _pk . _g_g2 * _r , G1 :: zero ( ) , G1 :: zero ( ) , G1 :: zero ( ) , ) ) ; } } return Some ( KpAbeSecretKey { _policy : _policy . clone ( ) , _dj : _d , } ) ; }
The key generation algorithm of LSW KP-ABE.
The key generation algorithm of LSW KP - ABE .
_pk
&KpAbePublicKey
_msk
&KpAbeMasterKey
_policy
&String
_pk
&KpAbePublicKey
_msk
&KpAbeMasterKey
_policy
&String