rustpq / pqcrypto

Rust Post-Quantum cryptography
212 stars 38 forks source link

Adding Serde Macro Support For Public Key / Private Key / Signature Structs #13

Closed AtropineTears closed 3 years ago

AtropineTears commented 3 years ago

Note: This question is specific to pqcrypto-falcon and I really would like it implemented in that if possible but it also goes for other pqcrypto crates

Hi,

I was wondering whether it is possible to add serde support for deriving serialization/deserialization to the Public Key, Private Key, and Signature structs so they can be serialized/deserialized by simply adding:

#[derive(Serialize,Deserialize)]

Specifically (if there is one you want to try it out on first), I am talking about pqcrypto-falcon as I am trying to create structs that implement serde like below:

#[derive(Serialize,Deserialize)]
pub struct Keypair {
    public: falcon512::PublicKey,
    secret: falcon512::SecretKey
}

Due to the actual structs themselves not having serde support, to the best of my knowledge, it does not allow me to serialize/deserialize. If I am wrong about anything, feel free to correct me.

thomwiggers commented 3 years ago

That should be very possible. I'm not sure if I will have time to do this soon myself, but a pull request would be welcome: you would need to patch the pqcrypto-template/scheme directory files as those are used to generate the rest.

AtropineTears commented 3 years ago

Hi, any updates on serde implementation or whether you can do it? I am working on a project that needs serialization.

thomwiggers commented 3 years ago

I will see if I have some time to get to it this week; in the mean time I would be open to pull requests.

tbraun96 commented 3 years ago

Awesome

thomwiggers commented 3 years ago

You may be interested in the ops crate by the way, which already has serde support

thomwiggers commented 3 years ago

Unfortunately, it seems it's not trivial as derive(Serialize, Deserialize) doesn't work for arbitrary-sized arrays in Rust.

error[E0277]: the trait bound `[u8; 690]: Deserialize<'_>` is not satisfied
  --> pqcrypto-falcon/src/falcon512.rs:89:30
   |
89 | pub struct DetachedSignature([u8; ffi::PQCLEAN_FALCON512_CLEAN_CRYPTO_BYTES], usize);
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[u8; 690]`
   |

I will have to look into workarounds.