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

How to Convert QuadExtField<Fp12ParamsWrapper<Fq12Parameters>> Back to Original Hex? #901

Open
vinay10949 opened this issue Dec 2, 2024 · 0 comments

Comments

@vinay10949
Copy link

vinay10949 commented Dec 2, 2024

I’m working on a codebase and am encountering an issue when trying to convert a decrypted message of type QuadExtField<Fp12ParamsWrapper<Fq12Parameters>> back to its original hexadecimal string format.

Here's a snippet of the code:

let my_str = "00000000000000008a7f5d0f15ef296b1d80813c63241ff1952a1d3d4fbd0cb8008242f1000e3bb7";

// Serialize the input hexadecimal string
let mut bytes: Vec<u8> = hex::decode(my_str).unwrap();
let m = Fq12::from_random_bytes(&data).unwrap();

// Encrypt the message
let ct = enc(&pk, 0, m);

// Decrypt the ciphertext
let decrypted_m = dec(&mut sk, &ct); // Type: QuadExtField<Fp12ParamsWrapper<Fq12Parameters>>

When I try to convert decrypted_m back to bytes and then to a hex string, the output is incorrect. Instead of getting the original my_str, I end up with a padded and incorrect result, such as:

"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f5d0f..."

Also details

ark-ff = "0.3"
ark-ec = "0.3"
ark-bls12-381 = "0.3"
ark-std = "0.3"
rand = "0.8.5"
bls12_381 = "0.8.0"
hex-literal = "=0.4.1"
sha2 = "0.10.8"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ark-serialize = "0.3"

Question:

  • How can I correctly convert QuadExtField<Fp12ParamsWrapper<Fq12Parameters>> back to the original hexadecimal string (my_str)?
  • Is there a specific deserialization method or field extraction process I need to follow for this type?

Additional Context:

  • I’m using Fq12 for cryptographic operations.
  • The encryption and decryption steps work as expected, but the deserialization back to the original hex string is not producing the correct output.
  • Any guidance or references to examples would be greatly appreciated!

Thank You:

Thanks in advance for your help! 😊

@vinay10949 vinay10949 changed the title How to Convert QuadExtField<Fp12ParamsWrapper<Fq12Parameters>> Back to Original Hex String? How to Convert QuadExtField<Fp12ParamsWrapper<Fq12Parameters>> Back to Original Hex? Dec 2, 2024
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

No branches or pull requests

1 participant