Skip to content

Add BoxedUint::{from_be_slice_truncated, from_le_slice_truncated}#1266

Merged
tarcieri merged 1 commit into
masterfrom
boxed/from-slice-truncated
Jun 18, 2026
Merged

Add BoxedUint::{from_be_slice_truncated, from_le_slice_truncated}#1266
tarcieri merged 1 commit into
masterfrom
boxed/from-slice-truncated

Conversation

@tarcieri

@tarcieri tarcieri commented May 12, 2026

Copy link
Copy Markdown
Member

Adds infallible constructors for BoxedUint that handle the error case for the current from_be_slice/from_le_slice by truncating the input.

My real goal is to be able to add some slice constructors to the Encoding trait that can actually provide equivalent semantics between Uint and BoxedUint and also ensure construction of modulus-sized BoxedUints.

A truncating behavior like this eliminates the error case and allows for an infallible constructor. As it were, it's largely mimicking the bits2int function described in RFC6979 § 2.3.2 which is what I'd like to implement using Uint for ECDSA an BoxedUint for DSA.

An infallible constructor lets us compose both from_*e_slice_vartime and from_*e_slice in terms of from_*e_slice_truncated, whee the former is also infallible and picks its capacity/precision on-the-fly based on the input data (e.g. we need that to decode the public modulus and figure out what precision we're working with).

@tarcieri tarcieri changed the title [WIP] Add `BoxedUint::{from_be_slice_truncated, from_le_slice_truncat… [WIP] Add BoxedUint::{from_be_slice_truncated, from_le_slice_truncated} May 12, 2026
@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (97aa9b1) to head (ee3baff).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1266      +/-   ##
==========================================
+ Coverage   91.33%   91.35%   +0.02%     
==========================================
  Files         189      189              
  Lines       22480    22534      +54     
==========================================
+ Hits        20533    20587      +54     
  Misses       1947     1947              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tarcieri tarcieri requested a review from fjarri May 12, 2026 23:05
@tarcieri

tarcieri commented May 12, 2026

Copy link
Copy Markdown
Member Author

cc @andrewwhitehead

I'm going to try to flesh this out more with the trait changes I'd like and see if I can actually use it to implement the full RFC6979.

Edit: obviously needs tests as well.

Comment thread src/uint/boxed/encoding.rs Outdated
Comment thread src/uint/boxed/encoding.rs
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Jun 6, 2026
The changes in #1360 were breaking, so this release bumps the minor
version.

It might be possible to get some additional breaking changes in as well,
if we can land RustCrypto/crypto-bigint#1266.
@tarcieri tarcieri mentioned this pull request Jun 7, 2026
tarcieri added a commit that referenced this pull request Jun 7, 2026
@tarcieri tarcieri force-pushed the boxed/from-slice-truncated branch 2 times, most recently from 57e17ce to 0fd8484 Compare June 18, 2026 15:12
@tarcieri tarcieri changed the title [WIP] Add BoxedUint::{from_be_slice_truncated, from_le_slice_truncated} Add BoxedUint::{from_be_slice_truncated, from_le_slice_truncated} Jun 18, 2026
@tarcieri tarcieri force-pushed the boxed/from-slice-truncated branch from 0fd8484 to d44333a Compare June 18, 2026 15:28
@tarcieri tarcieri marked this pull request as ready for review June 18, 2026 15:28
Adds infallible constructors for `BoxedUint` that handle the error case
for the current `from_be_slice`/`from_le_slice` by truncating the input.

My real goal is to be able to add some slice constructors to the
`Encoding` trait that can actually provide equivalent semantics between
`Uint` and `BoxedUint` and also ensure construction of modulus-sized
`BoxedUint`s.

A truncating behavior like this eliminates the error case and allows for
an infallible constructor. As it were, it's largely mimicking the
`bits2int` function described in RFC6979 § 2.3.2 which is what I'd like
to implement using `Uint` for ECDSA an `BoxedUint` for DSA.

An infallible constructor lets us compose both `from_*e_slice_vartime`
and `from_*e_slice` in terms of `from_*e_slice_truncated`, whee the
former is also infallible and picks its capacity/precision on-the-fly
based on the input data (e.g. we need that to decode the public modulus
and figure out what precision we're working with).
@tarcieri tarcieri force-pushed the boxed/from-slice-truncated branch from d44333a to ee3baff Compare June 18, 2026 15:31
@tarcieri tarcieri merged commit 2b2df19 into master Jun 18, 2026
32 checks passed
@tarcieri tarcieri deleted the boxed/from-slice-truncated branch June 18, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants