/// Encrypt chunks. Returns ciphertext as well as the random spec_r's and s's
/// chosen, for later use in NIZK proofs.
Encrypt chunks. Returns ciphertext as well as the random spec_r's and s's
chosen, for later use in NIZK proofs.
Encrypt chunks . Returns ciphertext as well as the random spec_r ' s and s ' s chosen for later use in NIZK proofs .
pub fn enc_chunks(
    sij: &[Vec<isize>],
    pks: Vec<&ECP>,
    tau: &[Bit],
    associated_data: &[u8],
    sys: &SysParam,
    rng: &mut impl RAND,
) -> Option<(Crsz, ToxicWaste)> {
    if sij.is_empty() {
        return None;
    }
    // do
    //   chunks <- headMay allChunks
    //   guard $ all (== chunks) allChunks
    let all_chunks: LinkedList<_> = sij.iter().map(Vec::len).collect();
    let chunks = *all_chunks.front().expect("sij was empty");
    for si in sij.iter() {
        if si.len() != chunks {
            return None; // Chunk lengths disagree.
        }
        for x in si.iter() {
            if *x < CHUNK_MIN || *x > CHUNK_MAX {
                return None; // Chunk out of range.
            }
        }
    }
    use miracl_core::bls12381::pair::g1mul;
    use miracl_core::bls12381::pair::g2mul;
    let g1 = ECP::generator();
    let p = BIG::new_ints(&rom::CURVE_ORDER);
    // do
    //   spec_r <- replicateM chunks getRandom
    //   s <- replicateM chunks getRandom
    //   let rr = (g1^) <$> spec_r
    //   let ss = (g1^) <$> s
    let mut spec_r = Vec::new();
    let mut s = Vec::new();
    let mut rr = Vec::new();
    let mut ss = Vec::new();
    for _j in 0..chunks {
        {
            let tmp = BIG::randomnum(&p, rng);
            spec_r.push(tmp);
            rr.push(g1mul(&g1, &tmp));
        }
        {
            let tmp = BIG::randomnum(&p, rng);
            s.push(tmp);
            ss.push(g1mul(&g1, &tmp));
        }
    }
    // [[pk^spec_r * g1^s | (spec_r, s) <- zip rs si] | (pk, si) <- zip pks sij]
    let cc: Vec<Vec<_>> = sij
        .iter()
        .zip(&pks)
        .map(|(sj, pk)| {
            sj.iter()
                .zip(&spec_r)
                .map(|(s, spec_r)| pk.mul2(spec_r, &g1, &BIG::new_int(*s)))
                .collect()
        })
        .collect();
    let extended_tau = extend_tau(&cc, &rr, &ss, tau, associated_data);
    let id = ftau(&extended_tau, sys).expect("extended_tau not the correct size");
    let mut zz = Vec::new();
    for j in 0..chunks {
        let mut tmp = g2mul(&id, &spec_r[j]);
        tmp.add(&g2mul(&sys.h, &s[j]));
        zz.push(tmp);
    }
    Some((Crsz { cc, rr, ss, zz }, ToxicWaste { spec_r, s }))
}
pub fn enc_chunks ( sij : & [ Vec < isize > ] , pks : Vec < & ECP > , tau : & [ Bit ] , associated_data : & [ u8 ] , sys : & SysParam , rng : & mut impl RAND , ) -> Option < ( Crsz , ToxicWaste ) > { if sij . is_empty ( ) { return None ; } // do //   chunks <- headMay allChunks //   guard $ all (== chunks) allChunks let all_chunks : LinkedList < _ > = sij . iter ( ) . map ( Vec :: len ) . collect ( ) ; let chunks = * all_chunks . front ( ) . expect ( " " ) ; for si in sij . iter ( ) { if si . len ( ) != chunks { return None ; // Chunk lengths disagree. } for x in si . iter ( ) { if * x < CHUNK_MIN || * x > CHUNK_MAX { return None ; // Chunk out of range. } } } use miracl_core :: bls12381 :: pair :: g1mul ; use miracl_core :: bls12381 :: pair :: g2mul ; let g1 = ECP :: generator ( ) ; let p = BIG :: new_ints ( & rom :: CURVE_ORDER ) ; // do //   spec_r <- replicateM chunks getRandom //   s <- replicateM chunks getRandom //   let rr = (g1^) <$> spec_r //   let ss = (g1^) <$> s let mut spec_r = Vec :: new ( ) ; let mut s = Vec :: new ( ) ; let mut rr = Vec :: new ( ) ; let mut ss = Vec :: new ( ) ; for _j in 0 .. chunks { { let tmp = BIG :: randomnum ( & p , rng ) ; spec_r . push ( tmp ) ; rr . push ( g1mul ( & g1 , & tmp ) ) ; } { let tmp = BIG :: randomnum ( & p , rng ) ; s . push ( tmp ) ; ss . push ( g1mul ( & g1 , & tmp ) ) ; } } // [[pk^spec_r * g1^s | (spec_r, s) <- zip rs si] | (pk, si) <- zip pks sij] let cc : Vec < Vec < _ > > = sij . iter ( ) . zip ( & pks ) . map ( | ( sj , pk ) | { sj . iter ( ) . zip ( & spec_r ) . map ( | ( s , spec_r ) | pk . mul2 ( spec_r , & g1 , & BIG :: new_int ( * s ) ) ) . collect ( ) } ) . collect ( ) ; let extended_tau = extend_tau ( & cc , & rr , & ss , tau , associated_data ) ; let id = ftau ( & extended_tau , sys ) . expect ( " " ) ; let mut zz = Vec :: new ( ) ; for j in 0 .. chunks { let mut tmp = g2mul ( & id , & spec_r [ j ] ) ; tmp . add ( & g2mul ( & sys . h , & s [ j ] ) ) ; zz . push ( tmp ) ; } Some ( ( Crsz { cc , rr , ss , zz } , ToxicWaste { spec_r , s } ) ) }
Encrypt chunks.
Encrypt chunks .
sij
&[Vec<isize>]
pks
Vec<&ECP>
tau
&[Bit]
associated_data
&[u8]
sys
&SysParam
rng
&mut impl RAND