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

feat: Add is_small_order_point, is_prime_subgroup_point #188

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

huitseeker
Copy link
Contributor

@huitseeker huitseeker commented Jan 5, 2022

What

In a nutshell, this offers an opt-in way of performing some public key checks relating to small order components, without having to pay an additional point decompression.

In detail

Since 8dbaf9a, the PublicKey type is the performant way to carry public key material, with an eager check that the point is on curve.

However, some applications which may like eager point decompression also need to check whether the point is small order, or even torsion-free:

verify_strict was introduced to offer an opt-in approach to some of this sort of scrutiny at the time the key is used for signing, but cannot be performed eagerly, e.g. as soon as deserializing a public key.

OTOH, rejecting small order keys (or worse non-torsion-free) keys by default on deserialization would have a significant performance impact.

However, it's still desirable to have the option to seek for small-order or torsion-free-ness, long before the key is ever used for any actual cryptographic purpose (e.g. signature verification). In order to perform this sort of check, some code bases have taken to re-implementing it from the bytes representation of the key, which involves an additional decompression.

The added functions of this PR allow the checks to be performed without additional decompression.

@huitseeker huitseeker changed the base branch from main to develop January 5, 2022 15:59
In a nutshell, this offers an opt-in way of performing some public key checks relating to small order components, without having to pay an additional point decompression.

In detail:
Since dalek-cryptography@8dbaf9a, the `PublicKey` type is the performant way to carry public key material, with an eager check that the point is on curve.

However, some applications which may like eager point decompression also need to check whether the point is small order, or even torsion-free:
- aligning a discrepancy in verification between batch verification and iterated verification (see dalek-cryptography#115),
- avoiding small subgroup confinement attacks in a DH,
- ...

`verify_strict` was introduced to offer an opt-in approach to some of this sort of scrutiny at the time the key is used, but cannot be performed eagerly, e.g. at the time of deserializing a public key.

Rejecting small order keys (or worse non-torsion-free) keys on deserialization would have a performance impact. However, it's still desirable to have the option to do so long before the key is ever used for any actual cryptographic purpose (e.g. signature verification).

In order to perform this sort of check, some code bases have taken to [re-implementing the check from the bytes representation of the key, which involves an additional decompression](https://github.com/diem/diem/blob/a290b0859a6152a5ffd6f85773a875f17334adac/crates/diem-crypto/src/ed25519.rs#L358-L386).
The added functions of this PR allow the checks to be performed without additional decompression.
Copy link
Contributor

@rozbb rozbb left a comment

Choose a reason for hiding this comment

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

Agree with your reasoning and implementation. LGTM

@alinush
Copy link

alinush commented Jul 4, 2022

I'm running into the same performance issue due to the lack of this functionality. Will this be merged?

@burdges
Copy link

burdges commented Sep 8, 2022

I'd suggest evaluating ideas like this for ed25519-zebra since verify_strict winds up being kinda the opposite of what is needed for many use cases.

This was referenced Jan 27, 2023
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

4 participants