Skip to content

Commit

Permalink
fix: allow double allocation when using SecretBox
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jan 19, 2024
1 parent 52f441c commit b8fd959
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions ferveo/src/bindings_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,13 @@ macro_rules! generate_boxed_bytes_serialization {

#[pyfunction]
pub fn encrypt(
message: &[u8],
message: Vec<u8>,
aad: &[u8],
dkg_public_key: &DkgPublicKey,
) -> PyResult<Ciphertext> {
let ciphertext = api::encrypt(
// TODO: Avoid double-allocation here. `SecretBox` already allocates for its contents.
api::SecretBox::new(message.to_vec()),
aad,
&dkg_public_key.0,
)
.map_err(FerveoPythonError::FerveoError)?;
let ciphertext =
api::encrypt(api::SecretBox::new(message), aad, &dkg_public_key.0)
.map_err(FerveoPythonError::FerveoError)?;
Ok(Ciphertext(ciphertext))
}

Expand Down Expand Up @@ -816,7 +812,7 @@ mod test_ferveo_python {
let dkg_public_key = dkg.public_key();

// In the meantime, the client creates a ciphertext and decryption request
let ciphertext = encrypt(MSG, AAD, &dkg_public_key).unwrap();
let ciphertext = encrypt(MSG.to_vec(), AAD, &dkg_public_key).unwrap();

// Having aggregated the transcripts, the validators can now create decryption shares
let decryption_shares: Vec<_> = izip!(&validators, &validator_keypairs)
Expand Down Expand Up @@ -887,7 +883,7 @@ mod test_ferveo_python {
let dkg_public_key = dkg.public_key();

// In the meantime, the client creates a ciphertext and decryption request
let ciphertext = encrypt(MSG, AAD, &dkg_public_key).unwrap();
let ciphertext = encrypt(MSG.to_vec(), AAD, &dkg_public_key).unwrap();

// Having aggregated the transcripts, the validators can now create decryption shares
let decryption_shares: Vec<_> = izip!(&validators, &validator_keypairs)
Expand Down

0 comments on commit b8fd959

Please sign in to comment.