Skip to content

Commit

Permalink
export all of p256k1 as curve, so it can be replaced in the future, a…
Browse files Browse the repository at this point in the history
…nd no one needs to include it directly
  • Loading branch information
xoloki committed Nov 28, 2023
1 parent 3cc9ddb commit 9f54f4e
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 24 deletions.
10 changes: 9 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 8 additions & 1 deletion src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/state_machine/coordinator/fire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +16,6 @@ use crate::{
},
taproot::SchnorrProof,
traits::Aggregator as AggregatorTrait,
Point,
};

/// The coordinator for the FIRE algorithm
Expand Down
2 changes: 1 addition & 1 deletion src/state_machine/coordinator/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +16,6 @@ use crate::{
},
taproot::SchnorrProof,
traits::Aggregator as AggregatorTrait,
Point,
};

/// The coordinator for the FROST algorithm
Expand Down
7 changes: 5 additions & 2 deletions src/state_machine/coordinator/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/state_machine/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ 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,
},
state_machine::{PublicKeys, StateMachine},
traits::Signer as SignerTrait,
util::{decrypt, encrypt, make_shared_secret},
Compressed, Point, Scalar,
};

#[derive(Debug, Clone, PartialEq)]
Expand Down
10 changes: 9 additions & 1 deletion src/taproot.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vss.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down

0 comments on commit 9f54f4e

Please sign in to comment.