Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Ciphertext::from_elements #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dobo90
Copy link

@dobo90 dobo90 commented Jan 30, 2025

What?

This is similar to PR34. It implements additional function in Ciphertext. I've named it from_elements as there are already from_element functions in PublicKey and VerifiableDecryption (of course I can change to from_parts or any other name). For example it allows to instantiate Ciphertext from untagged bytes:

use elastic_elgamal::{group::Generic, Ciphertext};
use p256::{elliptic_curve::sec1::FromEncodedPoint, AffinePoint, EncodedPoint, NistP256};

fn main() {
    let random_element_bytes = [0u8; 64]; // some real bytes here
    let blinded_element_bytes = [0u8; 64]; // some real bytes here

    let random_element = EncodedPoint::from_untagged_bytes(&random_element_bytes.into());
    let random_element = AffinePoint::from_encoded_point(&random_element).unwrap();

    let blinded_element = EncodedPoint::from_untagged_bytes(&blinded_element_bytes.into());
    let blinded_element = AffinePoint::from_encoded_point(&blinded_element).unwrap();

    let ciphertext: Ciphertext<Generic<NistP256>> =
        Ciphertext::from_elements(random_element.into(), blinded_element.into());
}

Why?

playready-rs requires a functionality to instantiate Ciphertext from bytes sent over the wire. For now I've forked elastic-elgamal but I would love to publish playready-rs on crates.io (but it's not possible as it uses modified version of this repository).

For example it allows to instantiate Ciphertext from untagged bytes:
```
use elastic_elgamal::{group::Generic, Ciphertext};
use p256::{elliptic_curve::sec1::FromEncodedPoint, AffinePoint, EncodedPoint, NistP256};

fn main() {
    let random_element_bytes = [0u8; 64]; // some real bytes here
    let blinded_element_bytes = [0u8; 64]; // some real bytes here

    let random_element = EncodedPoint::from_untagged_bytes(&random_element_bytes.into());
    let random_element = AffinePoint::from_encoded_point(&random_element).unwrap();

    let blinded_element = EncodedPoint::from_untagged_bytes(&blinded_element_bytes.into());
    let blinded_element = AffinePoint::from_encoded_point(&blinded_element).unwrap();

    let ciphertext: Ciphertext<Generic<NistP256>> =
        Ciphertext::from_elements(random_element.into(), blinded_element.into());
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant