pub fn encrypt(
    _gk: &Aw11GlobalKey,
    _pks: &Vec<Aw11PublicKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<Aw11Ciphertext> {
    // 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 _s:Fr = _rng.gen();
    // and calculate shares "s" and "zero"
    let _s_shares = gen_shares_str(_s, _policy).unwrap();
    let _w_shares = gen_shares_str(Fr::zero(), _policy).unwrap();
    // calculate c0 with a randomly selected "msg"
    let _msg: Gt = _rng.gen();
    let _c_0 = _msg * pairing(_gk._g1, _gk._g2).pow(_s);
    // now calculate the C1,x C2,x and C3,x parts
    let mut _c: Vec<(String, Gt, G2, G2)> = Vec::new();
    for (_i, (_attr_name, _attr_share)) in _s_shares.into_iter().enumerate() {
        let _r_x:Fr = _rng.gen();
        let _pk_attr = find_pk_attr(_pks, &_attr_name.to_uppercase());
        match _pk_attr {
            None => return None,
            Some(_attr) => {
                _c.push((
                    _attr_name.clone().to_uppercase(),
                    pairing(_gk._g1, _gk._g2).pow(_attr_share) * _attr.1.pow(_r_x),
                    _gk._g2 * _r_x,
                    (_attr.2 * _r_x) + (_gk._g2 * _w_shares[_i].1),
                ));
            }
        }
    }
    //Encrypt plaintext using derived key from secret
    let _policy = _policy.to_string();
    let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    return Some(Aw11Ciphertext { _policy, _c_0, _c, _ct });
}
/// This function encrypts plaintext data using a given JSON String policy and produces a 'Aw11Ciphertext' if successfull.
///
/// # Arguments
///
///	* `_gk` - A Global Parameters Key (GK), generated by setup()
///	* `_pk` - A Public Parameters Key (MK), associated with an authority and generated by authgen()
///	* `_policy` - A JSON String policy describing the access rights
///	* `_plaintext` - The plaintext data given as a Vector of u8.
This function encrypts plaintext data using a given JSON String policy and produces a 'Aw11Ciphertext' if successfull.
This function encrypts plaintext data using a given JSON String policy and produces a ' Aw11Ciphertext ' if successfull .
pub fn encrypt(
    _gk: &Aw11GlobalKey,
    _pks: &Vec<Aw11PublicKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<Aw11Ciphertext> {
    // 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 _s:Fr = _rng.gen();
    // and calculate shares "s" and "zero"
    let _s_shares = gen_shares_str(_s, _policy).unwrap();
    let _w_shares = gen_shares_str(Fr::zero(), _policy).unwrap();
    // calculate c0 with a randomly selected "msg"
    let _msg: Gt = _rng.gen();
    let _c_0 = _msg * pairing(_gk._g1, _gk._g2).pow(_s);
    // now calculate the C1,x C2,x and C3,x parts
    let mut _c: Vec<(String, Gt, G2, G2)> = Vec::new();
    for (_i, (_attr_name, _attr_share)) in _s_shares.into_iter().enumerate() {
        let _r_x:Fr = _rng.gen();
        let _pk_attr = find_pk_attr(_pks, &_attr_name.to_uppercase());
        match _pk_attr {
            None => return None,
            Some(_attr) => {
                _c.push((
                    _attr_name.clone().to_uppercase(),
                    pairing(_gk._g1, _gk._g2).pow(_attr_share) * _attr.1.pow(_r_x),
                    _gk._g2 * _r_x,
                    (_attr.2 * _r_x) + (_gk._g2 * _w_shares[_i].1),
                ));
            }
        }
    }
    //Encrypt plaintext using derived key from secret
    let _policy = _policy.to_string();
    let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    return Some(Aw11Ciphertext { _policy, _c_0, _c, _ct });
}
pub fn encrypt ( _gk : & Aw11GlobalKey , _pks : & Vec < Aw11PublicKey > , _policy : & String , _plaintext : & [ u8 ] , ) -> Option < Aw11Ciphertext > { // 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 _s : Fr = _rng . gen ( ) ; // and calculate shares "s" and "zero" let _s_shares = gen_shares_str ( _s , _policy ) . unwrap ( ) ; let _w_shares = gen_shares_str ( Fr :: zero ( ) , _policy ) . unwrap ( ) ; // calculate c0 with a randomly selected "msg" let _msg : Gt = _rng . gen ( ) ; let _c_0 = _msg * pairing ( _gk . _g1 , _gk . _g2 ) . pow ( _s ) ; // now calculate the C1,x C2,x and C3,x parts let mut _c : Vec < ( String , Gt , G2 , G2 ) > = Vec :: new ( ) ; for ( _i , ( _attr_name , _attr_share ) ) in _s_shares . into_iter ( ) . enumerate ( ) { let _r_x : Fr = _rng . gen ( ) ; let _pk_attr = find_pk_attr ( _pks , & _attr_name . to_uppercase ( ) ) ; match _pk_attr { None => return None , Some ( _attr ) => { _c . push ( ( _attr_name . clone ( ) . to_uppercase ( ) , pairing ( _gk . _g1 , _gk . _g2 ) . pow ( _attr_share ) * _attr . 1 . pow ( _r_x ) , _gk . _g2 * _r_x , ( _attr . 2 * _r_x ) + ( _gk . _g2 * _w_shares [ _i ] . 1 ) , ) ) ; } } } //Encrypt plaintext using derived key from secret let _policy = _policy . to_string ( ) ; let _ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; return Some ( Aw11Ciphertext { _policy , _c_0 , _c , _ct } ) ; }
This function encrypts plaintext data using a given JSON String policy and produces a 'Aw11Ciphertext' if successfull.
This function encrypts plaintext data using a given JSON String policy and produces a ' Aw11Ciphertext ' if successfull .
_gk
&Aw11GlobalKey
_pks
&Vec<Aw11PublicKey>
_policy
&String
_plaintext
&[u8]
_gk
&Aw11GlobalKey
_pks
&Vec<Aw11PublicKey>
_policy
&String
_plaintext
&[u8]