Merge rust-bitcoin/rust-secp256k1#709: Bump MSRV to 1.63
55c2efc320
Bump MSRV to 1.63 (Martin Habovstiak) Pull request description: The version 1.63 satisfies our requirements for MSRV and provides significant benefits so this commit bumps it. This commit also starts using weak dependencies. ACKs for top commit: tcharding: ACK55c2efc320
Tree-SHA512: 565fd46768384e7c026c3aa8873e321a20425a6526bcd379ba442cf2504517a435c6c14e21186b36c99185d0a8439f4de2d3ba097b91119483d1a83ab05010ba
This commit is contained in:
commit
c4c029fca2
|
@ -57,7 +57,7 @@ jobs:
|
|||
run: ./contrib/test.sh
|
||||
|
||||
MSRV:
|
||||
name: Test - 1.56.1 toolchain
|
||||
name: Test - MSRV toolchain
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
@ -65,7 +65,7 @@ jobs:
|
|||
- name: Checkout Crate
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout Toolchain
|
||||
uses: dtolnay/rust-toolchain@1.56.1
|
||||
uses: dtolnay/rust-toolchain@1.63.0
|
||||
- name: Running test script
|
||||
env:
|
||||
DO_FEATURE_MATRIX: true
|
||||
|
|
16
Cargo.toml
16
Cargo.toml
|
@ -11,7 +11,7 @@ description = "Rust wrapper library for Pieter Wuille's `libsecp256k1`. Implemen
|
|||
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
|
||||
readme = "README.md"
|
||||
edition = "2021"
|
||||
rust-version = "1.56.1"
|
||||
rust-version = "1.63.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -19,18 +19,16 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["alloc", "secp256k1-sys/std"]
|
||||
std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "hashes?/std"]
|
||||
# allow use of Secp256k1::new and related API that requires an allocator
|
||||
alloc = ["secp256k1-sys/alloc"]
|
||||
hashes-std = ["std", "hashes/std"]
|
||||
rand-std = ["std", "rand", "rand/std", "rand/std_rng"]
|
||||
recovery = ["secp256k1-sys/recovery"]
|
||||
lowmemory = ["secp256k1-sys/lowmemory"]
|
||||
global-context = ["std"]
|
||||
# disable re-randomization of the global context, which provides some
|
||||
# defense-in-depth against sidechannel attacks. You should only use
|
||||
# this feature if you expect the `rand` crate's thread_rng to panic.
|
||||
# (If you are sure the `rand-std` feature will not be enabled, e.g.
|
||||
# (If you are sure the `rand` and `std` features will not be enabled, e.g.
|
||||
# if you are doing a no-std build, then this feature does nothing
|
||||
# and is not necessary.)
|
||||
global-context-less-secure = ["global-context"]
|
||||
|
@ -39,8 +37,6 @@ global-context-less-secure = ["global-context"]
|
|||
secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys" }
|
||||
serde = { version = "1.0.103", default-features = false, optional = true }
|
||||
|
||||
# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
|
||||
# the respective -std feature e.g., hashes-std
|
||||
hashes = { package = "bitcoin_hashes", version = ">= 0.12, <= 0.14", default-features = false, optional = true }
|
||||
rand = { version = "0.8", default-features = false, optional = true }
|
||||
|
||||
|
@ -59,15 +55,15 @@ unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fu
|
|||
|
||||
[[example]]
|
||||
name = "sign_verify_recovery"
|
||||
required-features = ["recovery", "hashes-std"]
|
||||
required-features = ["recovery", "hashes", "std"]
|
||||
|
||||
[[example]]
|
||||
name = "sign_verify"
|
||||
required-features = ["hashes-std"]
|
||||
required-features = ["hashes", "std"]
|
||||
|
||||
[[example]]
|
||||
name = "generate_keys"
|
||||
required-features = ["rand-std"]
|
||||
required-features = ["rand", "std"]
|
||||
|
||||
[workspace]
|
||||
members = ["secp256k1-sys"]
|
||||
|
|
|
@ -1 +1 @@
|
|||
msrv = "1.56.1"
|
||||
msrv = "1.63.0"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
set -ex
|
||||
|
||||
REPO_DIR=$(git rev-parse --show-toplevel)
|
||||
FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std"
|
||||
FEATURES="hashes global-context lowmemory rand recovery serde std alloc"
|
||||
|
||||
cargo --version
|
||||
rustc --version
|
||||
|
@ -62,17 +62,17 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
|
|||
fi
|
||||
|
||||
# Examples
|
||||
cargo run --locked --example sign_verify --features=hashes-std
|
||||
cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std
|
||||
cargo run --locked --example generate_keys --features=rand-std
|
||||
cargo run --locked --example sign_verify --features=hashes,std
|
||||
cargo run --locked --example sign_verify_recovery --features=recovery,hashes,std
|
||||
cargo run --locked --example generate_keys --features=rand,std
|
||||
fi
|
||||
|
||||
if [ "$DO_LINT" = true ]
|
||||
then
|
||||
cargo clippy --locked --all-features --all-targets -- -D warnings
|
||||
cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings
|
||||
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings
|
||||
cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings
|
||||
cargo clippy --locked --example sign_verify --features=hashes,std -- -D warnings
|
||||
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes,std -- -D warnings
|
||||
cargo clippy --locked --example generate_keys --features=rand,std -- -D warnings
|
||||
fi
|
||||
|
||||
# Build the docs if told to (this only works with the nightly toolchain)
|
||||
|
@ -120,7 +120,7 @@ fi
|
|||
# Bench if told to, only works with non-stable toolchain (nightly, beta).
|
||||
if [ "$DO_BENCH" = true ]
|
||||
then
|
||||
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std
|
||||
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand,std
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -47,7 +47,7 @@ fi
|
|||
git diff-index --check --cached $against -- || exit 1
|
||||
|
||||
# Check that code lints cleanly.
|
||||
cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1
|
||||
cargo clippy --features=rand,std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1
|
||||
|
||||
# Check that there are no formatting issues.
|
||||
cargo +nightly fmt --check || exit 1
|
||||
|
|
|
@ -14,7 +14,7 @@ readme = "README.md"
|
|||
build = "build.rs"
|
||||
links = "rustsecp256k1_v0_10_0"
|
||||
edition = "2021"
|
||||
rust-version = "1.56.1"
|
||||
rust-version = "1.63.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
|
@ -27,10 +27,11 @@ pub mod global {
|
|||
|
||||
/// A global static context to avoid repeatedly creating contexts.
|
||||
///
|
||||
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
|
||||
/// If `rand` and `std` feature is enabled, context will have been randomized using
|
||||
/// `thread_rng`.
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(all(feature = "global-context", feature = "rand-std"))] {
|
||||
/// # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{PublicKey, SECP256K1};
|
||||
/// let _ = SECP256K1.generate_keypair(&mut rand::thread_rng());
|
||||
/// # }
|
||||
|
@ -40,7 +41,7 @@ pub mod global {
|
|||
impl Deref for GlobalContext {
|
||||
type Target = Secp256k1<All>;
|
||||
|
||||
#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
|
||||
#[allow(unused_mut)] // Unused when `rand` + `std` is not enabled.
|
||||
fn deref(&self) -> &Self::Target {
|
||||
static ONCE: Once = Once::new();
|
||||
static mut CONTEXT: Option<Secp256k1<All>> = None;
|
||||
|
@ -48,7 +49,8 @@ pub mod global {
|
|||
let mut ctx = Secp256k1::new();
|
||||
#[cfg(all(
|
||||
not(target_arch = "wasm32"),
|
||||
feature = "rand-std",
|
||||
feature = "rand",
|
||||
feature = "std",
|
||||
not(feature = "global-context-less-secure")
|
||||
))]
|
||||
{
|
||||
|
@ -181,10 +183,12 @@ mod alloc_only {
|
|||
impl<C: Context> Secp256k1<C> {
|
||||
/// Lets you create a context in a generic manner (sign/verify/all).
|
||||
///
|
||||
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
|
||||
/// If `rand-std` feature is not enabled please consider randomizing the context as follows:
|
||||
/// If `rand` and `std` feature is enabled, context will have been randomized using
|
||||
/// `thread_rng`.
|
||||
/// If `rand` or `std` feature is not enabled please consider randomizing the context as
|
||||
/// follows:
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// # use secp256k1::Secp256k1;
|
||||
/// # use secp256k1::rand::{thread_rng, RngCore};
|
||||
/// let mut ctx = Secp256k1::new();
|
||||
|
@ -195,7 +199,10 @@ mod alloc_only {
|
|||
/// ctx.seeded_randomize(&seed);
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg_attr(not(feature = "rand-std"), allow(clippy::let_and_return, unused_mut))]
|
||||
#[cfg_attr(
|
||||
not(all(feature = "rand", feature = "std")),
|
||||
allow(clippy::let_and_return, unused_mut)
|
||||
)]
|
||||
pub fn gen_new() -> Secp256k1<C> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
ffi::types::sanity_checks_for_wasm();
|
||||
|
@ -214,7 +221,8 @@ mod alloc_only {
|
|||
|
||||
#[cfg(all(
|
||||
not(target_arch = "wasm32"),
|
||||
feature = "rand-std",
|
||||
feature = "rand",
|
||||
feature = "std",
|
||||
not(feature = "global-context-less-secure")
|
||||
))]
|
||||
{
|
||||
|
@ -229,27 +237,30 @@ mod alloc_only {
|
|||
impl Secp256k1<All> {
|
||||
/// Creates a new Secp256k1 context with all capabilities.
|
||||
///
|
||||
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
|
||||
/// If `rand-std` feature is not enabled please consider randomizing the context (see docs
|
||||
/// for `Secp256k1::gen_new()`).
|
||||
/// If `rand` and `std` feature is enabled, context will have been randomized using
|
||||
/// `thread_rng`.
|
||||
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
|
||||
/// docs for `Secp256k1::gen_new()`).
|
||||
pub fn new() -> Secp256k1<All> { Secp256k1::gen_new() }
|
||||
}
|
||||
|
||||
impl Secp256k1<SignOnly> {
|
||||
/// Creates a new Secp256k1 context that can only be used for signing.
|
||||
///
|
||||
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
|
||||
/// If `rand-std` feature is not enabled please consider randomizing the context (see docs
|
||||
/// for `Secp256k1::gen_new()`).
|
||||
/// If `rand` and `std` feature is enabled, context will have been randomized using
|
||||
/// `thread_rng`.
|
||||
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
|
||||
/// docs for `Secp256k1::gen_new()`).
|
||||
pub fn signing_only() -> Secp256k1<SignOnly> { Secp256k1::gen_new() }
|
||||
}
|
||||
|
||||
impl Secp256k1<VerifyOnly> {
|
||||
/// Creates a new Secp256k1 context that can only be used for verification.
|
||||
///
|
||||
/// * If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
|
||||
/// * If `rand-std` feature is not enabled please consider randomizing the context (see docs
|
||||
/// for `Secp256k1::gen_new()`).
|
||||
/// If `rand` and `std` feature is enabled, context will have been randomized using
|
||||
/// `thread_rng`.
|
||||
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
|
||||
/// docs for `Secp256k1::gen_new()`).
|
||||
pub fn verification_only() -> Secp256k1<VerifyOnly> { Secp256k1::gen_new() }
|
||||
}
|
||||
|
||||
|
|
10
src/ecdh.rs
10
src/ecdh.rs
|
@ -20,7 +20,7 @@ const SHARED_SECRET_SIZE: usize = constants::SECRET_KEY_SIZE;
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// # use secp256k1::{rand, Secp256k1};
|
||||
/// # use secp256k1::ecdh::SharedSecret;
|
||||
/// let s = Secp256k1::new();
|
||||
|
@ -110,7 +110,7 @@ impl AsRef<[u8]> for SharedSecret {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # #[cfg(all(feature = "hashes-std", feature = "rand-std"))] {
|
||||
/// # #[cfg(all(feature = "hashes", feature = "rand", feature = "std"))] {
|
||||
/// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey};
|
||||
/// # use secp256k1::hashes::{Hash, sha512};
|
||||
///
|
||||
|
@ -193,7 +193,7 @@ mod tests {
|
|||
use crate::Secp256k1;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn ecdh() {
|
||||
let s = Secp256k1::signing_only();
|
||||
let (sk1, pk1) = s.generate_keypair(&mut rand::thread_rng());
|
||||
|
@ -225,7 +225,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
#[cfg(not(secp256k1_fuzz))]
|
||||
#[cfg(all(feature = "hashes-std", feature = "rand-std"))]
|
||||
#[cfg(all(feature = "hashes", feature = "rand", feature = "std"))]
|
||||
fn hashes_and_sys_generate_same_secret() {
|
||||
use hashes::{sha256, Hash, HashEngine};
|
||||
|
||||
|
@ -275,7 +275,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[cfg(bench)]
|
||||
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
|
||||
#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std".
|
||||
mod benches {
|
||||
use test::{black_box, Bencher};
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ impl<C: Verification> Secp256k1<C> {
|
|||
/// verify-capable context.
|
||||
///
|
||||
/// ```rust
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// # use secp256k1::{rand, Secp256k1, Message, Error};
|
||||
/// #
|
||||
/// # let secp = Secp256k1::new();
|
||||
|
|
|
@ -219,7 +219,7 @@ mod tests {
|
|||
use crate::{Error, Message, Secp256k1, SecretKey};
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn capabilities() {
|
||||
let sign = Secp256k1::signing_only();
|
||||
let vrfy = Secp256k1::verification_only();
|
||||
|
@ -251,7 +251,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
#[rustfmt::skip]
|
||||
fn sign() {
|
||||
let mut s = Secp256k1::new();
|
||||
|
@ -276,7 +276,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
#[rustfmt::skip]
|
||||
fn sign_with_noncedata() {
|
||||
let mut s = Secp256k1::new();
|
||||
|
@ -301,7 +301,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_and_verify_fail() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -323,7 +323,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_with_recovery() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -339,7 +339,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_with_recovery_and_noncedata() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -357,7 +357,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn bad_recovery() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -423,7 +423,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[cfg(bench)]
|
||||
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
|
||||
#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std".
|
||||
mod benches {
|
||||
use test::{black_box, Bencher};
|
||||
|
||||
|
|
48
src/key.rs
48
src/key.rs
|
@ -44,7 +44,7 @@ use crate::{
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, SecretKey};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -182,7 +182,7 @@ impl SecretKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
|
||||
/// # #[cfg(all(feature = "std", feature = "rand"))] {
|
||||
/// use secp256k1::{rand, SecretKey};
|
||||
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
|
||||
/// # }
|
||||
|
@ -235,7 +235,7 @@ impl SecretKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, SecretKey, Keypair};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -409,7 +409,7 @@ impl PublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -467,7 +467,7 @@ impl PublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, PublicKey, Keypair};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -600,7 +600,7 @@ impl PublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -626,7 +626,7 @@ impl PublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, PublicKey};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -760,7 +760,7 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Keypair, Secp256k1};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -857,7 +857,7 @@ impl Keypair {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, SecretKey, Keypair};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -904,7 +904,7 @@ impl Keypair {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{Secp256k1, Keypair, Scalar};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -957,7 +957,7 @@ impl Keypair {
|
|||
|
||||
/// Constructs an schnorr signature for `msg` using the global [`SECP256K1`] context.
|
||||
#[inline]
|
||||
#[cfg(all(feature = "global-context", feature = "rand-std"))]
|
||||
#[cfg(all(feature = "global-context", feature = "rand", feature = "std"))]
|
||||
pub fn sign_schnorr(&self, msg: &[u8]) -> schnorr::Signature {
|
||||
SECP256K1.sign_schnorr(msg, self)
|
||||
}
|
||||
|
@ -1078,7 +1078,7 @@ impl CPtr for Keypair {
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{rand, Secp256k1, Keypair, XOnlyPublicKey};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -1210,7 +1210,7 @@ impl XOnlyPublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{Secp256k1, Keypair, Scalar, XOnlyPublicKey};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -1270,7 +1270,7 @@ impl XOnlyPublicKey {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # #[cfg(all(feature = "rand", feature = "std"))] {
|
||||
/// use secp256k1::{Secp256k1, Keypair, Scalar};
|
||||
///
|
||||
/// let secp = Secp256k1::new();
|
||||
|
@ -1576,7 +1576,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn keypair_slice_round_trip() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -1856,7 +1856,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn tweak_add_arbitrary_data() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -1875,7 +1875,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn tweak_add_zero() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -1890,7 +1890,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn tweak_mul_arbitrary_data() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -1909,7 +1909,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn tweak_mul_zero() {
|
||||
let s = Secp256k1::new();
|
||||
let (sk, _) = s.generate_keypair(&mut rand::thread_rng());
|
||||
|
@ -1919,7 +1919,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_negation() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -1941,7 +1941,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn pubkey_hash() {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::collections::HashSet;
|
||||
|
@ -2024,7 +2024,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn create_pubkey_combine() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -2134,7 +2134,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_tweak_add_then_tweak_add_check() {
|
||||
let s = Secp256k1::new();
|
||||
|
||||
|
@ -2393,7 +2393,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_keypair_from_str() {
|
||||
let ctx = crate::Secp256k1::new();
|
||||
let keypair = Keypair::new(&ctx, &mut rand::thread_rng());
|
||||
|
|
29
src/lib.rs
29
src/lib.rs
|
@ -7,7 +7,7 @@
|
|||
//!
|
||||
//! To minimize dependencies, some functions are feature-gated. To generate
|
||||
//! random keys or to re-randomize a context object, compile with the
|
||||
//! `rand-std` feature. If you are willing to use the `rand-std` feature, we
|
||||
//! `rand` and `std` features. If you are willing to use these features, we
|
||||
//! have enabled an additional defense-in-depth sidechannel protection for
|
||||
//! our context objects, which re-blinds certain operations on secret key
|
||||
//! data. To de/serialize objects with serde, compile with "serde".
|
||||
|
@ -28,7 +28,7 @@
|
|||
//! trigger any assertion failures in the upstream library.
|
||||
//!
|
||||
//! ```rust
|
||||
//! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] {
|
||||
//! # #[cfg(all(feature = "rand", feature = "hashes", feature = "std"))] {
|
||||
//! use secp256k1::rand::rngs::OsRng;
|
||||
//! use secp256k1::{Secp256k1, Message};
|
||||
//! use secp256k1::hashes::{sha256, Hash};
|
||||
|
@ -46,7 +46,7 @@
|
|||
//! If the "global-context" feature is enabled you have access to an alternate API.
|
||||
//!
|
||||
//! ```rust
|
||||
//! # #[cfg(all(feature = "global-context", feature = "hashes-std", feature = "rand-std"))] {
|
||||
//! # #[cfg(all(feature = "global-context", feature = "hashes", feature = "rand", feature = "std"))] {
|
||||
//! use secp256k1::{generate_keypair, Message};
|
||||
//! use secp256k1::hashes::{sha256, Hash};
|
||||
//!
|
||||
|
@ -59,7 +59,7 @@
|
|||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `hashes-std`
|
||||
//! The above code requires `rust-secp256k1` to be compiled with the `rand`, `hashes`, and `std`
|
||||
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
|
||||
//! Alternately, keys and messages can be parsed from slices, like
|
||||
//!
|
||||
|
@ -71,7 +71,6 @@
|
|||
//! let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
|
||||
//! let public_key = PublicKey::from_secret_key(&secp, &secret_key);
|
||||
//! // This is unsafe unless the supplied byte slice is the output of a cryptographic hash function.
|
||||
//! // See the above example for how to use this library together with `hashes-std`.
|
||||
//! let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
|
||||
//!
|
||||
//! let sig = secp.sign_ecdsa(&message, &secret_key);
|
||||
|
@ -128,9 +127,7 @@
|
|||
//! * `std` - use standard Rust library, enabled by default.
|
||||
//! * `alloc` - use the `alloc` standard Rust library to provide heap allocations.
|
||||
//! * `rand` - use `rand` library to provide random generator (e.g. to generate keys).
|
||||
//! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.)
|
||||
//! * `hashes` - use the `hashes` library.
|
||||
//! * `hashes-std` - use the `hashes` library with its `std` feature enabled (implies `hashes`).
|
||||
//! * `recovery` - enable functions that can compute the public key from signature.
|
||||
//! * `lowmemory` - optimize the library for low-memory environments.
|
||||
//! * `global-context` - enable use of global secp256k1 context (implies `std`).
|
||||
|
@ -525,7 +522,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
// In rustc 1.72 this Clippy lint was pulled out of clippy and into rustc, and
|
||||
// was made deny-by-default, breaking compilation of this test. Aside from this
|
||||
// breaking change, which there is no point in bugging, the rename was done so
|
||||
|
@ -597,7 +594,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_preallocation() {
|
||||
use crate::ffi::types::AlignedType;
|
||||
|
||||
|
@ -624,7 +621,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn capabilities() {
|
||||
let sign = Secp256k1::signing_only();
|
||||
let vrfy = Secp256k1::verification_only();
|
||||
|
@ -653,7 +650,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn signature_serialize_roundtrip() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -743,7 +740,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_and_verify_ecdsa() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -777,7 +774,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_and_verify_extreme() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -811,7 +808,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_and_verify_fail() {
|
||||
let mut s = Secp256k1::new();
|
||||
s.randomize(&mut rand::thread_rng());
|
||||
|
@ -852,7 +849,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_hex() {
|
||||
use rand::RngCore;
|
||||
|
||||
|
@ -1009,7 +1006,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[cfg(bench)]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
mod benches {
|
||||
use rand::rngs::mock::StepRng;
|
||||
use test::{black_box, Bencher};
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Scalar {
|
|||
pub const MAX: Scalar = Scalar(MAX_RAW);
|
||||
|
||||
/// Generates a random scalar
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
pub fn random() -> Self { Self::random_custom(rand::thread_rng()) }
|
||||
|
||||
/// Generates a random scalar using supplied RNG
|
||||
|
|
|
@ -127,7 +127,7 @@ impl<C: Signing> Secp256k1<C> {
|
|||
|
||||
/// Creates a schnorr signature internally using the [`rand::rngs::ThreadRng`] random number
|
||||
/// generator to generate the auxiliary random data.
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
pub fn sign_schnorr(&self, msg: &[u8], keypair: &Keypair) -> Signature {
|
||||
self.sign_schnorr_with_rng(msg, keypair, &mut rand::thread_rng())
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ impl<C: Verification> Secp256k1<C> {
|
|||
mod tests {
|
||||
use core::str::FromStr;
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
use rand::rngs::ThreadRng;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
@ -213,7 +213,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn schnorr_sign_with_aux_rand_verify() {
|
||||
sign_helper(|secp, msg, seckey, rng| {
|
||||
let aux_rand = crate::random_32_bytes(rng);
|
||||
|
@ -222,22 +222,22 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn schnor_sign_with_rng_verify() {
|
||||
sign_helper(|secp, msg, seckey, rng| secp.sign_schnorr_with_rng(msg, seckey, rng))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn schnorr_sign_verify() { sign_helper(|secp, msg, seckey, _| secp.sign_schnorr(msg, seckey)) }
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn schnorr_sign_no_aux_rand_verify() {
|
||||
sign_helper(|secp, msg, seckey, _| secp.sign_schnorr_no_aux_rand(msg, seckey))
|
||||
}
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn sign_helper(sign: fn(&Secp256k1<crate::All>, &[u8], &Keypair, &mut ThreadRng) -> Signature) {
|
||||
let secp = Secp256k1::new();
|
||||
|
||||
|
@ -317,7 +317,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
#[cfg(all(feature = "rand", feature = "std"))]
|
||||
fn test_pubkey_serialize_roundtrip() {
|
||||
let secp = Secp256k1::new();
|
||||
let kp = Keypair::new(&secp, &mut rand::thread_rng());
|
||||
|
|
Loading…
Reference in New Issue