-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split crate into core and main, and use build script for const/const_…
…gen generation (#40) * Rename the library exposed name to just libsecp256k1 This reduces confusion and avoids conflicts in the case when both `secp256k1` and `libsecp256k1` needs to be used. * Move all const context related code to a separate module * Split create into core and main * Fix all tests * Use build script to generate const.rs file * Use build script to generate const_gen.rs file * Change back CI to test --all * Set all sub-crates' version to 0.1.0 before 0.4.0 is released * Fix version pins * Add missing descriptions for crate * typo: keyword style fix * Update core/src/lib.rs Co-Authored-By: Marcio Diaz <[email protected]> Co-authored-by: Marcio Diaz <[email protected]>
- Loading branch information
Showing
22 changed files
with
209 additions
and
17,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,19 @@ license = "Apache-2.0" | |
version = "0.4.0" | ||
authors = ["Wei Tang <[email protected]>"] | ||
repository = "https://github.com/paritytech/libsecp256k1" | ||
keywords = [ "crypto", "ECDSA", "secp256k1", "bitcoin", "no_std" ] | ||
keywords = ["crypto", "ECDSA", "secp256k1", "bitcoin", "no_std"] | ||
edition = "2018" | ||
|
||
[lib] | ||
name = "secp256k1" | ||
|
||
[dependencies] | ||
libsecp256k1-core = { version = "0.1.0", path = "core", default-features = false } | ||
arrayref = "0.3" | ||
rand = { version = "0.7", default-features = false } | ||
digest = "0.8" | ||
base64 = { version = "0.11.0", default-features = false } | ||
hmac-drbg = { version = "0.2", optional = true } | ||
sha2 = { version = "0.8", optional = true, default-features = false } | ||
digest = "0.8" | ||
typenum = { version = "1.11", optional = true } | ||
arrayref = "0.3" | ||
subtle = { version = "2.2", default-features = false } | ||
serde = { version = "1.0.104", features = ["derive"], default-features = false } | ||
base64 = { version = "0.11.0", default-features = false } | ||
crunchy = "0.2" | ||
serde = { version = "1.0.104", features = ["derive"], default-features = false } | ||
|
||
[dev-dependencies] | ||
secp256k1-test = "0.7" | ||
|
@@ -30,11 +26,14 @@ rand-test = { package = "rand", version = "0.4" } | |
serde_json = "1.0" | ||
hex-literal = "0.2.1" | ||
|
||
[build-dependencies] | ||
libsecp256k1-gen-ecmult = { version = "0.1.0", path = "gen/ecmult" } | ||
libsecp256k1-gen-genmult = { version = "0.1.0", path = "gen/genmult" } | ||
|
||
[features] | ||
default = ["std", "hmac"] | ||
std = ["subtle/std", "rand/std", "sha2/std", "serde/std", "base64/std"] | ||
std = ["libsecp256k1-core/std", "sha2/std", "rand/std", "serde/std", "base64/std"] | ||
hmac = ["hmac-drbg", "sha2", "typenum"] | ||
noconst = [] | ||
|
||
[workspace] | ||
members = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::{env, io::Write, fs::File, path::Path}; | ||
|
||
fn main() { | ||
let out_dir = env::var_os("OUT_DIR").unwrap(); | ||
|
||
let const_path = Path::new(&out_dir).join("const.rs"); | ||
let mut const_file = File::create(&const_path).expect("Create const.rs file failed"); | ||
libsecp256k1_gen_ecmult::generate_to(&mut const_file).expect("Write const.rs file failed"); | ||
const_file.flush().expect("Flush const.rs file failed"); | ||
|
||
let gen_path = Path::new(&out_dir).join("const_gen.rs"); | ||
let mut gen_file = File::create(&gen_path).expect("Create const_gen.rs file failed"); | ||
libsecp256k1_gen_genmult::generate_to(&mut gen_file).expect("Write const_gen.rs file failed"); | ||
gen_file.flush().expect("Flush const_gen.rs file failed"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "libsecp256k1-core" | ||
description = "Core functions for pure Rust secp256k1 implementation." | ||
license = "Apache-2.0" | ||
version = "0.1.0" | ||
authors = ["Wei Tang <[email protected]>"] | ||
repository = "https://github.com/paritytech/libsecp256k1" | ||
keywords = ["crypto", "ECDSA", "secp256k1", "bitcoin", "no_std"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
subtle = { version = "2.2", default-features = false } | ||
crunchy = "0.2" | ||
digest = "0.8" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["subtle/std"] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Pure Rust implementation of the secp256k1 curve and fast ECDSA | ||
//! signatures. The secp256k1 curve is used exclusively in Bitcoin and | ||
//! Ethereum alike cryptocurrencies. | ||
#![deny(unused_import_braces, unused_imports, | ||
unused_comparisons, unused_must_use, | ||
unused_variables, non_shorthand_field_patterns, | ||
unreachable_code, unused_parens)] | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[macro_use] | ||
mod field; | ||
#[macro_use] | ||
mod group; | ||
mod scalar; | ||
mod error; | ||
mod der; | ||
mod ecmult; | ||
mod ecdsa; | ||
mod ecdh; | ||
|
||
extern crate alloc; | ||
|
||
pub use crate::error::Error; | ||
|
||
/// Curve related structs. | ||
pub mod curve { | ||
pub use crate::field::{Field, FieldStorage}; | ||
pub use crate::group::{Affine, Jacobian, AffineStorage, AFFINE_G, CURVE_B}; | ||
pub use crate::scalar::Scalar; | ||
|
||
pub use crate::ecmult::{ECMultContext, ECMultGenContext}; | ||
} | ||
|
||
/// Utilities to manipulate the secp256k1 curve parameters. | ||
pub mod util { | ||
pub const TAG_PUBKEY_EVEN: u8 = 0x02; | ||
pub const TAG_PUBKEY_ODD: u8 = 0x03; | ||
pub const TAG_PUBKEY_FULL: u8 = 0x04; | ||
pub const TAG_PUBKEY_HYBRID_EVEN: u8 = 0x06; | ||
pub const TAG_PUBKEY_HYBRID_ODD: u8 = 0x07; | ||
|
||
pub const MESSAGE_SIZE: usize = 32; | ||
pub const SECRET_KEY_SIZE: usize = 32; | ||
pub const RAW_PUBLIC_KEY_SIZE: usize = 64; | ||
pub const FULL_PUBLIC_KEY_SIZE: usize = 65; | ||
pub const COMPRESSED_PUBLIC_KEY_SIZE: usize = 33; | ||
pub const SIGNATURE_SIZE: usize = 64; | ||
pub const DER_MAX_SIGNATURE_SIZE: usize = 72; | ||
|
||
pub use crate::group::{AFFINE_INFINITY, JACOBIAN_INFINITY, | ||
set_table_gej_var, globalz_set_table_gej}; | ||
pub use crate::ecmult::{WINDOW_A, WINDOW_G, ECMULT_TABLE_SIZE_A, ECMULT_TABLE_SIZE_G, | ||
odd_multiples_table}; | ||
|
||
pub use crate::der::{Decoder, SignatureArray}; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
[package] | ||
name = "libsecp256k1-gen-ecmult" | ||
version = "0.0.0" | ||
description = "Generator function of const_gen for libsecp256k1." | ||
license = "Apache-2.0" | ||
version = "0.1.0" | ||
authors = ["Wei Tang <[email protected]>"] | ||
edition = "2018" | ||
repository = "https://github.com/paritytech/libsecp256k1" | ||
keywords = ["crypto", "ECDSA", "secp256k1", "bitcoin", "no_std"] | ||
|
||
[dependencies] | ||
libsecp256k1 = { path = "../..", features = ["noconst"] } | ||
libsecp256k1-core = { version = "0.1.0", path = "../../core" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
[package] | ||
name = "libsecp256k1-gen-genmult" | ||
version = "0.0.0" | ||
description = "Generator function of const for libsecp256k1." | ||
license = "Apache-2.0" | ||
version = "0.1.0" | ||
authors = ["Wei Tang <[email protected]>"] | ||
edition = "2018" | ||
repository = "https://github.com/paritytech/libsecp256k1" | ||
keywords = ["crypto", "ECDSA", "secp256k1", "bitcoin", "no_std"] | ||
|
||
[dependencies] | ||
libsecp256k1 = { path = "../..", features = ["noconst"] } | ||
libsecp256k1-core = { version = "0.1.0", path = "../../core" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.