Commit Graph

38 Commits

Author SHA1 Message Date
Nick Johnson ea0a31876f
release: prep chacha20-poly1305 crate for 0.1.2 2025-05-15 19:40:15 -07:00
merge-script ef5e3256df
Merge rust-bitcoin/rust-bitcoin#4509: fix: add author to the chacha20_poly1305 crate
b17452b77a fix: add authors to the chacha20_poly1305 crate (Nick Johnson)

Pull request description:

  Closes #4501

ACKs for top commit:
  rustaceanrob:
    ACK b17452b77a
  tcharding:
    ACK b17452b77a
  apoelstra:
    ACK b17452b77a2034074d97673450b61f7d9f9b6039; successfully ran local tests

Tree-SHA512: 7c47affbcfc1cfa8a7591076d8b74e15e936af9251ba0d375ce0701175f9966e86b56fed5202945df96b7294d431d3b02dc3c7fc2749c96ac96afa3888f2039f
2025-05-15 18:16:54 +00:00
merge-script 35a49993c8
Merge rust-bitcoin/rust-bitcoin#4083: Improve chacha20 cipher performance
1ca55ac77d chacha20_poly1305: inline simd functions (Nick Johnson)
30920c4d84 chacha20_poly1305: drop mutable requirement (Nick Johnson)
415945cd2b chacha20_poly1305: avoid duplicate block work (Nick Johnson)
33dc1b95fa chacha20_poly1305: swap tuple for array (Nick Johnson)
dadd1d7224 chacha20_poly1305: remove alignment (Nick Johnson)
36d45bf360 chacha20_poly1305: remove mod operator (Nick Johnson)

Pull request description:

  Inspired by JeremiahR's new benchmark on the chacha20 module, I dug in and found a few tweaks (and a larger refactor) which help a lot with performance.

  The tweaks are broken down by commit. One of the relatively fruitful ones (5% increase) was refactoring the U32x4's rotation methods to use hardcoded matches instead of the mod operator. Others saw more modest performance gains.

  The big change though was to *not* calculate two blocks for each keystream call (oops). I refactored the logic to handle the offset state (which is technically not required for BIP324, but as seen here, can be confusing to not have) and now we always calculate just the required amount of a keystream. This about doubles the performance.

  For the curious, the SIMD performance isn't very impressive at this point, just a modest increase. But I have some hope that the experimental core library U32x4 will bring a nice bump (it is implemented with some unsafe hacking) and be an easy refactor.

ACKs for top commit:
  apoelstra:
    ACK 1ca55ac77db698f3816d8b7ed4051ddb5a579a29; successfully ran local tests
  tcharding:
    ACK 1ca55ac77d

Tree-SHA512: 8db1c6144d172775164859ffd0d97021f90d9123d06b5cccde21800aec4dcea75a5753d547933288ae233caf82e92849f894fb7019537d188baf10fbf7019684
2025-05-15 12:47:00 +00:00
Nick Johnson b17452b77a
fix: add authors to the chacha20_poly1305 crate 2025-05-14 20:51:34 -07:00
merge-script 8a563efb02
Merge rust-bitcoin/rust-bitcoin#4460: fix duplicate poly1305.rs
f36b8f22d9 fix duplicate poly1305.rs (futreall)

Pull request description:

  hi devs
  fixed error `and and`

ACKs for top commit:
  tcharding:
    ACK f36b8f22d9

Tree-SHA512: 65669ebcd289e2431fe2126ad8256fdc79f2c3afc2bdff4ded968f453bd865feb82488ba9ab2ec1678b1d9b9c6947e82e61848d8f445d0558eb24a51cad76a4d
2025-05-07 21:51:10 +00:00
futreall f36b8f22d9
fix duplicate poly1305.rs 2025-05-07 12:57:11 +03:00
Jamil Lambert, PhD 2fbbc825c9
Allow uninlined format args
There is a new lint error on nightly-2025-04-25 "variables can be used
directly in the `format!` string".

Exclude the lint to allow the existing syntax in `format!` strings.
2025-05-06 09:49:02 +01:00
Jamil Lambert f22e997587
Use parameters instead of arguments in rustdocs
The rustdocs use both `# Parameters` and `# Arguments` to mean the same
thing.

Change all of them to `# Parameters` to be consistent.
2025-04-22 10:43:13 +01:00
healthyyyoung 427bfb82d7 chore: spellchecker 2025-03-16 07:23:18 +00:00
Tobin C. Harding 83d071e54b
chacha20: Add whitespace
Mirror the other crates. Whitespace only.
2025-03-03 13:33:19 +11:00
Tobin C. Harding 4451724d31
chacha20: Add a docs heading
Like we do for the other crates add a heading to the crate docs.
2025-03-03 13:33:11 +11:00
Nick Johnson 1ca55ac77d
chacha20_poly1305: inline simd functions
* Inline all the block operations to give the compiler the best chance
to optimize the SIMD instruction usage. This squeezed out another
percent or two on the benchmarks when comparing target-cpu=native
builds to standard.
2025-02-24 15:29:29 -08:00
Nick Johnson 30920c4d84
chacha20_poly1305: drop mutable requirement
* The get_keystream method exposes the keystream for a block for
special case scenarios. Generally the cipher state should only be
updated with teh apply_keystream method.
2025-02-24 15:29:29 -08:00
Nick Johnson 415945cd2b
chacha20_poly1305: avoid duplicate block work
* The keystream function is creating two state block on every call,
but just to handle a corner case. Break up the function
into separate methods so that the corner case is handled by itself,
avoiding unnecessary work most of the time.
* Handle offset state internally. While not strictly necessary due to
the cipher's use in BIP324, it makes the library much easier to work
with (the bug above would probably have been avoided) if the cipher
handles the offset state.
2025-02-24 15:29:29 -08:00
Nick Johnson 33dc1b95fa
chacha20_poly1305: swap tuple for array
* While perhaps a small performance gain, < 1%, this conforms to the
style used in the rest of the module.
2025-02-24 15:29:29 -08:00
Nick Johnson dadd1d7224
chacha20_poly1305: remove alignment
* Benchmarks showed that on recent versions of the rust compiler,
alignment settings could hurt and never helped.
2025-02-24 15:29:29 -08:00
Nick Johnson 36d45bf360
chacha20_poly1305: remove mod operator
* Swaps out the mod operator for a switch statement for a 5% performance
boost.
2025-02-24 15:29:29 -08:00
Fmt Bot 0596867048 2025-02-23 automated rustfmt nightly 2025-02-23 01:21:34 +00:00
jeremiah e41653d188 add chacha20 benchmarks 2025-02-17 21:00:40 -05:00
Fmt Bot 8bdd67a368 2025-01-12 automated rustfmt nightly 2025-01-12 01:23:13 +00:00
Tobin C. Harding 2c9fda4135
Add parenthesis to explicitly show precedence
Recent clippy nightly update introduces warnings about precedence. While
ours are, IMO, clear the lint docs have some cases that are not so I
don't think we should ignore this lint. Specifically I could easily miss
this one

  1 << 2 + 3 equals 32, while (1 << 2) + 3 equals 7

ref: https://rust-lang.github.io/rust-clippy/master/#/precede

Add parenthesis to explicitly show precedence. Refactor only no logic
changes.
2025-01-04 15:25:00 +11:00
Tobin C. Harding 85e04315d5
Remove test_ prefix from unit tests
There is a loose convention in Rust to not use `test_` prefix. The
reason being that `cargo test` outputs 'test <test name>' using the
prefix makes the output stutter.

This patch smells a bit like code-churn but having the prefix in some
places and not others is confusing to new contributors and is leading me
to explain this many times now. Lets just fix it.

Remove the prefix unless doing so breaks the code.
2025-01-02 10:06:50 +11:00
calciumbe 9a5970dbfe
chacha20_poly1305: fix typo 2024-12-23 20:44:18 +08:00
merge-script 73e33e5808
Merge rust-bitcoin/rust-bitcoin#3581: Fix re-exports and (manually) format the codebase
727c519efa Re-export amount from primitives (Tobin C. Harding)
84ede349b0 Run the formatter (Tobin C. Harding)
4865d60258 bitcoin: Improve the re-exports ... again (Tobin C. Harding)

Pull request description:

  When we messed with the re-exports recently we failed to notice that the formatter would move the `pub use` blocks around because I only put `rustfmt::skip` on one block, I thought that had the effect of stopping all exports below that block being changed, turns out I was wrong.

  Run the formatter then make some minor changes to the re-exports in `bitcoin`, including changing comments that do not make sense with the new layout.

ACKs for top commit:
  apoelstra:
    ACK 727c519efa771d3ec6a21350e4638b9f1536bfe1; successfully ran local tests

Tree-SHA512: fa9fbadf7efa0a76db6a0a2915fcabeda348c561e4047f9517ca7fba1a2008d5624072b7a9ce6069d71c229a794b4d27c3d96195768e87b3c2c412d611ecbfcf
2024-11-11 20:15:14 +00:00
merge-script c3a4ba2c5a
Merge rust-bitcoin/rust-bitcoin#3593: Release tracking PR: chacha20-poly1305 v0.1.1
2ae6a9abc1 Prep the chacha20-poly1305 crate for release (Nick Johnson)

Pull request description:

  Bump the patch version to `v0.1.1` to include the no_std support.

  Could see this requiring `v0.2.0`, but went with the patch bump.

ACKs for top commit:
  apoelstra:
    ACK 2ae6a9abc1cb6b0f3edb358ebe5e9a0781051abe; successfully ran local tests; let's do it
  tcharding:
    ACK 2ae6a9abc1

Tree-SHA512: 880e8390447c238bfd0e9493682622213b91f7f41c8c320fea6af763e00d73fb30bfc545f420b79614a8b33249abbd08bc9dcb7ace9522a68862194240b7258a
2024-11-11 16:43:11 +00:00
Tobin C. Harding 84ede349b0
Run the formatter
Run `just fmt`, no manual changes.
2024-11-11 14:19:17 +11:00
Nick Johnson 2ae6a9abc1 Prep the chacha20-poly1305 crate for release
Bump the patch version to 0.1.1 to include the no_std support.
2024-11-09 07:23:45 -08:00
Nick Johnson eb0a7b40ec Add callouts to the chacha20-poly1305 public docs
Making it clear in the chacha20-poly1305 documentation that this
implementation is maintained by bitcoin developers and targeted
specifically for bitcoin ecosystem use cases.
2024-11-08 10:56:36 -08:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
Tobin C. Harding 9f60e1ae26
Copy crate level attributes to chacha20_poly1305
No obvious reason not to; copy the crate level attributes that we have
in all our other crates.
2024-11-04 13:38:19 +11:00
Fmt Bot 5ecf7f2d67 2024-11-03 automated rustfmt nightly 2024-11-03 01:21:14 +00:00
merge-script dbb35c0960
Merge rust-bitcoin/rust-bitcoin#3545: Add no_std flag to the chacha20-poly1305 crate
26ed97877b Add no_std flag to the chacha20-poly1205 crate (Nick Johnson)

Pull request description:

  I unfortunately forgot to copy over the `no_std` configuration when I promoted the chacha20_poly1305 from an internal module (where it inherited the setting) to the main module of the new crate.

  This crate is using a slightly simpler no_std pattern than some other crates in the org. I like the simple approach, but can update it if consistency is valued in this case.

ACKs for top commit:
  tcharding:
    ACK 26ed97877b
  apoelstra:
    ACK 26ed97877bdbee0b9b67db52ff0d53b706361e08; successfully ran local tests

Tree-SHA512: ffa672b7593daa4148ef8584903939e976302138b0aae1f09de647885629e502bcb1380471b29d8cd28ae52a435e52bd22b231c6631528d17fe3090e7f56add7
2024-10-31 22:09:34 +00:00
Nick Johnson 26ed97877b Add no_std flag to the chacha20-poly1205 crate 2024-10-30 20:48:21 -07:00
Leo Nash 7f289a9fdf Bump hex-conservative to 0.3.0 2024-10-31 03:36:22 +00:00
Nick Johnson 7d6ed16dfc Add changelog to chacha20-poly1305 crate
* No other preperation needed for release since the version is already
set in Cargo.toml.
2024-10-28 13:21:39 -07:00
Fmt Bot 2a08b29232 2024-10-20 automated rustfmt nightly 2024-10-20 01:21:52 +00:00
Nick Johnson a5f5c795f5 Add the ChaCha20Poly1305 AEAD crate
* The ChaCha20 stream cipher and the Poly1305 message authenticator
are used in BIP324's encrypted P2P transport protocol.
2024-10-14 20:55:03 -07:00