Skip to content

dsa: reduce Box<[u8]> allocation in SignatureEncoding::to_vec #969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dishmaker
Copy link
Contributor

Rewritten as SignatureRef


use crate::Signature;

pub(crate) struct SignatureBoxed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is essentially what dsa::Signature is (dsa::Signature is composed of NonZero<BoxedUint>)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be possible to get an iterator over the inner limbs? and get big endian from there? without allocating a new box.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

der checks for leading zeros when encoding UIntRef, so it would be too tricky

Copy link
Member

@baloo baloo May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that's just up to the consumer of the said iterator to strip leading zeroes? I don't know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah nevermind, you have to have a buffer for SignatureRef, that can't be an iterator of limbs.

@tarcieri
Copy link
Member

The crypto-bigint crate has native support for der, although it's missing DecodeValue/EncodeValue impls for BoxedUint (and NonZero<BoxedUint>). They exist for Uint.

Perhaps support could be added there so there's not need for complex encoding logic in the dsa crate.

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.

3 participants