fn unshuffle_suids()

in protocol/src/suid_create/sharer.rs [284:328]


    fn unshuffle_suids(
        &self,
        mut data: TPayload,
    ) -> Result<Vec<(TPayload, TPayload)>, ProtocolError> {
        // Since ElGamal cyphertexts have two parts, this should be even numbered
        assert_eq!(data.len() % 2, 0);
        let data_len = data.len();

        match (
            self.permutation.clone().read(),
            self.num_entries.clone().read(),
        ) {
            (Ok(permutation), Ok(num_entries)) => {
                let (c1, c2) = {
                    let mut c2_buf = data.drain((data_len / 2)..).collect::<Vec<_>>();
                    let mut c1_buf = data;

                    undo_permute(permutation.as_slice(), &mut c1_buf);
                    undo_permute(permutation.as_slice(), &mut c2_buf);

                    let offsets = compute_prefix_sum(&num_entries);

                    (
                        unflatten_vec(&c1_buf, &offsets),
                        unflatten_vec(&c2_buf, &offsets),
                    )
                };

                assert_eq!(c1.len(), c2.len());

                let x = c1
                    .iter()
                    .zip_eq(c2.iter())
                    .map(|(x, y)| (x.clone(), y.clone()))
                    .collect::<Vec<_>>();
                Ok(x)
            }
            _ => {
                error!("Unable to un-shuffle data");
                Err(ProtocolError::ErrorShuffle(
                    "unable to un-shuffle data".to_string(),
                ))
            }
        }
    }