Skip to content

Commit

Permalink
Self-review cleanup and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Feb 21, 2025
1 parent 8682bad commit 94953f6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 1 addition & 3 deletions synedrion/src/cggmp21/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ fn uint_from_scalar<P: SchemeParams>(value: &Scalar<P>) -> <P::Paillier as Paill
pub(crate) fn public_signed_from_scalar<P: SchemeParams>(
value: &Scalar<P>,
) -> PublicSigned<<P::Paillier as PaillierParams>::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::<P>(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"
Expand Down
2 changes: 1 addition & 1 deletion synedrion/src/cggmp21/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub(crate) struct PublicAuxInfoPrecomputed<P: SchemeParams> {
pub struct KeyShareChange<P: SchemeParams, I: Ord> {
pub(crate) owner: I,
/// The value to be added to the secret share.
pub(crate) secret_share_change: Secret<Scalar<P>>,
pub(crate) secret_share_change: Secret<Scalar<P>>, // `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<I, Point<P>>, // `X_k^* - X_k == \sum_j X_j^k`, for all nodes
}
Expand Down
2 changes: 1 addition & 1 deletion synedrion/src/cggmp21/interactive_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: Curve> = FieldBytes<C>;

Expand Down
20 changes: 11 additions & 9 deletions synedrion/src/cggmp21/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Output = <Self::Curve as Curve>::Uint>;
type WideCurveUint: bigintv05::Integer + bigintv05::Split<Output = <Self::Curve as Curve>::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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion synedrion/src/curve/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl HashableType for TinyCurve32 {
type BackendScalar<P> = <<P as SchemeParams>::Curve as CurveArithmetic>::Scalar;

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

impl<P: SchemeParams> Scalar<P> {
pub const ZERO: Self = Self(BackendScalar::<P>::ZERO);
Expand Down

0 comments on commit 94953f6

Please sign in to comment.