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

Have DigestSigner/DigestVerifier take Digest instance #17

Merged
merged 1 commit into from
Jun 6, 2019

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Jun 6, 2019

This is needed for compatibility with ed25519-dalek's Ed25519ph:

https://docs.rs/ed25519-dalek/1.0.0-pre.1/ed25519_dalek/struct.Keypair.html#method.sign_prehashed

Until const generics land, this API feels a lot cleaner to me. It gets all the GenericArray crap out of the way.

It's also misuse resistant in that it ensures the prehashing is done by the relevant hash function, as opposed to the user being able to pass in arbitrary values. There's a potential attack if a verifier accidentally accepts a raw value which isn't the output of a hash function which could allow an attacker to forge signatures:

https://twitter.com/pwuille/status/1063582706288586752

This is needed forcompatibility with ed25519-dalek's Ed25519ph:

https://docs.rs/ed25519-dalek/1.0.0-pre.1/ed25519_dalek/struct.Keypair.html#method.sign_prehashed

Until const generics land, this API feels a lot cleaner to me. It gets
all the `GenericArray` crap out of the way.

It's also misuse resistant in that it ensures the prehashing is done by
the relevant hash function, as opposed to the user being able to pass in
arbitrary values. There's a potential attack if a verifier accidentally
accepts a raw value which isn't the output of a hash function which
could allow an attacker to forge signatures:

https://twitter.com/pwuille/status/1063582706288586752
@tarcieri tarcieri merged commit a94234e into master Jun 6, 2019
@tarcieri tarcieri deleted the revise-digest-apis branch June 6, 2019 17:17
@tarcieri tarcieri mentioned this pull request Jun 7, 2019
@tarcieri tarcieri mentioned this pull request Sep 25, 2019
tarcieri added a commit to RustCrypto/traits that referenced this pull request Sep 9, 2022
Adds a `hazmat` module gated under a newly added `hazmat-preview`
feature which calls out the relevant functionality as subject to change
with minor versions.

It adds the following traits:

- `PrehashSigner`
- `PrehashVerifier`

These APIs accept the digest to be signed/verified as a raw byte slice.
This comes with potential misuses like failing to use a
cryptographically secure hash function as the `prehash`, which could
enable existential forgeries of signatures, hence gating it under a
`hazmat-preview` feature and placing it in a `hazmat` module.

Note that we previously explored APIs like this for `DigestSigner`. They
were removed in RustCrypto/signatures#17 due to the afforementioned
misuse potential.

However, these APIs are occasionally needed for implementing protocols
that use special rules for computing hashes (e.g. EIP-712 structured
hashes), or for implementing things like network signing services which
want to accept a prehash of a message to be signed rather than the full
message (to cut down on network bandwidth).

The traits accept a byte slice `prehash`, which permits multiple lengths
and allows the implementation to decide which lengths are valid. This
makes it possible for e.g. ECDSA implementations to automatically
truncate message prehashes which are larger than the field size.,
tarcieri added a commit to RustCrypto/traits that referenced this pull request Sep 9, 2022
Adds a `hazmat` module gated under a newly added `hazmat-preview`
feature which calls out the relevant functionality as subject to change
with minor versions.

It adds the following traits:

- `PrehashSigner`
- `PrehashVerifier`

These APIs accept the digest to be signed/verified as a raw byte slice.
This comes with potential misuses like failing to use a
cryptographically secure hash function as the `prehash`, which could
enable existential forgeries of signatures, hence gating it under a
`hazmat-preview` feature and placing it in a `hazmat` module.

Note that we previously explored APIs like this for `DigestSigner`. They
were removed in RustCrypto/signatures#17 due to the afforementioned
misuse potential.

However, these APIs are occasionally needed for implementing protocols
that use special rules for computing hashes (e.g. EIP-712 structured
hashes), or for implementing things like network signing services which
want to accept a prehash of a message to be signed rather than the full
message (to cut down on network bandwidth).

The traits accept a byte slice `prehash`, which permits multiple lengths
and allows the implementation to decide which lengths are valid. This
makes it possible for e.g. ECDSA implementations to automatically
truncate message prehashes which are larger than the field size.
tarcieri added a commit to RustCrypto/traits that referenced this pull request Sep 9, 2022
Adds a `hazmat` module gated under a newly added `hazmat-preview`
feature which calls out the relevant functionality as subject to change
with minor versions.

It adds the following traits:

- `PrehashSigner`
- `PrehashVerifier`

These APIs accept the digest to be signed/verified as a raw byte slice.
This comes with potential misuses like failing to use a
cryptographically secure hash function as the `prehash`, which could
enable existential forgeries of signatures, hence gating it under a
`hazmat-preview` feature and placing it in a `hazmat` module.

Note that we previously explored APIs like this for `DigestSigner`. They
were removed in RustCrypto/signatures#17 due to the afforementioned
misuse potential.

However, these APIs are occasionally needed for implementing protocols
that use special rules for computing hashes (e.g. EIP-712 structured
hashes), or for implementing things like network signing services which
want to accept a prehash of a message to be signed rather than the full
message (to cut down on network bandwidth).

The traits accept a byte slice `prehash`, which permits multiple lengths
and allows the implementation to decide which lengths are valid. This
makes it possible for e.g. ECDSA implementations to automatically
truncate message prehashes which are larger than the field size.
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.

None yet

1 participant