pub fn cp_encrypt(
    pk: &Ac17PublicKey,
    policy: &String,
    _plaintext: &[u8],
) -> Option<Ac17CpCiphertext> {
    // 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 _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 the [(V^T As||U^T_2 As||...) M^T_i + W^T_i As]_1 terms
    // pre-compute hashes
    let mut _hash_table: Vec<Vec<Vec<G1>>> = Vec::new();
    for _j in 0usize.._num_cols {
        let mut _x: Vec<Vec<G1>> = Vec::new();
        let mut _hash1 = String::new();
        _hash1.push_str(&String::from("0"));
        _hash1.push_str(&(_j + 1).to_string());
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _y: Vec<G1> = Vec::new();
            let mut _hash2 = String::new();
            _hash2.push_str(&_hash1);
            _hash2.push_str(&_l.to_string());
            for _t in 0usize..ASSUMPTION_SIZE {
                let mut _hash3 = String::new();
                _hash3.push_str(&_hash2);
                _hash3.push_str(&_t.to_string());
                let _hashed_value = blake2b_hash_g1(pk._g, &_hash3);
                _y.push(_hashed_value);
            }
            _x.push(_y)
        }
        _hash_table.push(_x);
    }
    let mut _c: Vec<(String, Vec<G1>)> = Vec::new();
    for _i in 0usize.._num_rows {
        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(&msp._pi[_i]);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());
                let mut _prod1 = blake2b_hash_g1(pk._g, &_hash);
                for _j in 0usize.._num_cols {
                    if msp._m[_i][_j] == 1 {
                        _prod1 = _prod1 + _hash_table[_j][_l][_t];
                    } else if msp._m[_i][_j] == -1 {
                        _prod1 = _prod1 - _hash_table[_j][_l][_t];
                    }
                }
                _prod = _prod + (_prod1 * _s[_t]);
            }
            _ct.push(_prod);
        }
        _c.push((msp._pi[_i].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 _aes_ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    _c_p = _c_p * _msg;
    let _policy = policy.to_string();
    //Encrypt plaintext using derived key from secret
    return Some(Ac17CpCiphertext {
        _policy,
        _ct: Ac17Ciphertext { _c_0, _c, _c_p, _ct: _aes_ct },
    });
}
/// The encrypt algorithm of AC17CP. Generates an Ac17CpCiphertext using an Ac17PublicKey, an access policy given as String and some plaintext data given as [u8].
///
/// # Arguments
///
///	* `pk` - A Public Key (PK), generated by the function setup()
///	* `policy` - An access policy given as JSON String
///	* `plaintext` - plaintext data given as a Vector of u8
///
The encrypt algorithm of AC17CP. Generates an Ac17CpCiphertext using an Ac17PublicKey, an access policy given as String and some plaintext data given as [u8].
The encrypt algorithm of AC17CP . Generates an Ac17CpCiphertext using an Ac17PublicKey an access policy given as String and some plaintext data given as [ u8 ] .
pub fn cp_encrypt(
    pk: &Ac17PublicKey,
    policy: &String,
    _plaintext: &[u8],
) -> Option<Ac17CpCiphertext> {
    // 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 _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 the [(V^T As||U^T_2 As||...) M^T_i + W^T_i As]_1 terms
    // pre-compute hashes
    let mut _hash_table: Vec<Vec<Vec<G1>>> = Vec::new();
    for _j in 0usize.._num_cols {
        let mut _x: Vec<Vec<G1>> = Vec::new();
        let mut _hash1 = String::new();
        _hash1.push_str(&String::from("0"));
        _hash1.push_str(&(_j + 1).to_string());
        for _l in 0usize..(ASSUMPTION_SIZE + 1) {
            let mut _y: Vec<G1> = Vec::new();
            let mut _hash2 = String::new();
            _hash2.push_str(&_hash1);
            _hash2.push_str(&_l.to_string());
            for _t in 0usize..ASSUMPTION_SIZE {
                let mut _hash3 = String::new();
                _hash3.push_str(&_hash2);
                _hash3.push_str(&_t.to_string());
                let _hashed_value = blake2b_hash_g1(pk._g, &_hash3);
                _y.push(_hashed_value);
            }
            _x.push(_y)
        }
        _hash_table.push(_x);
    }
    let mut _c: Vec<(String, Vec<G1>)> = Vec::new();
    for _i in 0usize.._num_rows {
        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(&msp._pi[_i]);
                _hash.push_str(&_l.to_string());
                _hash.push_str(&_t.to_string());
                let mut _prod1 = blake2b_hash_g1(pk._g, &_hash);
                for _j in 0usize.._num_cols {
                    if msp._m[_i][_j] == 1 {
                        _prod1 = _prod1 + _hash_table[_j][_l][_t];
                    } else if msp._m[_i][_j] == -1 {
                        _prod1 = _prod1 - _hash_table[_j][_l][_t];
                    }
                }
                _prod = _prod + (_prod1 * _s[_t]);
            }
            _ct.push(_prod);
        }
        _c.push((msp._pi[_i].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 _aes_ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
    _c_p = _c_p * _msg;
    let _policy = policy.to_string();
    //Encrypt plaintext using derived key from secret
    return Some(Ac17CpCiphertext {
        _policy,
        _ct: Ac17Ciphertext { _c_0, _c, _c_p, _ct: _aes_ct },
    });
}
pub fn cp_encrypt ( pk : & Ac17PublicKey , policy : & String , _plaintext : & [ u8 ] , ) -> Option < Ac17CpCiphertext > { // 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 _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 the [(V^T As||U^T_2 As||...) M^T_i + W^T_i As]_1 terms // pre-compute hashes let mut _hash_table : Vec < Vec < Vec < G1 > > > = Vec :: new ( ) ; for _j in 0usize .. _num_cols { let mut _x : Vec < Vec < G1 > > = Vec :: new ( ) ; let mut _hash1 = String :: new ( ) ; _hash1 . push_str ( & String :: from ( " " ) ) ; _hash1 . push_str ( & ( _j + 1 ) . to_string ( ) ) ; for _l in 0usize .. ( ASSUMPTION_SIZE + 1 ) { let mut _y : Vec < G1 > = Vec :: new ( ) ; let mut _hash2 = String :: new ( ) ; _hash2 . push_str ( & _hash1 ) ; _hash2 . push_str ( & _l . to_string ( ) ) ; for _t in 0usize .. ASSUMPTION_SIZE { let mut _hash3 = String :: new ( ) ; _hash3 . push_str ( & _hash2 ) ; _hash3 . push_str ( & _t . to_string ( ) ) ; let _hashed_value = blake2b_hash_g1 ( pk . _g , & _hash3 ) ; _y . push ( _hashed_value ) ; } _x . push ( _y ) } _hash_table . push ( _x ) ; } let mut _c : Vec < ( String , Vec < G1 > ) > = Vec :: new ( ) ; for _i in 0usize .. _num_rows { 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 ( & msp . _pi [ _i ] ) ; _hash . push_str ( & _l . to_string ( ) ) ; _hash . push_str ( & _t . to_string ( ) ) ; let mut _prod1 = blake2b_hash_g1 ( pk . _g , & _hash ) ; for _j in 0usize .. _num_cols { if msp . _m [ _i ] [ _j ] == 1 { _prod1 = _prod1 + _hash_table [ _j ] [ _l ] [ _t ] ; } else if msp . _m [ _i ] [ _j ] == - 1 { _prod1 = _prod1 - _hash_table [ _j ] [ _l ] [ _t ] ; } } _prod = _prod + ( _prod1 * _s [ _t ] ) ; } _ct . push ( _prod ) ; } _c . push ( ( msp . _pi [ _i ] . 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 _aes_ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; _c_p = _c_p * _msg ; let _policy = policy . to_string ( ) ; //Encrypt plaintext using derived key from secret return Some ( Ac17CpCiphertext { _policy , _ct : Ac17Ciphertext { _c_0 , _c , _c_p , _ct : _aes_ct } , } ) ; }
The encrypt algorithm of AC17CP.
The encrypt algorithm of AC17CP .
pk
&Ac17PublicKey
policy
&String
_plaintext
&[u8]
pk
&Ac17PublicKey
policy
&String
_plaintext
&[u8]