pub fn keygen(
    _pk: &CpAbePublicKey,
    _msk: &CpAbeMasterKey,
    _attributes: &Vec<String>,
) -> Option<CpAbeSecretKey> {
    // if no attibutes or an empty policy
    // maybe add empty msk also here
    if _attributes.is_empty() || _attributes.len() == 0 {
        return None;
    }
    // random number generator
    let mut _rng = rand::thread_rng();
    // generate random r1 and r2 and sum of both
    // compute Br as well because it will be used later too
    let _r:Fr = _rng.gen();
    let _g_r = _pk._g2 * _r;
    let _d = (_msk._g2_alpha + _g_r) * _msk._beta.inverse().unwrap();
    let mut _d_j: Vec<CpAbeAttribute> = Vec::new();
    for _j in _attributes {
        let _r_j:Fr = _rng.gen();
        _d_j.push(CpAbeAttribute {
            _str: _j.clone(), // attribute name
            _g1: _pk._g1 * _r_j, // D_j Prime
            _g2: _g_r + (blake2b_hash_g2(_pk._g2, &_j) * _r_j), // D_j
        });
    }
    return Some(CpAbeSecretKey {_d, _d_j});
}
/// The key generation algorithm of BSW CP-ABE. Generates a CpAbeSecretKey using a CpAbePublicKey, a CpAbeMasterKey and a set of attributes given as Vec<String>.
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_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 BSW CP-ABE. Generates a CpAbeSecretKey using a CpAbePublicKey, a CpAbeMasterKey and a set of attributes given as Vec.
The key generation algorithm of BSW CP - ABE . Generates a CpAbeSecretKey using a CpAbePublicKey a CpAbeMasterKey and a set of attributes given as Vec .
pub fn keygen(
    _pk: &CpAbePublicKey,
    _msk: &CpAbeMasterKey,
    _attributes: &Vec<String>,
) -> Option<CpAbeSecretKey> {
    // if no attibutes or an empty policy
    // maybe add empty msk also here
    if _attributes.is_empty() || _attributes.len() == 0 {
        return None;
    }
    // random number generator
    let mut _rng = rand::thread_rng();
    // generate random r1 and r2 and sum of both
    // compute Br as well because it will be used later too
    let _r:Fr = _rng.gen();
    let _g_r = _pk._g2 * _r;
    let _d = (_msk._g2_alpha + _g_r) * _msk._beta.inverse().unwrap();
    let mut _d_j: Vec<CpAbeAttribute> = Vec::new();
    for _j in _attributes {
        let _r_j:Fr = _rng.gen();
        _d_j.push(CpAbeAttribute {
            _str: _j.clone(), // attribute name
            _g1: _pk._g1 * _r_j, // D_j Prime
            _g2: _g_r + (blake2b_hash_g2(_pk._g2, &_j) * _r_j), // D_j
        });
    }
    return Some(CpAbeSecretKey {_d, _d_j});
}
pub fn keygen ( _pk : & CpAbePublicKey , _msk : & CpAbeMasterKey , _attributes : & Vec < String > , ) -> Option < CpAbeSecretKey > { // if no attibutes or an empty policy // maybe add empty msk also here if _attributes . is_empty ( ) || _attributes . len ( ) == 0 { return None ; } // random number generator let mut _rng = rand :: thread_rng ( ) ; // generate random r1 and r2 and sum of both // compute Br as well because it will be used later too let _r : Fr = _rng . gen ( ) ; let _g_r = _pk . _g2 * _r ; let _d = ( _msk . _g2_alpha + _g_r ) * _msk . _beta . inverse ( ) . unwrap ( ) ; let mut _d_j : Vec < CpAbeAttribute > = Vec :: new ( ) ; for _j in _attributes { let _r_j : Fr = _rng . gen ( ) ; _d_j . push ( CpAbeAttribute { _str : _j . clone ( ) , // attribute name _g1 : _pk . _g1 * _r_j , // D_j Prime _g2 : _g_r + ( blake2b_hash_g2 ( _pk . _g2 , & _j ) * _r_j ) , // D_j } ) ; } return Some ( CpAbeSecretKey { _d , _d_j } ) ; }
The key generation algorithm of BSW CP-ABE.
The key generation algorithm of BSW CP - ABE .
_pk
&CpAbePublicKey
_msk
&CpAbeMasterKey
_attributes
&Vec<String>
_pk
&CpAbePublicKey
_msk
&CpAbeMasterKey
_attributes
&Vec<String>