Skip to content

ssh-encoding: support mpint encoding and decoding without alloc - #656

Merged
tarcieri merged 1 commit into
masterfrom
ssh-encoding/mpintref
Dec 3, 2026
Merged

tarcieri merged 1 commit into
masterfrom
ssh-encoding/mpintref

Conversation

@tarcieri

@tarcieri tarcieri commented Dec 3, 2026

Copy link
Copy Markdown
Member

Add Decoder::read_mpint_bytes to decode a nonnegative SSH mpint directly into a caller-provided buffer. It left-pads the magnitude to fill the buffer and returns the significant bytes. This lets ssh-key decode P-384 scalars directly into 48-byte fields.

Add MpintRef to encode a borrowed big-endian magnitude and implement Writer for &mut [u8] so callers can write into fixed-size buffers. MpintRef emits a sign byte only when the high bit requires one.

Share the wire-format rules with the owned Mpint type. Both decoding paths reject negative values and enforce the existing wire-size limit before stripping redundant leading zeros.

Add `Decoder::read_mpint_bytes` to decode a nonnegative SSH `mpint`
directly into a caller-provided buffer. It left-pads the magnitude to
fill the buffer and returns the significant bytes. This lets `ssh-key`
decode P-384 scalars directly into 48-byte fields.

Add `MpintRef` to encode a borrowed big-endian magnitude and implement
`Writer` for `&mut [u8]` so callers can write into fixed-size buffers.
`MpintRef` emits a sign byte only when the high bit requires one.

Share the wire-format rules with the owned `Mpint` type. Both decoding
paths reject negative values and enforce the existing wire-size limit
before stripping redundant leading zeros.
@tarcieri
tarcieri merged commit 0488d68 into master Dec 3, 2026
21 checks passed
@tarcieri
tarcieri deleted the ssh-encoding/mpintref branch December 3, 2026 21:28
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.

1 participant