Skip to content

Commit b22b9e5

Browse files
committed
Merge remote-tracking branch 'rust-bitcoin/master'
* rust-bitcoin/master: Fix no-std raw test, after removal of lang items Fix broken benchmarks Disable emscripten tests until they work again rust-lang/rust#66916 rustwasm/team#291 Add constant of the prime of the curve field. Simplify callback logic to returning raw coordinates Removed no longer used dont_replace_c_symbols feature Fix wrong feature name external-symbols Fix missing return c_int in NonceFn
2 parents ba01394 + 9aa768d commit b22b9e5

File tree

9 files changed

+85
-162
lines changed

9 files changed

+85
-162
lines changed

.travis.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: rust
2-
cache:
3-
directories:
4-
- cargo_web
2+
# cache:
3+
# directories:
4+
# - cargo_web
55

66
rust:
77
- stable
@@ -45,12 +45,12 @@ script:
4545
- cargo run --example generate_keys --features=rand
4646
- if [ ${TRAVIS_RUST_VERSION} == "stable" ]; then cargo doc --verbose --features="rand,serde,recovery,endomorphism"; fi
4747
- if [ ${TRAVIS_RUST_VERSION} == "nightly" ]; then cargo test --verbose --benches --features=unstable; fi
48-
- if [ ${TRAVIS_RUST_VERSION} == "nightly" -a "$TRAVIS_OS_NAME" = "linux" ]; then
48+
- if [ ${TRAVIS_RUST_VERSION} == "nightly" -a "$TRAVIS_OS_NAME" = "linux" ]; then
4949
cd no_std_test &&
5050
cargo run --release | grep -q "Verified Successfully";
5151
fi
52-
- if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
53-
CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web &&
54-
cargo web build --verbose --target=asmjs-unknown-emscripten &&
55-
cargo web test --verbose --target=asmjs-unknown-emscripten;
56-
fi
52+
- #if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
53+
#CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web &&
54+
#cargo web build --verbose --target=asmjs-unknown-emscripten &&
55+
#cargo web test --verbose --target=asmjs-unknown-emscripten;
56+
#fi

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ name = "secp256k1"
2222
path = "src/lib.rs"
2323

2424
[features]
25-
unstable = []
25+
unstable = ["recovery", "rand-std"]
2626
default = ["std"]
2727
std = ["secp256k1-sys/std"]
2828
rand-std = ["rand/std"]

no_std_test/src/main.rs

+9-22
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
//! # secp256k1 no-std test.
1616
//! This binary is a short smallest rust code to produce a working binary *without libstd*.
17-
//! This gives us 2 things:
17+
//! This gives us 2 things:
1818
//! 1. Test that the parts of the code that should work in a no-std enviroment actually work.
1919
//! 2. Test that we don't accidentally import libstd into `secp256k1`.
20-
//!
20+
//!
2121
//! The first is tested using the following command `cargo run --release | grep -q "Verified Successfully"`.
2222
//! (Making sure that it successfully printed that. i.e. it didn't abort before that).
23-
//!
23+
//!
2424
//! The second is tested by the fact that it compiles. if we accidentally link against libstd we should see the following error:
2525
//! `error[E0152]: duplicate lang item found`.
2626
//! Example:
@@ -33,11 +33,11 @@
3333
//! |
3434
//! = note: first defined in crate `panic_unwind` (which `std` depends on).
3535
//! ```
36-
//!
37-
//! Notes:
36+
//!
37+
//! Notes:
3838
//! * Requires `panic=abort` and `--release` to not depend on libunwind(which is provided usually by libstd) https://github.com/rust-lang/rust/issues/47493
3939
//! * Requires linking with `libc` for calling `printf`.
40-
//!
40+
//!
4141
4242
#![feature(lang_items)]
4343
#![feature(start)]
@@ -52,10 +52,10 @@ use core::fmt::{self, write, Write};
5252
use core::intrinsics;
5353
use core::panic::PanicInfo;
5454

55+
use secp256k1::ecdh::SharedSecret;
5556
use secp256k1::rand::{self, RngCore};
5657
use secp256k1::serde::Serialize;
5758
use secp256k1::*;
58-
use secp256k1::ecdh::SharedSecret;
5959

6060
use serde_cbor::de;
6161
use serde_cbor::ser::SliceWrite;
@@ -105,30 +105,17 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
105105

106106
let _ = SharedSecret::new(&public_key, &secret_key);
107107
let mut x_arr = [0u8; 32];
108-
let y_arr = unsafe { SharedSecret::new_with_hash_no_panic(&public_key, &secret_key, |x,y| {
108+
let y_arr = SharedSecret::new_with_hash(&public_key, &secret_key, |x,y| {
109109
x_arr = x;
110110
y.into()
111-
})}.unwrap();
111+
});
112112
assert_ne!(x_arr, [0u8; 32]);
113113
assert_ne!(&y_arr[..], &[0u8; 32][..]);
114-
115114

116115
unsafe { libc::printf("Verified Successfully!\n\0".as_ptr() as _) };
117116
0
118117
}
119118

120-
// These functions are used by the compiler, but not
121-
// for a bare-bones hello world. These are normally
122-
// provided by libstd.
123-
#[lang = "eh_personality"]
124-
#[no_mangle]
125-
pub extern "C" fn rust_eh_personality() {}
126-
127-
// This function may be needed based on the compilation target.
128-
#[lang = "eh_unwind_resume"]
129-
#[no_mangle]
130-
pub extern "C" fn rust_eh_unwind_resume() {}
131-
132119
const MAX_PRINT: usize = 511;
133120
struct Print {
134121
loc: usize,

secp256k1-sys/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ fn main() {
6363
} else {
6464
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
6565
}
66-
#[cfg(not(feature = "dont_replace_c_symbols"))]
6766
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
6867
#[cfg(feature = "endomorphism")]
6968
base_config.define("USE_ENDOMORPHISM", Some("1"));

secp256k1-sys/src/lib.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub type NonceFn = unsafe extern "C" fn(nonce32: *mut c_uchar,
6363
algo16: *const c_uchar,
6464
data: *mut c_void,
6565
attempt: c_uint,
66-
);
66+
) -> c_int;
6767

6868
/// Hash function to use to post-process an ECDH point to get
6969
/// a shared secret.
@@ -295,7 +295,7 @@ extern "C" {
295295
// Returns: a newly created context object.
296296
// In: flags: which parts of the context to initialize.
297297
#[no_mangle]
298-
#[cfg(all(feature = "std", not(feature = "external_symbols")))]
298+
#[cfg(all(feature = "std", not(feature = "external-symbols")))]
299299
pub unsafe extern "C" fn rustsecp256k1_v0_1_1_context_create(flags: c_uint) -> *mut Context {
300300
use std::mem;
301301
assert!(mem::align_of::<usize>() >= mem::align_of::<u8>());
@@ -312,7 +312,7 @@ pub unsafe extern "C" fn rustsecp256k1_v0_1_1_context_create(flags: c_uint) -> *
312312
secp256k1_context_preallocated_create(ptr as *mut c_void, flags)
313313
}
314314

315-
#[cfg(all(feature = "std", not(feature = "external_symbols")))]
315+
#[cfg(all(feature = "std", not(feature = "external-symbols")))]
316316
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
317317
rustsecp256k1_v0_1_1_context_create(flags)
318318
}
@@ -324,7 +324,7 @@ pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
324324
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
325325
///
326326
#[no_mangle]
327-
#[cfg(all(feature = "std", not(feature = "external_symbols")))]
327+
#[cfg(all(feature = "std", not(feature = "external-symbols")))]
328328
pub unsafe extern "C" fn rustsecp256k1_v0_1_1_context_destroy(ctx: *mut Context) {
329329
secp256k1_context_preallocated_destroy(ctx);
330330
let ctx: *mut usize = ctx as *mut usize;
@@ -335,7 +335,7 @@ pub unsafe extern "C" fn rustsecp256k1_v0_1_1_context_destroy(ctx: *mut Context)
335335
let _ = Box::from_raw(slice as *mut [usize]);
336336
}
337337

338-
#[cfg(all(feature = "std", not(feature = "external_symbols")))]
338+
#[cfg(all(feature = "std", not(feature = "external-symbols")))]
339339
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
340340
rustsecp256k1_v0_1_1_context_destroy(ctx)
341341
}
@@ -360,7 +360,7 @@ pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
360360
/// See also secp256k1_default_error_callback_fn.
361361
///
362362
#[no_mangle]
363-
#[cfg(not(feature = "external_symbols"))]
363+
#[cfg(not(feature = "external-symbols"))]
364364
pub unsafe extern "C" fn rustsecp256k1_v0_1_1_default_illegal_callback_fn(message: *const c_char, _data: *mut c_void) {
365365
use core::str;
366366
let msg_slice = slice::from_raw_parts(message as *const u8, strlen(message));
@@ -383,7 +383,7 @@ pub unsafe extern "C" fn rustsecp256k1_v0_1_1_default_illegal_callback_fn(messag
383383
/// See also secp256k1_default_illegal_callback_fn.
384384
///
385385
#[no_mangle]
386-
#[cfg(not(feature = "external_symbols"))]
386+
#[cfg(not(feature = "external-symbols"))]
387387
pub unsafe extern "C" fn rustsecp256k1_v0_1_1_default_error_callback_fn(message: *const c_char, _data: *mut c_void) {
388388
use core::str;
389389
let msg_slice = slice::from_raw_parts(message as *const u8, strlen(message));
@@ -491,13 +491,6 @@ mod fuzz_dummy {
491491
1
492492
}
493493

494-
// TODO secp256k1_context_set_illegal_callback
495-
// TODO secp256k1_context_set_error_callback
496-
// (Actually, I don't really want these exposed; if either of these
497-
// are ever triggered it indicates a bug in rust-secp256k1, since
498-
// one goal is to use Rust's type system to eliminate all possible
499-
// bad inputs.)
500-
501494
// Pubkeys
502495
/// Parse 33/65 byte pubkey into PublicKey, losing compressed information
503496
pub unsafe fn secp256k1_ec_pubkey_parse(cx: *const Context, pk: *mut PublicKey,

src/constants.rs

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ pub const MAX_SIGNATURE_SIZE: usize = 72;
3434
/// The maximum size of a compact signature
3535
pub const COMPACT_SIGNATURE_SIZE: usize = 64;
3636

37+
/// The Prime for the secp256k1 field element.
38+
pub const FIELD_SIZE: [u8; 32] = [
39+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
42+
0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f
43+
];
44+
3745
/// The order of the secp256k1 curve
3846
pub const CURVE_ORDER: [u8; 32] = [
3947
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

0 commit comments

Comments
 (0)