diff --git a/Cargo.toml b/Cargo.toml index f952ad2..5727a4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,5 @@ siphasher = "1.0.0" x25519-dalek = { version = "2.0.0", features = ["reusable_secrets", "static_secrets"] } [dev-dependencies] +hex-literal = "0.4.1" rand = "0.8.5" diff --git a/src/keys.rs b/src/keys.rs index d3e0809..2321e18 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -113,16 +113,15 @@ impl PublicKeyPackage { #[cfg(test)] mod tests { + use super::PublicKeyPackage; + use crate::participant::Secret; + use hex_literal::hex; use rand::thread_rng; use reddsa::frost::{ redjubjub::{keys::split, SigningKey}, redpallas::frost::keys::IdentifierList, }; - use crate::participant::Secret; - - use super::PublicKeyPackage; - #[test] fn serialization_roundtrip() { let secret1 = Secret::random(thread_rng()); @@ -152,4 +151,28 @@ mod tests { assert_eq!(public_key_package, deserialized) } + + #[test] + fn deserialization_regression() { + let serialization = hex!( + " + a600000000c3d2051e02b62709a88950f3a75eb0d03a9510123a72947eb083b5822 + e874793e8f40f6b0ba381109571a24f9f87421f0393f45cee913ef891bd75eb7ba7 + a5611858a80305cf631451a7d94604cb32d11285ebd4b6ee797eceaa464b2dfcd09 + 7295cacf90c579265130e9e37225a23dfd51da2c4b8db499cb0e7aa6b03a15cde2d + b678e99c94974b2a766f83b134c5c782803f5f5a65bc4a6392f6a81062ad8292e84 + 4f3c00200000072cf6be086f2453ec7ce6f7b76fbb35c4dcf6fac1737dbcc2a2467 + b3f0c8453574ad36e9dd2b092aa0870930ed6be8d9ba40c146c5b2110fbb03f7e3b + 60e5d63347f47bd69c418630d0c4d3301f0a910c3d127c9d7064cedf26c0c2f0cea + 9486a8993eea77744ead60ea210bc43a4c56be4933762dddaba145fb215c5dbaebc + a0272586e451ceb90d00fde8fa96f7eba99845066803aef4073ca39f3af9050b9f0 + bc63deb3652c1455090070a8dd3376128e093726a055bab2e2d2325cb5c978b62eb + a97c6b42325cf4fc106321b7c8979fc123dc77a5da91ace3b3245405d680b9bcc13 + 5828ac28415305d74abe2ca084639dd1ab7bb8c69930cf0a55a1151022020200 + " + ); + let deserialized = + PublicKeyPackage::deserialize_from(&serialization[..]).expect("deserialization failed"); + assert_eq!(&serialization[..], deserialized.serialize()); + } } diff --git a/src/participant.rs b/src/participant.rs index 1d1e390..2c78ad2 100644 --- a/src/participant.rs +++ b/src/participant.rs @@ -310,6 +310,7 @@ mod tests { use super::Identity; use super::Secret; use ed25519_dalek::Signature; + use hex_literal::hex; use rand::thread_rng; #[test] @@ -330,6 +331,19 @@ mod tests { assert_eq!(identity1, identity2); } + #[test] + fn secret_deserialization_regression() { + let serialization = hex!( + " + 72adb5f2526cba20e38cb7e44466503d41823e2da95c68faa1904ada33d8660edeb + 29e91c501aca3bb7791fe37ae562ff50fcf88bb3af9a64671ace8f6095bb169 + " + ); + let deserialized = + Secret::deserialize_from(&serialization[..]).expect("deserialization failed"); + assert_eq!(serialization, deserialized.serialize()); + } + #[test] fn identity_serialization_stability() { let secret = Secret::random(thread_rng()); @@ -350,6 +364,21 @@ mod tests { assert_eq!(id, deserialized); } + #[test] + fn identity_deserialization_regression() { + let serialization = hex!( + " + 723c692fa94b563faa41cf99b5759f8d0dc2606c90df30e8ae1813b1068d5cddd60 + 0c88978733e6399d65a1b5c5c025030a3505737c4207075e11fce168ba97246a545 + 92e5217ea54b1bc68efcdf15e8bf227d098d84d403994cebe774a119cfcbcec2eee + a73d09306e395019d9b891e8c9d6acaa1751cacde66f4010f748c9e0d + " + ); + let deserialized = + Identity::deserialize_from(&serialization[..]).expect("deserialization failed"); + assert_eq!(serialization, deserialized.serialize()); + } + #[test] fn identity_integrity_check() { let secret = Secret::random(thread_rng()); diff --git a/src/signature_share.rs b/src/signature_share.rs index 69f2b51..a0f019d 100644 --- a/src/signature_share.rs +++ b/src/signature_share.rs @@ -64,3 +64,25 @@ impl SignatureShare { }) } } + +#[cfg(test)] +mod tests { + use super::*; + use hex_literal::hex; + + #[test] + fn deserialization_regression() { + let serialization = hex!( + " + 723c692fa94b563faa41cf99b5759f8d0dc2606c90df30e8ae1813b1068d5cddd60 + 0c88978733e6399d65a1b5c5c025030a3505737c4207075e11fce168ba97246a545 + 92e5217ea54b1bc68efcdf15e8bf227d098d84d403994cebe774a119cfcbcec2eee + a73d09306e395019d9b891e8c9d6acaa1751cacde66f4010f748c9e0d705b03830c + 7c83e0c5e95a21dfb8f1976cf40cd67541f38bb75d1fed1bb9cc09 + " + ); + let deserialized = + SignatureShare::deserialize_from(&serialization[..]).expect("deserialization failed"); + assert_eq!(serialization, deserialized.serialize()); + } +} diff --git a/src/signing_commitment.rs b/src/signing_commitment.rs index 7417775..899c40d 100644 --- a/src/signing_commitment.rs +++ b/src/signing_commitment.rs @@ -227,6 +227,7 @@ mod tests { use super::SigningCommitment; use crate::frost::keys::SigningShare; use crate::participant::Secret; + use hex_literal::hex; use rand::thread_rng; #[test] @@ -256,6 +257,25 @@ mod tests { assert_eq!(deserialized, commitment); } + #[test] + fn deserialization_regression() { + let serialization = hex!( + " + 307be5a2c20495d05966fc12b2cee3ea4d44cb3623f92b0f6a391c626fa7708e835 + 26e886448d5ef376c5d09675aed3e711cd3e0df9f6c607604e6a7371a210e725c3a + 20a22aebc59d856bfbaa48fde8f8ea6fe48ddd978555932c283e760397f78b4b468 + 2f9b70f8baad6d7752f5e25bcbc6b3453d16d92589da722ad13a7390d0057c6aae8 + 363a50e835b89b44bccdd5889ef5a362fa89d841c96e65b34dbe3adf8f71faa041f + 394ef6b127c4b6b1e43714f32c450e8d3d089b376915acd6500639cad9b202c479e + 4216e2d4d16cad09b634e01270f4a52707d924fd9834e6206f48f04388ae90bcd63 + f901369c6034760245574a2d3068f52b617d33ca1a417ea391d3785b542f5 + " + ); + let deserialized = SigningCommitment::deserialize_from(&serialization[..]) + .expect("deserialization failed"); + assert_eq!(serialization, deserialized.serialize()); + } + #[test] fn test_invalid_deserialization() { let mut rng = thread_rng();