Commit Graph

310 Commits

Author SHA1 Message Date
Elichai Turkel ea4eae8a20
Merge pull request #315 from LNP-BP/fix/feat-warning
Fixing warning in context mod under feature-specific compilation
2021-06-30 15:32:35 +03:00
sanket1729 5bac4e4bac Change error enum for KeyPair::from_seckey_slice
Also does another nit in the file which removes a trailing whitespace
2021-06-27 17:20:23 -07:00
Dr Maxim Orlovsky 593a550e3f
Fixing warning in context mod under feature-specific compilation 2021-06-27 20:09:41 +02:00
Dr Maxim Orlovsky aa6bdaff3c
Creating SecretKey and PublicKey from BIP-340 KeyPair 2021-06-16 10:56:59 +02:00
Andrew Poelstra bb25ed4715
Merge pull request #282 from TheBlueMatt/2021-02-redo-fuzz
Reduce cryptography usage in --cfg=fuzzing
2021-06-09 15:01:52 +00:00
Matt Corallo 940a51c2c6 Reduce cryptography usage in --cfg=fuzzing
This reduces the usage of real cryptography in --cfg=fuzzing,
specifically replacing the secret->public key derivation with a
simple copy and ECDH with XOR of the public and private parts
(plus a stream of 1s to make a test pass that expected non-0
output).

It leaves secret tweak addition/multiplication as-is.

It also changes the context creation to over-allocate and store
the context flags at the end of the context buffer, allowing us
to easily test context flags in each function.

While it would be nice to have something fancier (eg XOR-based),
its not immediately obvious how to accomplish this, and better to
fix the issues I have than spend too much time on it.

Fixes #271.

This partially reverts b811ec133a
2021-06-08 19:17:08 +00:00
Matt Corallo f2e4b297e1 Do not test secret->public derivation or pk validity in fuzzing cfg
In the next commit the secret->public key derivation in fuzzing cfg
is changed to be simpler, as well as the validity rules of public
keys relaxed.

This adds a new test to ensure random keys can be added, not just
the hard-coded keys test that exists today.
2021-06-08 19:17:07 +00:00
Devrandom b5ff47a1a8 New alloc feature
Allows use of `Secp256k1::new` and related API if an allocator is available
2021-06-08 20:41:49 +02:00
Andrew Poelstra e89fd5d269
Merge pull request #291 from p2pderivatives/add-combine-keys
Add combine_keys function to PublicKey
2021-06-08 18:09:35 +00:00
Andrew Poelstra a5dfd09e94
Merge pull request #294 from LNP-BP/feat/from_secret_key
Adding schnorrsig::KeyPair::from_secret_key convenience function
2021-06-08 18:05:20 +00:00
Matt Corallo ce930ab6b7 Add a global-context-less-secure feature which skips randomization
This is useful for us downstream as we wish to target WASM with a
global context, and using rand in such a build doesn't seem like a
safe idea.
2021-06-08 01:48:50 +00:00
sanket1729 6265b2558a Fix SecretKey FromStr bug
Secret::from_str did not check if the secret key
was a valid one or not.
2021-04-26 14:17:39 -07:00
Elichai Turkel 3c2bee31f2
Merge pull request #270 from thomaseizinger/serde-owned-types
Rebased version of `[Alternative] Allow deserializing from owned types` + support for new schnorr module
2021-04-21 19:06:29 +03:00
Dr Maxim Orlovsky bf9a276342
Adding schnorrsig::KeyPair::from_secret_key convenience function 2021-04-12 15:25:50 +02:00
Tibo-lg 7d32182537 Add combine_keys function to PublicKey 2021-04-08 06:28:03 +09:00
Tim Ruffing 1eb2c32df7 Manually test that panicking from C will abort the process
Panicking from C is not UB in newer rust versions and will reliably
trigger an abort (without unwinding). In older rust versions, it is
technically UB but empirically it seems to "just work" (and what should
it realistically do except crashing, which is what we intent).

Since there's potentially no unwinding, we can't test this behavior
using [should_panic]. This PR will instead check the libtest output
explicitly in our CI tests.

Fixes #228.
2021-03-24 21:54:02 +01:00
Dr Maxim Orlovsky 519857cd83
More standard derives for Error 2021-01-30 12:35:41 +01:00
Thomas Eizinger c2fd5cefa4
Remove `visit_bytes` implementation from `FromStrVisitor`
This visitor is meant to deserialize strings using `FromStr` not
bytes.
2021-01-13 09:57:09 +11:00
Thomas Eizinger e6e23e9dd6
Rename `HexVisitor` to `FromStrVisitor`
The visitor works with all types that implement `FromStr`. Whether or
not that ends up being hex encoding depends on the implementation
of `FromStr`.
2021-01-13 09:54:33 +11:00
Thomas Eizinger 18890d3b86
Extend schnorr-sig serde test suite with owned and slice variants 2021-01-12 11:52:24 +11:00
Thomas Eizinger b4040f0a82
Update test names to reflect what they are doing
These tests are testing more than just the signature serialization.
2021-01-12 11:52:06 +11:00
Elichai Turkel 1f08a313e5
Replace serde macros with generic visitor module
Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
Co-authored-by: Sebastian Geisler <sebastian@blockstream.io>
2021-01-12 11:51:29 +11:00
Andrew Poelstra 65ff814a39 rename `rust_secp_fuzz` to `fuzzing` 2021-01-11 19:14:42 +00:00
Matt Corallo 1f043216a0 Add ability to randomize context without the `rand` feature.
There is little reason to pull in the `rand` dep just for the `Rng`
trait for users who want to randomize contexts. We should expose a
randomize function that just takes 32 bytes.
2020-12-29 16:45:07 -05:00
Andrew Poelstra d1714ce0ac fuzz: disable sig-grinding tests, prevent spin-looping 2020-12-28 18:55:33 +00:00
Andrew Poelstra 96862b6a74 fuzz: implement recoverable signatures, get all tests passing, run them in CI 2020-12-28 18:42:46 +00:00
Andrew Poelstra b811ec133a fuzz: only replace signing and verification, leave everything else alone
We can now run unit tests with the fuzz feature on, and they'll pass,
which is some assurance that fuzzing with the feature on won't lead to
spurious failures due to the fuzz harness inadequately simulating message
signing.
2020-12-23 17:59:52 +00:00
Andrew Poelstra 40c31342f2 ffi: make function types nullable 2020-12-23 17:59:52 +00:00
Andrew Poelstra a2c25f2e83
Merge pull request #259 from p2pderivatives/implement-low-r-signing
Implement low r signing
2020-12-22 23:28:34 +00:00
Andrew Poelstra b31bf2f611
Merge pull request #258 from thomaseizinger/better-wasm-tests
Run more tests in wasm
2020-12-22 06:12:01 +00:00
Tibo-lg 1d166d061b Implement low r signing 2020-12-22 14:50:37 +09:00
Tobin Harding a584643486 Use ManuallyDrop
Suggested by clippy, we need to use ManuallyDrop for these types in
order to correctly free up the memory.
2020-12-22 14:56:17 +11:00
Tobin Harding c38136b6bc Use for loop instead of map
Currently we are misusing `map` on an iterator to loop `n` times,
additionally the assertion is pointless. Use a for loop and assert
against the length of the set.
2020-12-22 14:56:17 +11:00
Tobin Harding c92b946493 Remove unnecessary clone
Type is `Copy`, no need for clone.
2020-12-22 14:56:17 +11:00
Tobin Harding ef23cb8167 Return Ok directly
Clippy emits warning:

	warning: passing a unit value to a function

Just return `Ok(())` after calling `fill_bytes`.
2020-12-22 14:56:17 +11:00
Tobin Harding 34ad4110f1 Remove unused error return value
This helper never returns an error, remove the `Result` return type.
Found by clippy.
2020-12-22 14:56:17 +11:00
Tobin Harding ed29f12216
Remove unnecessary return statements
Found by clippy. We don't need a `return` for the final statement.
2020-12-22 13:38:02 +11:00
Tobin Harding 4e87e6fe94
Implement is_empty method
Clippy warns of missing `is_empty`, trivially implement it by calling
through to `self.data.is_empty()`.
2020-12-22 13:37:25 +11:00
Thomas Eizinger 8b8e482f79
Run more tests in wasm
Instead of repeating ourselves in defining one big test for the wasm
target, we can override the `test` attribute with the `wasm-bindgen-test`
one and therefore automatically run all (supported) tests in wasm.

Unfortunately, wasm doesn't support catching panics yet which means we
have to disable the `test_panic_raw_ctx` test.
2020-12-22 10:30:56 +11:00
Elichai Turkel 767246a282
Make preallocated use AlignedType 2020-12-18 12:48:19 +02:00
Elichai Turkel fd206ab57c
Replace use of boxes with global allocator 2020-12-18 12:48:19 +02:00
Andrew Poelstra ea027ce258 schnorrsig: change tweak_add_check to return a bool, take a fixed-length array 2020-12-09 16:49:48 +00:00
Andrew Poelstra 0ec8fab82c stop explicitly casting references to rawptrs 2020-11-30 02:47:34 +00:00
Andrew Poelstra 37049d743e schnorrsig: expose tweak_check_add API 2020-11-27 18:42:14 +00:00
Andrew Poelstra 12b0abbcf8 make `ffi::Type::new` functions all unsafe, expand documentation 2020-11-27 18:42:12 +00:00
Andrew Poelstra be9a78f39e
Merge pull request #237 from p2pderivatives/add-bip340-schnorr
Add bip340 schnorr
2020-11-27 18:04:44 +00:00
Andrew Poelstra 9083babbe2
Merge pull request #248 from justinmoon/pubkey-ordering
Implement lexigraphic ordering for PubKey
2020-11-26 03:03:17 +00:00
Justin Moon 6f8a480974 Implement lexigraphic ordering for PubKey 2020-11-25 19:27:31 -06:00
Andrew Poelstra 1859ddc28a switch from travis to github workflows 2020-11-10 23:58:03 +00:00
Tibo-lg 0c937d04f5 Add key::PublicKey to schnorrsig::PublicKey conversion 2020-11-10 14:15:34 +09:00