From 9f54f4e64c48b8d94a40a3fcb7ce8d28f0b8e598 Mon Sep 17 00:00:00 2001 From: Joey Yandle Date: Tue, 28 Nov 2023 14:14:49 -0500 Subject: [PATCH] export all of p256k1 as curve, so it can be replaced in the future, and no one needs to include it directly --- src/common.rs | 10 +++++++++- src/compute.rs | 9 ++++++++- src/errors.rs | 2 +- src/lib.rs | 7 +------ src/net.rs | 2 +- src/schnorr.rs | 8 +++++++- src/state_machine/coordinator/fire.rs | 2 +- src/state_machine/coordinator/frost.rs | 2 +- src/state_machine/coordinator/mod.rs | 7 +++++-- src/state_machine/mod.rs | 3 +-- src/state_machine/signer/mod.rs | 5 ++++- src/taproot.rs | 10 +++++++++- src/traits.rs | 2 +- src/util.rs | 2 +- src/v1.rs | 5 ++++- src/v2.rs | 5 ++++- src/vss.rs | 2 +- 17 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/common.rs b/src/common.rs index b0aebedf..57f846a9 100644 --- a/src/common.rs +++ b/src/common.rs @@ -7,7 +7,15 @@ use num_traits::{One, Zero}; use rand_core::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; -use crate::{compute::challenge, schnorr::ID, MultiMult, Point, Scalar, G}; +use crate::{ + compute::challenge, + curve::{ + point::{Point, G}, + scalar::Scalar, + traits::MultiMult, + }, + schnorr::ID, +}; /// A merkle root is a 256 bit hash pub type MerkleRoot = [u8; 32]; diff --git a/src/compute.rs b/src/compute.rs index 47152456..6cf2a750 100644 --- a/src/compute.rs +++ b/src/compute.rs @@ -2,7 +2,14 @@ use core::iter::zip; use num_traits::{One, Zero}; use sha2::{Digest, Sha256}; -use crate::{common::PublicNonce, util::hash_to_scalar, Compressed, Point, PointError, Scalar, G}; +use crate::{ + common::PublicNonce, + curve::{ + point::{Compressed, Error as PointError, Point, G}, + scalar::Scalar, + }, + util::hash_to_scalar, +}; #[allow(non_snake_case)] /// Compute a binding value from the party ID, public nonces, and signed message diff --git a/src/errors.rs b/src/errors.rs index e0a2a393..d22fa5e0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,6 @@ use thiserror::Error; -use crate::{PointError, Scalar}; +use crate::curve::{point::Error as PointError, scalar::Scalar}; #[derive(Error, Debug, Clone)] /// Errors which can happen during distributed key generation diff --git a/src/lib.rs b/src/lib.rs index d2186794..2e87da67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,9 +30,4 @@ pub mod v2; /// Shamir secret sharing, using in distributed key generation pub mod vss; -pub use p256k1::{ - ecdsa, field, - point::{Compressed, Error as PointError, Point, G, N}, - scalar::{Error as ScalarError, Scalar}, - traits::MultiMult, -}; +pub use p256k1 as curve; diff --git a/src/net.rs b/src/net.rs index 59d23dc2..da8512e3 100644 --- a/src/net.rs +++ b/src/net.rs @@ -4,7 +4,7 @@ use sha2::{Digest, Sha256}; use crate::{ common::{MerkleRoot, PolyCommitment, PublicNonce, SignatureShare}, - ecdsa, Scalar, + curve::{ecdsa, scalar::Scalar}, }; /// Trait to encapsulate sign/verify, users only need to impl hash diff --git a/src/schnorr.rs b/src/schnorr.rs index b6fe187f..e0051d26 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -2,7 +2,13 @@ use rand_core::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -use crate::{util::hash_to_scalar, Point, Scalar, G}; +use crate::{ + curve::{ + point::{Point, G}, + scalar::Scalar, + }, + util::hash_to_scalar, +}; #[allow(non_snake_case)] #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/state_machine/coordinator/fire.rs b/src/state_machine/coordinator/fire.rs index 2a893889..8378d3ba 100644 --- a/src/state_machine/coordinator/fire.rs +++ b/src/state_machine/coordinator/fire.rs @@ -5,6 +5,7 @@ use tracing::{debug, error, info, warn}; use crate::{ common::{MerkleRoot, PolyCommitment, PublicNonce, Signature, SignatureShare}, compute, + curve::point::Point, net::{ DkgBegin, DkgPublicShares, Message, NonceRequest, NonceResponse, Packet, Signable, SignatureShareRequest, @@ -15,7 +16,6 @@ use crate::{ }, taproot::SchnorrProof, traits::Aggregator as AggregatorTrait, - Point, }; /// The coordinator for the FIRE algorithm diff --git a/src/state_machine/coordinator/frost.rs b/src/state_machine/coordinator/frost.rs index 7b02db2d..ddb77217 100644 --- a/src/state_machine/coordinator/frost.rs +++ b/src/state_machine/coordinator/frost.rs @@ -5,6 +5,7 @@ use tracing::{debug, info}; use crate::{ common::{MerkleRoot, PolyCommitment, PublicNonce, Signature, SignatureShare}, compute, + curve::point::Point, net::{ DkgBegin, DkgPublicShares, Message, NonceRequest, NonceResponse, Packet, Signable, SignatureShareRequest, @@ -15,7 +16,6 @@ use crate::{ }, taproot::SchnorrProof, traits::Aggregator as AggregatorTrait, - Point, }; /// The coordinator for the FROST algorithm diff --git a/src/state_machine/coordinator/mod.rs b/src/state_machine/coordinator/mod.rs index e8e8c504..181bcd7f 100644 --- a/src/state_machine/coordinator/mod.rs +++ b/src/state_machine/coordinator/mod.rs @@ -1,6 +1,9 @@ use crate::{ - common::MerkleRoot, errors::AggregatorError, net::Packet, state_machine::OperationResult, - Point, Scalar, + common::MerkleRoot, + curve::{point::Point, scalar::Scalar}, + errors::AggregatorError, + net::Packet, + state_machine::OperationResult, }; use hashbrown::{HashMap, HashSet}; use std::time::Duration; diff --git a/src/state_machine/mod.rs b/src/state_machine/mod.rs index ce1e4141..427090b7 100644 --- a/src/state_machine/mod.rs +++ b/src/state_machine/mod.rs @@ -3,10 +3,9 @@ use thiserror::Error; use crate::{ common::Signature, - ecdsa, + curve::{ecdsa, point::Point}, errors::{AggregatorError, DkgError as DkgCryptoError}, taproot::SchnorrProof, - Point, }; /// A generic state machine diff --git a/src/state_machine/signer/mod.rs b/src/state_machine/signer/mod.rs index 4df149b3..40625f18 100644 --- a/src/state_machine/signer/mod.rs +++ b/src/state_machine/signer/mod.rs @@ -5,6 +5,10 @@ use tracing::{debug, info, trace, warn}; use crate::{ common::{PolyCommitment, PublicNonce}, + curve::{ + point::{Compressed, Point}, + scalar::Scalar, + }, net::{ DkgBegin, DkgEnd, DkgPrivateShares, DkgPublicShares, DkgStatus, Message, NonceRequest, NonceResponse, Packet, Signable, SignatureShareRequest, SignatureShareResponse, @@ -12,7 +16,6 @@ use crate::{ state_machine::{PublicKeys, StateMachine}, traits::Signer as SignerTrait, util::{decrypt, encrypt, make_shared_secret}, - Compressed, Point, Scalar, }; #[derive(Debug, Clone, PartialEq)] diff --git a/src/taproot.rs b/src/taproot.rs index a43578b4..c52b680d 100644 --- a/src/taproot.rs +++ b/src/taproot.rs @@ -1,4 +1,12 @@ -use crate::{common::Signature, compute, field, Point, Scalar, G}; +use crate::{ + common::Signature, + compute, + curve::{ + field, + point::{Point, G}, + scalar::Scalar, + }, +}; /// A SchnorrProof in BIP-340 format #[allow(non_snake_case)] diff --git a/src/traits.rs b/src/traits.rs index fb38cbd0..762ffb4f 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -3,9 +3,9 @@ use rand_core::{CryptoRng, RngCore}; use crate::{ common::{MerkleRoot, PolyCommitment, PublicNonce, Signature, SignatureShare}, + curve::{point::Point, scalar::Scalar}, errors::{AggregatorError, DkgError}, taproot::SchnorrProof, - Point, Scalar, }; /// A trait which provides a common `Signer` interface for `v1` and `v2` diff --git a/src/util.rs b/src/util.rs index 2b99a569..5792515f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,7 +2,7 @@ use aes_gcm::{aead::Aead, Aes256Gcm, Error as AesGcmError, KeyInit, Nonce}; use rand_core::{CryptoRng, RngCore}; use sha2::{Digest, Sha256}; -use crate::{Point, Scalar}; +use crate::curve::{point::Point, scalar::Scalar}; /// Size of the AES-GCM nonce pub const AES_GCM_NONCE_SIZE: usize = 12; diff --git a/src/v1.rs b/src/v1.rs index 48637d73..21bbb577 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -7,12 +7,15 @@ use serde::{Deserialize, Serialize}; use crate::{ common::{CheckPrivateShares, Nonce, PolyCommitment, PublicNonce, Signature, SignatureShare}, compute, + curve::{ + point::{Point, G}, + scalar::Scalar, + }, errors::{AggregatorError, DkgError}, schnorr::ID, taproot::SchnorrProof, traits, vss::VSS, - Point, Scalar, G, }; #[derive(Debug, Deserialize, Serialize)] diff --git a/src/v2.rs b/src/v2.rs index 82cc32a9..fe483311 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -7,12 +7,15 @@ use serde::{Deserialize, Serialize}; use crate::{ common::{Nonce, PolyCommitment, PublicNonce, Signature, SignatureShare}, compute, + curve::{ + point::{Point, G}, + scalar::Scalar, + }, errors::{AggregatorError, DkgError}, schnorr::ID, taproot::SchnorrProof, traits, vss::VSS, - Point, Scalar, G, }; /// A map of private keys indexed by key ID diff --git a/src/vss.rs b/src/vss.rs index 50f7c6da..4ffbcb45 100644 --- a/src/vss.rs +++ b/src/vss.rs @@ -1,7 +1,7 @@ use polynomial::Polynomial; use rand_core::{CryptoRng, RngCore}; -use crate::Scalar; +use crate::curve::scalar::Scalar; /// A verifiable secret share algorithm pub struct VSS {}