From 94953f694dff36390e4055af2387e2ec30c9834d Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 21 Feb 2025 15:12:09 +0100 Subject: [PATCH] Self-review cleanup and tweaks --- synedrion/src/cggmp21/conversion.rs | 4 +--- synedrion/src/cggmp21/entities.rs | 2 +- synedrion/src/cggmp21/interactive_signing.rs | 2 +- synedrion/src/cggmp21/params.rs | 20 +++++++++++--------- synedrion/src/curve/arithmetic.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/synedrion/src/cggmp21/conversion.rs b/synedrion/src/cggmp21/conversion.rs index 829990a..d98ec3b 100644 --- a/synedrion/src/cggmp21/conversion.rs +++ b/synedrion/src/cggmp21/conversion.rs @@ -28,9 +28,7 @@ fn uint_from_scalar(value: &Scalar

) -> ( value: &Scalar

, ) -> PublicSigned<::Uint> { - // TODO: When elliptic-curve upgrades to crypto-bigint v0.6 the Integer trait will implement - // BitOps so we can do `P::CURVE_ORDER.bits_vartime()` directly I reckon. - let order_bits = BitOps::bits_vartime(&P::CURVE_ORDER.get()); + let order_bits = P::CURVE_ORDER.as_ref().bits_vartime(); PublicSigned::new_positive(uint_from_scalar::

(value), order_bits).expect(concat![ "a curve scalar value is smaller than the half of `PaillierParams::Uint` range, ", "so it is still positive when treated as a 2-complement signed value" diff --git a/synedrion/src/cggmp21/entities.rs b/synedrion/src/cggmp21/entities.rs index 319377a..ef0004a 100644 --- a/synedrion/src/cggmp21/entities.rs +++ b/synedrion/src/cggmp21/entities.rs @@ -112,7 +112,7 @@ pub(crate) struct PublicAuxInfoPrecomputed { pub struct KeyShareChange { pub(crate) owner: I, /// The value to be added to the secret share. - pub(crate) secret_share_change: Secret>, + pub(crate) secret_share_change: Secret>, // `x_i^* - x_i == \sum_{j} x_j^i` /// The values to be added to the public shares of remote nodes. pub(crate) public_share_changes: BTreeMap>, // `X_k^* - X_k == \sum_j X_j^k`, for all nodes } diff --git a/synedrion/src/cggmp21/interactive_signing.rs b/synedrion/src/cggmp21/interactive_signing.rs index 6a32621..ad5970d 100644 --- a/synedrion/src/cggmp21/interactive_signing.rs +++ b/synedrion/src/cggmp21/interactive_signing.rs @@ -45,7 +45,7 @@ use crate::{ }; /// Prehashed message to sign. -// TODO: Type aliases are not enforced by the compiler, but it should be. Maybe one day it will? +// TODO: Type aliases are not enforced by the compiler, but they should be. Maybe one? #[allow(type_alias_bounds)] pub type PrehashedMessage = FieldBytes; diff --git a/synedrion/src/cggmp21/params.rs b/synedrion/src/cggmp21/params.rs index eb644d3..fa6a056 100644 --- a/synedrion/src/cggmp21/params.rs +++ b/synedrion/src/cggmp21/params.rs @@ -8,7 +8,7 @@ use crypto_bigint::{BitOps, NonZero, Uint, U1024, U2048, U4096, U512, U8192}; use digest::generic_array::{ArrayLength, GenericArray}; use ecdsa::hazmat::{DigestPrimitive, SignPrimitive, VerifyPrimitive}; use primeorder::elliptic_curve::{ - bigint::{Concat, Uint as CurveUint}, + bigint::{self as bigintv05, Concat, Uint as CurveUint}, point::DecompressPoint, sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint}, Curve, CurveArithmetic, PrimeCurve, @@ -132,8 +132,7 @@ where /// The elliptic curve (of prime order) used. type Curve: CurveArithmetic + PrimeCurve + HashableType + DigestPrimitive; /// Double the curve Scalar-width integer type. - type WideCurveUint: primeorder::elliptic_curve::bigint::Integer - + primeorder::elliptic_curve::bigint::Split::Uint>; + type WideCurveUint: bigintv05::Integer + bigintv05::Split::Uint>; // TODO: We should get rid of this entirely, along with the FofHasher. Instead generate a Box<[u8]> of length 2 * P::SECURITY_BITS and use that. /// Bla type HashOutput: Clone @@ -205,7 +204,7 @@ pub struct TestParams; // - P^{fac} assumes $N ~ 2^{4 \ell + 2 \eps}$ impl SchemeParams for TestParams { type Curve = TinyCurve64; - type WideCurveUint = primeorder::elliptic_curve::bigint::U384; + type WideCurveUint = bigintv05::U384; // TODO: 8*24 = 192, this is to work around an issue with the ModulusSize-trait. This should be ideally be 8 bytes long. type HashOutput = [u8; 24]; const SECURITY_BITS: usize = 16; @@ -230,7 +229,7 @@ pub struct TestParams32; #[cfg(test)] impl SchemeParams for TestParams32 { type Curve = TinyCurve32; - type WideCurveUint = primeorder::elliptic_curve::bigint::U384; + type WideCurveUint = bigintv05::U384; type HashOutput = [u8; 24]; const SECURITY_BITS: usize = 16; const SECURITY_PARAMETER: usize = 10; @@ -254,7 +253,7 @@ pub struct ProductionParams112; impl SchemeParams for ProductionParams112 { type Curve = k256::Secp256k1; - type WideCurveUint = primeorder::elliptic_curve::bigint::U512; + type WideCurveUint = bigintv05::U512; type HashOutput = [u8; 32]; const SECURITY_BITS: usize = 112; const SECURITY_PARAMETER: usize = 256; @@ -274,9 +273,10 @@ impl SchemeParams for ProductionParams112 { #[cfg(test)] mod tests { - use primeorder::elliptic_curve::bigint::{U256, U64}; - - use super::{upcast_uint, ProductionParams112, SchemeParams}; + use super::{ + bigintv05::{U256, U64}, + upcast_uint, ProductionParams112, SchemeParams, TestParams, TestParams32, + }; #[test] fn upcast_uint_results_in_a_bigger_type() { @@ -304,5 +304,7 @@ mod tests { #[test] fn parameter_consistency() { assert!(ProductionParams112::are_self_consistent()); + assert!(TestParams::are_self_consistent()); + assert!(TestParams32::are_self_consistent()); } } diff --git a/synedrion/src/curve/arithmetic.rs b/synedrion/src/curve/arithmetic.rs index f165a9b..e079d7e 100644 --- a/synedrion/src/curve/arithmetic.rs +++ b/synedrion/src/curve/arithmetic.rs @@ -83,7 +83,7 @@ impl HashableType for TinyCurve32 { type BackendScalar

= <

::Curve as CurveArithmetic>::Scalar; #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PartialOrd, Ord, Zeroize)] -pub(crate) struct Scalar(::Scalar); +pub(crate) struct Scalar(BackendScalar

); impl Scalar

{ pub const ZERO: Self = Self(BackendScalar::

::ZERO);