From de9710413a33fafa29b46841b31135dd3789a1f2 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 3 Jun 2022 00:55:41 -0400 Subject: [PATCH] Use big endian throughout FROST Slightly changes serialization of keys to be t-n-i instead of n-t-i. --- crypto/frost/src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crypto/frost/src/lib.rs b/crypto/frost/src/lib.rs index 5d2c5f19..35071889 100644 --- a/crypto/frost/src/lib.rs +++ b/crypto/frost/src/lib.rs @@ -312,9 +312,9 @@ impl MultisigKeys { ); serialized.push(C::id_len()); serialized.extend(C::id().as_bytes()); - serialized.extend(&self.params.n.to_le_bytes()); - serialized.extend(&self.params.t.to_le_bytes()); - serialized.extend(&self.params.i.to_le_bytes()); + serialized.extend(&self.params.t.to_be_bytes()); + serialized.extend(&self.params.n.to_be_bytes()); + serialized.extend(&self.params.i.to_be_bytes()); serialized.extend(&C::F_to_bytes(&self.secret_share)); serialized.extend(&C::G_to_bytes(&self.group_key)); for l in 1 ..= self.params.n.into() { @@ -346,19 +346,20 @@ impl MultisigKeys { } cursor += id_len; - if serialized.len() < (cursor + 8) { - Err(FrostError::InternalError("participant quantity wasn't included".to_string()))?; + if serialized.len() < (cursor + 4) { + Err(FrostError::InternalError("participant quantities weren't included".to_string()))?; } - let n = u16::from_le_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); + let t = u16::from_be_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); + cursor += 2; + + let n = u16::from_be_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); cursor += 2; if serialized.len() != MultisigKeys::::serialized_len(n) { Err(FrostError::InternalError("incorrect serialization length".to_string()))?; } - let t = u16::from_le_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); - cursor += 2; - let i = u16::from_le_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); + let i = u16::from_be_bytes(serialized[cursor .. (cursor + 2)].try_into().unwrap()); cursor += 2; let secret_share = C::F_from_slice(&serialized[cursor .. (cursor + C::F_len())])