Skip to content

Commit

Permalink
Merge pull request #132 from LLFourn/clean_up_feature_falgs
Browse files Browse the repository at this point in the history
Clean up feature flags make things compile with alloc and --no-default-features
  • Loading branch information
LLFourn committed Nov 24, 2022
2 parents e041ac0 + 147896a commit da6ffd2
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 142 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,23 @@ jobs:
strategy:
fail-fast: false
matrix:
args: [ "--all-features" ]
rust: [stable]
target: ["x86_64-unknown-linux-gnu", "armv7-unknown-linux-gnueabihf"]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
toolchain: 1.60.0
target: ${{ matrix.target }}
override: true
- uses: Swatinem/rust-cache@v2.0.0

- name: cross test (armv7)
- name: test-on-target
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }}
command: test
args: ${{ matrix.args }} --release --verbose --target ${{ matrix.target }}
args: --all-features --release --target ${{ matrix.target }}

# test nightly build/test
test-nightly:
Expand All @@ -66,11 +64,35 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --verbose --all-features
args: --release --all-features

# test without default features
test-minimal:
runs-on: ubuntu-latest
strategy:
matrix:
package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: "x86_64-unknown-linux-gnu"
override: true
- uses: Swatinem/rust-cache@v2.0.0
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --no-default-features -p ${{ matrix.package }}


# test with alloc feature only
test-alloc:
runs-on: ubuntu-latest
strategy:
matrix:
package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -83,7 +105,8 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --verbose --no-default-features
args: --release --no-default-features --features alloc,serde -p ${{ matrix.package }}


doc-build:
name: doc-build
Expand Down
18 changes: 8 additions & 10 deletions ecdsa_fun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "ecdsa_fun"
version = "0.7.1"
authors = ["LLFourn <lloyd.fourn@gmail.com>"]
edition = "2021"
rust-version = "1.56"
rust-version = "1.60"
license = "0BSD"
homepage = "https://github.com/LLFourn/secp256kfun/tree/master/ecdsa_fun"
repository = "https://github.com/LLFourn/secp256kfun"
Expand All @@ -13,12 +13,8 @@ readme = "README.md"
categories = ["cryptography", "cryptography::cryptocurrencies"]
keywords = ["bitcoin", "ecdsa", "secp256k1"]

[package.metadata.docs.rs]
features = ["all"]

[dependencies]
secp256kfun = { path = "../secp256kfun", version = "0.7.1", default-features = false }
serde_crate = { package = "serde", version = "1.0", default-features = false, optional = true, features = ["derive", "alloc"] }
sigma_fun = { path = "../sigma_fun", version = "0.4.1", features = ["secp256k1"], default-features = false, optional = true }
rand_chacha = { version = "0.3", optional = true } # needed for adaptor signatures atm but would be nice to get rid of
bincode = { version = "1.0", optional = true }
Expand All @@ -38,11 +34,13 @@ harness = false

[features]
default = ["std"]
all = ["std", "serde", "libsecp_compat", "adaptor"]
libsecp_compat = ["secp256kfun/libsecp_compat"]
std = ["alloc"]
alloc = ["secp256kfun/alloc" ]
serde = ["secp256kfun/serde", "serde_crate"]
# when https://github.com/rust-lang/cargo/issues/8832 is stabilized use the ? syntax to fix this
adaptor = ["sigma_fun", "bincode", "rand_chacha", "sigma_fun/serde", "sigma_fun/alloc"]
alloc = ["secp256kfun/alloc", "sigma_fun?/alloc" ]
serde = ["secp256kfun/serde","sigma_fun?/serde"]
adaptor = ["dep:sigma_fun", "dep:bincode", "rand_chacha"]
proptest = ["secp256kfun/proptest"]


[package.metadata.docs.rs]
all-features = true
5 changes: 3 additions & 2 deletions ecdsa_fun/src/adaptor/encrypted_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ secp256kfun::impl_display_debug_serialize! {
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
derive(crate::serde::Deserialize, crate::serde::Serialize),
serde(crate = "crate::serde")
)]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub(crate) struct EncryptedSignatureInternal {
pub R: PointNonce,
pub R_hat: Point,
Expand Down
7 changes: 4 additions & 3 deletions ecdsa_fun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#![no_std]
#![allow(non_snake_case)]

#[cfg(all(feature = "alloc", not(feature = "std")))]
#[macro_use]
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "std")]
Expand All @@ -14,7 +13,8 @@ extern crate std;
mod libsecp_compat;

#[cfg(feature = "serde")]
extern crate serde_crate as serde;
/// Rexport `serde`
pub use fun::serde;

use fun::{
derive_nonce, g,
Expand All @@ -27,6 +27,7 @@ pub use secp256kfun::nonce;
mod signature;
pub use signature::Signature;
#[cfg(feature = "adaptor")]
#[cfg_attr(docsrs, doc(cfg(feature = "adaptor")))]
pub mod adaptor;

/// An instance of the ECDSA signature scheme.
Expand Down
36 changes: 9 additions & 27 deletions ecdsa_fun/tests/adaptor_test_vectors.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
#![cfg(all(feature = "serde", feature = "alloc", feature = "adaptor"))]
extern crate serde_crate as serde;

static DLC_SPEC_JSON: &'static str = include_str!("./test_vectors.json");
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature, HashTranscript},
fun::{Point, Scalar},
Signature,
serde, Signature,
};
use sha2::Sha256;

#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(tag = "kind", rename_all = "snake_case", crate = "self::serde")]
enum TestVector {
Verification(Verification),
Recovery(Recovery),
Serialization(Serialization),
}

#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(crate = "self::serde")]
struct Recovery {
encryption_key: Point,
signature: Signature,
adaptor_sig: EncryptedSignature,
decryption_key: Option<Scalar>,
}

#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(crate = "self::serde")]
struct Verification {
adaptor_sig: EncryptedSignature,
public_signing_key: Point,
Expand All @@ -51,12 +37,8 @@ struct Verification {
error: Option<String>,
}

#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(crate = "self::serde")]
struct Serialization {
adaptor_sig: String,
error: Option<String>,
Expand Down
4 changes: 3 additions & 1 deletion ecdsa_fun/tests/against_c_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ecdsa_fun::{
self,
fun::{
hex,
marker::*,
secp256k1::{self, ecdsa, Message, PublicKey, SecretKey},
Point, Scalar,
},
Expand Down Expand Up @@ -68,7 +69,8 @@ fn ecdsa_verify_high_message() {
.unwrap();
let c_message = Message::from_slice(&message[..]).unwrap();
let c_signature = secp.sign_ecdsa(&c_message, &c_secret_key);
let signature = ecdsa_fun::Signature::from_bytes(c_signature.serialize_compact()).unwrap();
let signature =
ecdsa_fun::Signature::<Public>::from_bytes(c_signature.serialize_compact()).unwrap();

assert!(ecdsa.verify(&verification_key, &message, &signature));
}
Expand Down
14 changes: 6 additions & 8 deletions schnorr_fun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "schnorr_fun"
version = "0.7.1"
authors = ["LLFourn <lloyd.fourn@gmail.com>"]
edition = "2021"
rust-version = "1.56"
rust-version = "1.60"
license = "0BSD"
homepage = "https://github.com/LLFourn/secp256kfun/tree/master/schnorr_fun"
repository = "https://github.com/LLFourn/secp256kfun"
Expand All @@ -13,12 +13,8 @@ description = "BIP340 Schnorr signatures based on secp256kfun"
categories = ["cryptography", "cryptography::cryptocurrencies"]
keywords = ["bitcoin", "schnorr"]

[package.metadata.docs.rs]
features = ["all"]

[dependencies]
secp256kfun = { path = "../secp256kfun", version = "0.7.1", default-features = false }
serde_crate = { package = "serde", version = "1.0", default-features = false, optional = true, features = ["derive", "alloc"] }

[dev-dependencies]
rand = { version = "0.8" }
Expand All @@ -44,9 +40,11 @@ harness = false

[features]
default = ["std"]
all = ["std", "serde", "libsecp_compat", "proptest"]
alloc = ["secp256kfun/alloc"]
alloc = ["secp256kfun/alloc" ]
std = ["alloc", "secp256kfun/std"]
serde = ["serde_crate", "secp256kfun/serde"]
serde = ["secp256kfun/serde"]
libsecp_compat = ["secp256kfun/libsecp_compat"]
proptest = ["secp256kfun/proptest"]

[package.metadata.docs.rs]
all-features = true
5 changes: 3 additions & 2 deletions schnorr_fun/src/adaptor/encrypted_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use secp256kfun::{marker::*, Point, Scalar};
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
derive(crate::serde::Deserialize, crate::serde::Serialize),
serde(crate = "crate::serde")
)]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub struct EncryptedSignature<S = Public> {
/// The `R` point in the signature
pub R: Point<EvenY, Public>,
Expand Down
12 changes: 6 additions & 6 deletions schnorr_fun/src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
//! Note that if a key generation sesssion fails you must always start a fresh session with a different session id.
#![cfg(feature = "serde")]
pub use crate::binonce::{Nonce, NonceKeyPair};
use crate::{Message, Schnorr, Signature, Vec};
use crate::{Message, Schnorr, Signature};
use alloc::{collections::BTreeMap, vec::Vec};
use secp256kfun::{
derive_nonce_rng,
digest::{generic_array::typenum::U32, Digest},
Expand All @@ -157,7 +158,6 @@ use secp256kfun::{
rand_core::{RngCore, SeedableRng},
s, Point, Scalar, G,
};
use std::collections::BTreeMap;

/// The FROST context.
///
Expand Down Expand Up @@ -282,14 +282,14 @@ impl std::error::Error for FinishKeyGenError {}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(crate = "serde_crate")
derive(crate::serde::Deserialize, crate::serde::Serialize),
serde(crate = "crate::serde")
)]
pub struct FrostKey<T: PointType> {
/// The joint public key of the frost multisignature.
#[serde(bound(
deserialize = "Point<T>: serde::de::Deserialize<'de>",
serialize = "Point<T>: serde::Serialize"
deserialize = "Point<T>: crate::serde::de::Deserialize<'de>",
serialize = "Point<T>: crate::serde::Serialize"
))]
public_key: Point<T>,
/// Everyone else's point polynomial evaluated at your index, used in partial signature validation.
Expand Down
13 changes: 5 additions & 8 deletions schnorr_fun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(feature = "alloc")]
#[allow(unused)]
#[macro_use]
extern crate alloc;
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub(crate) use alloc::vec::Vec;

#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(feature = "std")]
pub(crate) use std::vec::Vec;

#[cfg(feature = "serde")]
extern crate serde_crate as serde;

pub use secp256kfun as fun;
pub use secp256kfun::nonce;

#[cfg(feature = "serde")]
pub use secp256kfun::serde;

/// binonces for Musig and FROST
pub mod binonce;
// musig needs vecs
Expand Down
Loading

0 comments on commit da6ffd2

Please sign in to comment.