pub fn kp_encrypt(
    pk: &Ac17PublicKey,
    attributes: &Vec<String>,
    _plaintext: &[u8],
) -> Option<Ac17KpCiphertext> {
    // random number generator
    let mut _rng = rand::thread_rng();
    // pick randomness
    let mut _s: Vec<Fr> = Vec::new();
    let mut _sum = Fr::zero();
    for _i in 0usize..ASSUMPTION_SIZE {
        let _rand:Fr = _rng.gen();
        _s.push(_rand);
        _sum = _sum + _rand;
    }
    // compute the [As]_2 term
    let mut _c_0: Vec<G2> = Vec::new();
    let _h_a = pk._h_a.clone();
    for _i in 0usize..ASSUMPTION_SIZE {
        _c_0.push(_h_a[_i] * _s[_i]);
    }
    _c_0.push(_h_a[ASSUMPTION_SIZE] * _sum);
    // compute ct_y terms
    let mut _c: Vec<(String, Vec<G1>)> = Vec::new();
    for _attr in attributes {
        let mut _ct: Vec<G1> = Vec::new();
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _prod = G1::zero();
            for _t in 0usize..ASSUMPTION_SIZE {
                let mut _hash = String::new();
                _hash.push_str(&_attr);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());

                let mut _prod1 = blake2b_hash_g1(pk._g, &_hash);
                _prod = _prod + (_prod1 * _s[_t]);
            }
            _ct.push(_prod);
        }
        _c.push((_attr.to_string(), _ct));
    }
    let mut _c_p = Gt::one();
    for _i in 0usize..ASSUMPTION_SIZE {
        _c_p = _c_p * (pk._e_gh_ka[_i].pow(_s[_i]));
    }
    // random msg
    let _msg: Gt = _rng.gen();
    let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    _c_p = _c_p * _msg;
    //Encrypt plaintext using derived key from secret
    return Some(Ac17KpCiphertext {
        _attr: attributes.clone(),
        _ct: Ac17Ciphertext {_c_0, _c, _c_p, _ct},
    });
}
/// The encrypt algorithm of AC17KP. Generates an Ac17KpCiphertext using an Ac17PublicKey, a set of attributes given as Vec<String> and some plaintext data given as [u8].
///
/// # Arguments
///
///	* `pk` - A Public Key (MSK), generated by the function setup()
///	* `attributes` - A set of attributes given as Vec<String>
///	* `_plaintext` - plaintext data given as a Vector of u8
///
The encrypt algorithm of AC17KP. Generates an Ac17KpCiphertext using an Ac17PublicKey, a set of attributes given as Vec and some plaintext data given as [u8].
The encrypt algorithm of AC17KP . Generates an Ac17KpCiphertext using an Ac17PublicKey a set of attributes given as Vec and some plaintext data given as [ u8 ] .
pub fn kp_encrypt(
    pk: &Ac17PublicKey,
    attributes: &Vec<String>,
    _plaintext: &[u8],
) -> Option<Ac17KpCiphertext> {
    // random number generator
    let mut _rng = rand::thread_rng();
    // pick randomness
    let mut _s: Vec<Fr> = Vec::new();
    let mut _sum = Fr::zero();
    for _i in 0usize..ASSUMPTION_SIZE {
        let _rand:Fr = _rng.gen();
        _s.push(_rand);
        _sum = _sum + _rand;
    }
    // compute the [As]_2 term
    let mut _c_0: Vec<G2> = Vec::new();
    let _h_a = pk._h_a.clone();
    for _i in 0usize..ASSUMPTION_SIZE {
        _c_0.push(_h_a[_i] * _s[_i]);
    }
    _c_0.push(_h_a[ASSUMPTION_SIZE] * _sum);
    // compute ct_y terms
    let mut _c: Vec<(String, Vec<G1>)> = Vec::new();
    for _attr in attributes {
        let mut _ct: Vec<G1> = Vec::new();
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _prod = G1::zero();
            for _t in 0usize..ASSUMPTION_SIZE {
                let mut _hash = String::new();
                _hash.push_str(&_attr);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());
                let mut _prod1 = blake2b_hash_g1(pk._g, &_hash);
                _prod = _prod + (_prod1 * _s[_t]);
            }
            _ct.push(_prod);
        }
        _c.push((_attr.to_string(), _ct));
    }
    let mut _c_p = Gt::one();
    for _i in 0usize..ASSUMPTION_SIZE {
        _c_p = _c_p * (pk._e_gh_ka[_i].pow(_s[_i]));
    }
    // random msg
    let _msg: Gt = _rng.gen();
    let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    _c_p = _c_p * _msg;
    //Encrypt plaintext using derived key from secret
    return Some(Ac17KpCiphertext {
        _attr: attributes.clone(),
        _ct: Ac17Ciphertext {_c_0, _c, _c_p, _ct},
    });
}
pub fn kp_encrypt ( pk : & Ac17PublicKey , attributes : & Vec < String > , _plaintext : & [ u8 ] , ) -> Option < Ac17KpCiphertext > { // random number generator let mut _rng = rand :: thread_rng ( ) ; // pick randomness let mut _s : Vec < Fr > = Vec :: new ( ) ; let mut _sum = Fr :: zero ( ) ; for _i in 0usize .. ASSUMPTION_SIZE { let _rand : Fr = _rng . gen ( ) ; _s . push ( _rand ) ; _sum = _sum + _rand ; } // compute the [As]_2 term let mut _c_0 : Vec < G2 > = Vec :: new ( ) ; let _h_a = pk . _h_a . clone ( ) ; for _i in 0usize .. ASSUMPTION_SIZE { _c_0 . push ( _h_a [ _i ] * _s [ _i ] ) ; } _c_0 . push ( _h_a [ ASSUMPTION_SIZE ] * _sum ) ; // compute ct_y terms let mut _c : Vec < ( String , Vec < G1 > ) > = Vec :: new ( ) ; for _attr in attributes { let mut _ct : Vec < G1 > = Vec :: new ( ) ; for _l in 0usize .. ( ASSUMPTION_SIZE + 1 ) { let mut _prod = G1 :: zero ( ) ; for _t in 0usize .. ASSUMPTION_SIZE { let mut _hash = String :: new ( ) ; _hash . push_str ( & _attr ) ; _hash . push_str ( & _l . to_string ( ) ) ; _hash . push_str ( & _t . to_string ( ) ) ; let mut _prod1 = blake2b_hash_g1 ( pk . _g , & _hash ) ; _prod = _prod + ( _prod1 * _s [ _t ] ) ; } _ct . push ( _prod ) ; } _c . push ( ( _attr . to_string ( ) , _ct ) ) ; } let mut _c_p = Gt :: one ( ) ; for _i in 0usize .. ASSUMPTION_SIZE { _c_p = _c_p * ( pk . _e_gh_ka [ _i ] . pow ( _s [ _i ] ) ) ; } // random msg let _msg : Gt = _rng . gen ( ) ; let _ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; _c_p = _c_p * _msg ; //Encrypt plaintext using derived key from secret return Some ( Ac17KpCiphertext { _attr : attributes . clone ( ) , _ct : Ac17Ciphertext { _c_0 , _c , _c_p , _ct } , } ) ; }
The encrypt algorithm of AC17KP.
The encrypt algorithm of AC17KP .
pk
&Ac17PublicKey
attributes
&Vec<String>
_plaintext
&[u8]
pk
&Ac17PublicKey
attributes
&Vec<String>
_plaintext
&[u8]