Commit Graph

974 Commits

Author SHA1 Message Date
sanket1729 837be22e09 Basic derives for Parity 2022-01-06 23:57:26 +05:30
sanket1729 7059192de9 Wildcard export from key module 2022-01-06 23:08:01 +05:30
Andrew Poelstra 74e8fc7699
Merge rust-bitcoin/rust-secp256k1#360: Re-export Parity struct
e595b39510 Re-export Parity struct (sanket1729)

Pull request description:

  pub struct Parity is under a private module key and not re-exported in lib.rs . It is therefore not
  possible to use it downstream.

ACKs for top commit:
  elichai:
    ACK e595b39510
  apoelstra:
    ACK e595b39510

Tree-SHA512: 2573689f9a08505c8dfe8f79cd921d5a2742a2a2f4f92cf4066fe6557c765c756531d13560fa4fe6461f094b0c11a52aca30b44542eb77eda7dd1ebd24d3b155
2022-01-06 15:46:18 +00:00
Andrew Poelstra 88f6baee73
Merge rust-bitcoin/rust-secp256k1#353: Documented features
18f74d5242 Clarify what does "less security" mean (Martin Habovstiak)
94c55b4d09 Fixed typos/grammar mistakes (Martin Habovštiak)
1bf05523f0 Documented features (Martin Habovstiak)

Pull request description:

  This documents the Cargo features making sure docs.rs shows warning for
  feature-gated items. They are also explicitly spelled out in the crate
  documentation.

  The PR is similar in spirit to https://github.com/rust-bitcoin/rust-bitcoin/pull/633

ACKs for top commit:
  apoelstra:
    ACK 18f74d5242

Tree-SHA512: 8aac3fc5fd8ee887d6b13606d66b3d11ce44662afb92228c4f8da6169e3f70ac6a005b328f427a91d307f8d36d091dcf24bfe4d17dfc034d02b578258719a90a
2022-01-06 15:42:32 +00:00
sanket1729 e595b39510 Re-export Parity struct
pub struct Parity is under a private module key. It is therefore not
possible to use it downstream.
2022-01-06 09:08:59 +05:30
Andrew Poelstra f7baa53b94
Merge rust-bitcoin/rust-secp256k1#357: release secp256k1-sys 0.4.2; make new `ZERO` type publically accessible
c50411f798 release secp256k1-sys 0.4.2; make new `ZERO` type publically accessible (Andrew Poelstra)

Pull request description:

  Exposes the new const object provided by #345

ACKs for top commit:
  elichai:
    ACK c50411f798

Tree-SHA512: 42fce191b68a88811c339ff267dafbb616e765108f5b2e70514b5153f64ef5152f5704982ddc0b20ece5ad15da23927e18f9c78af2763ef971c0e3b9bbf490a5
2022-01-05 16:02:46 +00:00
Andrew Poelstra c50411f798 release secp256k1-sys 0.4.2; make new `ZERO` type publically accessible 2022-01-05 15:56:49 +00:00
Andrew Poelstra 11ef535fa5
Merge rust-bitcoin/rust-secp256k1#347: Release 0.21.0
c3df9b89a2 Release 0.21.0 (Andrew Poelstra)

Pull request description:

  .

ACKs for top commit:
  elichai:
    re-ACK c3df9b89a2
  sanket1729:
    utACK c3df9b89a2. Excited for the new release

Tree-SHA512: ddcc62d3c0b1b967dec0e792f462bced8a255187902ed4cc516e0dea512ec1d8e4b9545e9fc35d4e429a2c2ca189e3c9a7192bacccb395854f54e1c49abc221d
2022-01-05 15:52:51 +00:00
Martin Habovstiak 18f74d5242 Clarify what does "less security" mean 2022-01-04 23:20:45 +01:00
Martin Habovštiak 94c55b4d09
Fixed typos/grammar mistakes
Co-authored-by: Tobin C. Harding <me@tobin.cc>
2022-01-04 23:16:28 +01:00
Martin Habovstiak 1bf05523f0 Documented features
This documents the Cargo features making sure docs.rs shows warning for
feature-gated items. They are also explicitly spelled out in the crate
documentation.
2022-01-04 16:55:01 +01:00
Andrew Poelstra 45bf2d349c
Merge rust-bitcoin/rust-secp256k1#349: Removed useless Makefile
fafc141782 Removed useless Makefile (Martin Habovstiak)

Pull request description:

  This Makefile did nothing interesting and could confuse people.

ACKs for top commit:
  apoelstra:
    ACK fafc141782

Tree-SHA512: 00337677787f98c4c4f1014f5cb4205b5e4057eaa2a1d512f44280d9e7952219b8ef3804e64dca35cc19856bbe780069ce3ab072a082023c72143542aaaaacaa
2022-01-04 14:33:08 +00:00
Andrew Poelstra c3df9b89a2 Release 0.21.0 2022-01-04 14:30:00 +00:00
Andrew Poelstra 4833b97169
Merge rust-bitcoin/rust-secp256k1#344: Improve handling of parity integer
ede114fb1a Improve docs on tweak_add_check method (Tobin Harding)
fbc64c7725 Add opaque parity type (Tobin Harding)
1b768b2749 Make tweak_add_assign return statements uniform (Tobin Harding)
edafb88f8c Move key unit tests to key module (Tobin Harding)
e3d21a3d87 Clean up test imports with key module (Tobin Harding)

Pull request description:

  Two functions in the FFI secp code return and accept a parity integer.

  Currently we are manually converting this to a bool. Doing so forces readers of the code to think what the bool means even though understanding this value is not needed since in is just passed back down to the FFI code.

  We initially tried to solve this issue by adding an enum, discussion below refers to that version. Instead of an enum we can solve this issue by adding an opaque type that holds the parity value returned by the FFI function call and then just pass it back down to FFI code without devs needing to know what the value should be. This fully abstracts the value away and removes the boolean conversion code which must otherwise be read by each dev.

  - Patch 1 and 2 improve unit tests that test the code path modified by this PR
  - Patch 3 trivially changes code to be uniform between two similar methods (`tweak_add_assign`)
  - Patch 4 is the meat and potatoes (main part of PR :)
  - Patch 5 is docs improvements to code in the area of this PR

ACKs for top commit:
  apoelstra:
    ACK ede114fb1a

Tree-SHA512: 37843e066d9006c5daa30dece9f7eb7a802864b85606e43ed2651c6d55938c4f884cc4abab81eccb69685f6eda918a9b9ba57bf1a4efec41e89239b99ae2b726
2022-01-04 14:28:29 +00:00
Martin Habovstiak fafc141782 Removed useless Makefile
This Makefile did nothing interesting and could confuse people.
2022-01-04 15:25:02 +01:00
Tobin Harding ede114fb1a Improve docs on tweak_add_check method
It is not immediately apparent what 'err == 1' means, one must determine
that the FFI function call returns 1 for success. We can help readers of
the code by adding a 'Return' section to the method documentation.

Add trailing full stop to method docs initial line also.
2022-01-04 09:19:11 +11:00
Tobin Harding fbc64c7725 Add opaque parity type
Two functions in the FFI secp code return and accept a parity int.
Currently we are manually converting this to a bool. Doing so forces
readers of the code to think what the bool means even though
understanding this bool is not needed since in is just passed back down
to the FFI code. We can abstract this away by using an opaque type to
hold the original int and not converting it to a boolean value.

Add 'Return' and 'Error' sections to `tweak_add_assign` while fixing the
docs to describe the new opaque parity type.
2022-01-04 09:19:05 +11:00
Tobin Harding 1b768b2749 Make tweak_add_assign return statements uniform
We have two `tweak_add_assign` methods (one for keypair and one for
x-only pubkey). Both check the return value from a FFI function call.
We can make both sites uniform to _slightly_ reduce cognitive load when
reading the code.

Use C style code to make it obvious to readers that this is basically C
code.
2022-01-04 09:01:34 +11:00
Tobin Harding edafb88f8c Move key unit tests to key module
There are currently two unit tests in the `schnorr` module that are
testing keys from the `key` module. This is possible because the tests
are only testing the public interface, none the less they are better
placed in the `key` module.
2022-01-04 08:23:05 +11:00
Tobin Harding e3d21a3d87 Clean up test imports with key module
The import statements can be simplified by using an import
wildcard (`super::*`). While we are at it put them in std, external
crate, this crate order.
2022-01-04 08:18:44 +11:00
Andrew Poelstra f531be3e3c
Merge rust-bitcoin/rust-secp256k1#348: Re-export types to reduce breaking changes downstream
eab549c46c Re-export types to reduce breaking changes downstream (sanket1729)

Pull request description:

  .

ACKs for top commit:
  elichai:
    ACK eab549c46c
  apoelstra:
    ACK eab549c46c

Tree-SHA512: ca3b2c09d68f3401302528779eff4de3204680bd1bbb1795df8e397e562d6e8c10781e083b97c0c3e81c754d70197852e55640976a879b2e8c4584905026736c
2022-01-03 16:07:59 +00:00
sanket1729 eab549c46c Re-export types to reduce breaking changes downstream 2022-01-03 08:55:54 +05:30
Andrew Poelstra 6a893208f8
Merge rust-bitcoin/rust-secp256k1#345: Add a static immutable zero aligned type
5e6d0f1363 Switch to associated constant (Jonathan Underwood)
9cf552e240 Add a static immutable zero aligned type (junderw)

Pull request description:

  The `zeroed` fn can not be used in static assignments.

  In environments where it is no_std and no allocator are present, the only way to get a slice of AlignedTypes is dynamically, so `preallocated_gen_new` can't be used.

  By offering this as a static, it can be used in static assignments as such:

  ```rust
  #[cfg(target_pointer_width = "32")]
  static mut CONTEXT_BUFFER: [AlignedType; 69645] = [ZERO_ALIGNED; 69645];
  #[cfg(target_pointer_width = "64")]
  static mut CONTEXT_BUFFER: [AlignedType; 69646] = [ZERO_ALIGNED; 69646];
  static mut SECP256K1: Option<Secp256k1<AllPreallocated>> = None;

  pub fn get_context(seed: Option<&[u8; 32]>) -> &'static Secp256k1<AllPreallocated<'static>> {
      unsafe {
          if SECP256K1.is_none() {
              SECP256K1 = Some(
                  Secp256k1::preallocated_gen_new(&mut CONTEXT_BUFFER)
                      .expect("CONTEXT_BUFFER size is wrong"),
              );
          }
          if let Some(seed) = seed {
              SECP256K1.as_mut().unwrap().seeded_randomize(seed);
          }
          SECP256K1.as_ref().unwrap()
      }
  }
  ```

ACKs for top commit:
  apoelstra:
    ACK 5e6d0f1363

Tree-SHA512: fc800f8c5c637fc7f81312da17f0a96d17cd087a2e6876f4dedbefffbe92b3625deb93636265f334f9fbd7ac38baa529d4ec72857dae662e26d753f32f91d394
2022-01-02 23:31:34 +00:00
Andrew Poelstra 50034ccb18
Merge rust-bitcoin/rust-secp256k1#342: Change context objects for verification methods
21aa914ad2 Change context objects for schnorr sig methods (sanket1729)

Pull request description:

  - The current schnorrsig verify methods should operate on verify context
  as is done throughout the bitcoin core
  - Finally, and importantly the XonlyPublicKey::from_keypair now operates
  without any context parameter.

ACKs for top commit:
  apoelstra:
    ACK 21aa914ad2

Tree-SHA512: 035338f19839805a080eb262ae7b93ab187dabb63086c8b7f6015f3a6006986604dc2c6f329a99a20ddfa78c1ee518f44cd5eee2f73810fbdc83ff8df7d12506
2021-12-24 14:34:07 +00:00
Jonathan Underwood 5e6d0f1363
Switch to associated constant 2021-12-23 12:30:43 -07:00
sanket1729 21aa914ad2 Change context objects for schnorr sig methods
- The current schnorrsig verify methods should operate on verify context
as is done throughout the bitcoin core
- Scondly, and importantly the XonlyPublicKey::from_keypair now operates
without any context objects.
2021-12-24 00:54:06 +05:30
Andrew Poelstra ada3f98ab6
Merge rust-bitcoin/rust-secp256k1#313: Serde implementation for KeyPair type
de77518d3a Serde serialization for KeyPair (Dr Maxim Orlovsky)

Pull request description:

  Serde implementation for `KeyPair` type (which hadn't it before).

  Based on #312 (includes all commits from that PR, will be rebased upon merge)

ACKs for top commit:
  apoelstra:
    ACK de77518d3a

Tree-SHA512: 1e75c4fc772dcba5ce7edb30235a58550342cf986c6a77b4affd81defeba456c9655e28b081e0040c1f8440da3f7ad2224485d35222c1921099567b4d1533794
2021-12-20 14:44:59 +00:00
junderw 9cf552e240
Add a static immutable zero aligned type 2021-12-04 13:38:34 +09:00
Dr Maxim Orlovsky de77518d3a
Serde serialization for KeyPair 2021-11-12 21:18:53 +01:00
Andrew Poelstra 48683d87c8
Merge rust-bitcoin/rust-secp256k1#327: Re-arrange functionality to make ECDSA and Schnorr equal-ish citizens
d244b4d747 Fix typo in docs (Thomas Eizinger)
c5c95513f2 Move helper function below usage (Thomas Eizinger)
ce4427747d Move ECDSA functionality into ECDSA module (Thomas Eizinger)
e0c3bb28c4 Rename schnorr functions on `Secp256k1` to match naming of ecdsa (Thomas Eizinger)
760559c70e Rename `schnorrsig` module to `schnorr` (Thomas Eizinger)
d4fb819d80 Move `XOnlyPublicKey` to `key` module (Thomas Eizinger)
87d936a765 Rename `schnorr::PublicKey` to `schnorr::XOnlyPublicKey` (Thomas Eizinger)
2e0e731664 Move `KeyPair` to `key` module (Thomas Eizinger)
c47ead9967 Move `Signature` and `SerializedSignature` to new `ecdsa` module (Thomas Eizinger)
49c7e21486 Prefer `use super::*` import over manually picking items (Thomas Eizinger)
52d0554423 Fully qualify Error to simplify imports (Thomas Eizinger)
8e96abae39 Make `key` module private (Thomas Eizinger)

Pull request description:

  This patch-set tries to re-structure the library a bit. What we currently have seems to have been mostly driven by historical growth. For example, with the addition of Schnorr signatures, just exposing `secp256k1::Signature` is ambiguous.

  This PR only contains renames and moving around of code. I've tried to structure the patches in such a way that makes this reasonably easy to review. Feedback welcome!

ACKs for top commit:
  sanket1729:
    ACK d244b4d747
  apoelstra:
    ACK d244b4d747

Tree-SHA512: d40af5c56ffa500305e40eb5dbe72f2f6d6193b3a190910018d3bacdec2820ab6a59f15d47d11e0fee7ef4de6efd46d316636cd502aad5db4f314dedfff726f9
2021-11-12 13:04:45 +00:00
Thomas Eizinger d244b4d747
Fix typo in docs 2021-11-11 13:43:51 +11:00
Thomas Eizinger c5c95513f2
Move helper function below usage
This is not C89. We can declare the more important things first.
2021-11-11 13:43:50 +11:00
Thomas Eizinger ce4427747d
Move ECDSA functionality into ECDSA module 2021-11-11 13:43:50 +11:00
Thomas Eizinger e0c3bb28c4
Rename schnorr functions on `Secp256k1` to match naming of ecdsa
The naming scheme we employ is `{sign,verify, ...}_{ecdsa,schnorr}`.
2021-11-11 13:43:50 +11:00
Thomas Eizinger 760559c70e
Rename `schnorrsig` module to `schnorr`
Schnorr is commenly known as a signature algorithm, we don't need
to restate that in the name of the module.
2021-11-11 13:43:50 +11:00
Thomas Eizinger d4fb819d80
Move `XOnlyPublicKey` to `key` module 2021-11-11 13:43:49 +11:00
Thomas Eizinger 87d936a765
Rename `schnorr::PublicKey` to `schnorr::XOnlyPublicKey`
The public key is unrelated to the signature algorithm. It will
be moved out of the module in another commit. For ease of review,
the renamed is kept separate.
2021-11-11 13:43:49 +11:00
Thomas Eizinger 2e0e731664
Move `KeyPair` to `key` module
The `KeyPair` type is semantically unrelated to the schnorr signature
algorithm.
2021-11-11 13:43:48 +11:00
Thomas Eizinger c47ead9967
Move `Signature` and `SerializedSignature` to new `ecdsa` module
With the introduction of Schnorr signatures, exporting a `Signature`
type without any further qualification is ambiguous. To minimize the
ambiguity, the `ecdsa` module is public which should encourage users
to refer to its types as `ecdsa::Signature` and `ecdsa::SerializedSignature`.

To reduce ambiguity in the APIs on `Secp256k1`, we deprecate several
fucntions and introduce new variants that explicitly mention the use of
the ECDSA signature algorithm.

Due to the move of `Signature` and `SerializedSignature` to a new module,
this patch is a breaking change. The impact is minimal though and fixing the
compile errors encourages a qualified naming of the type.
2021-11-11 13:43:48 +11:00
Thomas Eizinger 49c7e21486
Prefer `use super::*` import over manually picking items
Tests are usually placed next to the code they are testing. As such,
importing `super::*` is a good starting point.
2021-11-11 13:38:54 +11:00
Thomas Eizinger 52d0554423
Fully qualify Error to simplify imports 2021-11-11 13:38:52 +11:00
Thomas Eizinger 8e96abae39
Make `key` module private
We re-export all structs residing in that module. There is no reason
to expose the internal module structure of the library publicly.
2021-11-11 13:38:49 +11:00
Andrew Poelstra 96d2242f6a
Merge rust-bitcoin/rust-secp256k1#335: Implement `Hash` for `schnorrsig::Signature`
75b49efb3d Implement `Hash` for all array newtypes (elsirion)

Pull request description:

  I pondered putting the impl into the array type macro together with `(Partial)Eq`, but that would have meant removing other implementations and potentially implementing it for types where it is not wanted. The drawback of the separate impl is that it is more disconnected from the `(Partial)Eq` impl and could theoretically diverge (although unlikely in case of such a simple type) which would break the trait's contract.

ACKs for top commit:
  apoelstra:
    ACK 75b49efb3d

Tree-SHA512: 44d1bebdd3437dfd86de8b475f12097c4a2f872905c822a9cde624089fdc20f68f59a7734fdcc6f3a17ed233f70f63258dfd204ca269d2baf8002ffc325ddc87
2021-11-05 14:29:50 +00:00
elsirion 75b49efb3d
Implement `Hash` for all array newtypes
* implements `Hash` as part of the newtype macro
* removes type-specific implementations
2021-11-04 22:16:42 +01:00
Andrew Poelstra 476ced62fe
Merge rust-bitcoin/rust-secp256k1#307: Fixing documentation for BIP 340-related functions
931b560dc7 Fixing documentation for BIP 340-related functions (Dr Maxim Orlovsky)

Pull request description:

ACKs for top commit:
  thomaseizinger:
    ACK 931b560dc7
  apoelstra:
    ACK 931b560dc7

Tree-SHA512: d78fbda138e636c04c6f356e2a41fcdd0270eea710a9af6c965ff90acfd6740bd650a8909638c558badd52d307cbdcd914fa25846236b064ca8c38faccec8be8
2021-11-02 18:39:09 +00:00
Andrew Poelstra 5dcdffac82
Merge rust-bitcoin/rust-secp256k1#317: Add cross testing on rust tier 1 and tier 2 with host tools
801c3789c4 disable illumos and netbsd (Riccardo Casatta)
a426456bfa [CI] add cache (Riccardo Casatta)
f1bdee210a add cross testing on rust tier 1 and tier 2 with host tools (Riccardo Casatta)

Pull request description:

  After working on https://github.com/rust-bitcoin/rust-bitcoin/pull/627 I thought it may be simple and useful to use [cross](https://github.com/rust-embedded/cross) environment to test across different architectures and started here.

  So I took all rust tier1 and tier2 with Host tools archictectures and added to the test matrix, run here https://github.com/RCasatta/rust-secp256k1/actions/runs/985791240.

  Errors on darwin are due to the environment because it works fine on physical machine, however errors on illumos and netbsd maybe are useful to know?

ACKs for top commit:
  apoelstra:
    utACK 801c3789c4

Tree-SHA512: 43c7220e41856344d4a932426d8acb8e9f004fcf33acfbde4b26f3a6074b0ce3e766d99afaca6c18381a4438775fa693b06c70d3204d83ff5a97fcbebe126056
2021-11-02 18:34:46 +00:00
Andrew Poelstra 6a774bd47c
Merge rust-bitcoin/rust-secp256k1#334: Use explicit u8 when assigning a byte slice
24d6f62603 Use explicit u8 when assigning a byte slice (junderw)

Pull request description:

  Is there a way to tell the compiler to not allow `[0; 64]` and require that either the type is explicitly given to the variable, or that each member uses explicit `0u8` notation?

  I noticed the usage was a mix of explicit and implicit, so I changed all to explicit.

ACKs for top commit:
  apoelstra:
    ACK 24d6f62603

Tree-SHA512: f7796dcc3ae240983257bef0f25bd0df741943f75d86e9bca7c45076af179d96ce213bd9c339a01f721f7dc9b96a0a4a56ef2cf44339f4c91d208103b7659d9f
2021-11-02 18:21:14 +00:00
Andrew Poelstra 88196bdb3d
Merge rust-bitcoin/rust-secp256k1#312: Display and Debug for secret keys prints a hash
6810c2b547 Dedicated display_secret fn for secret-containing types (Dr Maxim Orlovsky)
635a6ae441 Add to_hex converter and add tests for hex conversion (Elichai Turkel)

Pull request description:

  Extract of concept ACK part of #311 related to changing the way secret keys are displayed/printed out

ACKs for top commit:
  apoelstra:
    ACK 6810c2b547
  thomaseizinger:
    ACK 6810c2b547

Tree-SHA512: 22ad7b22f47b177e299ec133129d607f8c3ced1970c4c9bea6e81e49506534c7e15b4fb1d745ba1d3f85f27715f7793c6fef0b93f258037665b7f740b967afe5
2021-11-02 17:58:08 +00:00
Riccardo Casatta 801c3789c4
disable illumos and netbsd 2021-10-28 12:10:46 +02:00
Riccardo Casatta a426456bfa
[CI] add cache 2021-10-28 12:10:44 +02:00