Skip to content
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

ecdsa: impl signature::hazmat::{PrehashSigner, PrehashVerifier} #534

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

tarcieri
Copy link
Member

Adds "hazmat" trait impls to SigningKey and VerifyingKey respectively which allow computing signatures over raw message digests. See RustCrypto/traits#1099.

The implementation allows digests which are shorter or longer than the field size of the curve, using zero-padding if the digest is too short, and truncating if it's too long. The minimum digest size is set to half of the curve's field size.

Adds "hazmat" trait impls to `SigningKey` and `VerifyingKey`
respectively which allow computing signatures over raw message digests.
See RustCrypto/traits#1099.

The implementation allows digests which are shorter or longer than the
field size of the curve, using zero-padding if the digest is too short,
and truncating if it's too long. The minimum digest size is set to half
of the curve's field size.
@tarcieri tarcieri force-pushed the ecdsa/prehash-signer-and-verifier-traits branch from ebd5355 to a7ff691 Compare September 12, 2022 22:41
@tarcieri tarcieri merged commit 556acaa into master Sep 12, 2022
@tarcieri tarcieri deleted the ecdsa/prehash-signer-and-verifier-traits branch September 12, 2022 22:55
@tarcieri tarcieri mentioned this pull request Sep 13, 2022
cmp::Ordering::Equal => field_bytes.copy_from_slice(prehash),
cmp::Ordering::Less => {
// If prehash is smaller than the field size, pad with zeroes
field_bytes[..prehash.len()].copy_from_slice(prehash);
Copy link
Contributor

@sorah sorah Sep 27, 2022

Choose a reason for hiding this comment

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

I'm not confident enough but if I read RFC correctly I believe this should be like:

field_bytes[(field_bytes.len()-prehash.len())..].copy_from_slice(prehash);

https://datatracker.ietf.org/doc/html/rfc6979#section-2.3.2

otherwise, qlen-blen bits (of value zero) are added to the left of the sequence

the present implementation adds zero on the right so the prehash gets "left shift"'d, while informal description in RFC says:

in many software implementations of arithmetics on big integers, that division is equivalent to a "right shift" by blen-qlen bits.

(Assume this method is intended to use with try_sign_prehashed_rfc6979)

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened a PR for this

➡️ #547

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