RustCrypto / RustCrypto/elliptic-curves

`hash2curve`: Bringing breaking changes to ease maintainability & usability.

Open
#1,295 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
874
Forks
299
Avg merge
1d 4h
Merged PRs (30d)
12

Description

There are a few changes I would like to bring to hash2curve, mainly to reduce the amount of code the crate has and make it independent of the elliptic-curve crate.

Motivations

  1. Reducing the amount of code is always a plus IMHO - makes the crate more maintainable & approachable.
  2. elliptic-curve is almost unused as a dependency, but brings a lot of transitive dependencies (see below for comparison).
  3. Some functions use out parameters and I would like to change that where possible (Expander and hash_to_field).

Changes

  • Change GroupDigest to something like a Suite trait.
/// A hash to curve suite.
///
/// <https://www.rfc-editor.org/rfc/rfc9380.html#name-suites-for-hashing>
pub trait Suite {
    const ID: &'static str;

    type Point: MapToCurve;
    type SecurityLevel: Unsigned;
    type ExpandMsg: ExpandMsg<Self::SecurityLevel>;

    fn hash_from_bytes(msg: &[&[u8]], dst: &[&[u8]]) -> Option<Self::Point> {
        // ...
    }

    fn encode_from_bytes(msg: &[&[u8]], dst: &[&[u8]]) -> Option<Self::Point> {
        // ...
    }
}
  • MapToCurve will be bound by Group instead of CurveArithmetic.
  • All places that return elliptic_curve::Result<_> will return Option instead (elliptic_curve::Error was already as ZST).
  • Make hash_to_field output Array<F, C> for F: FromOkm and C: ArraySize instead of taking &mut [F] as out parameter.
  • Make ExpandMsg return Iterator<Item = u8> instead of an Expander (This may cause a slight performance regression, will be benchmarked before it is added).

Dependency tree with & without elliptic-curve

With elliptic-curve

hash2curve v0.14.0-rc.0
├── digest v0.11.0-rc.0
│   ├── block-buffer v0.11.0-rc.4
│   │   └── hybrid-array v0.3.1
│   │       ├── typenum v1.18.0
│   │       └── zeroize v1.8.1
│   └── crypto-common v0.2.0-rc.3
│       └── hybrid-array v0.3.1 (*)
├── elliptic-curve v0.14.0-rc.10
│   ├── base16ct v0.2.0
│   ├── crypto-bigint v0.7.0-pre.6
│   │   ├── hybrid-array v0.3.1 (*)
│   │   ├── num-traits v0.2.19
│   │   │   [build-dependencies]
│   │   │   └── autocfg v1.5.0
│   │   ├── rand_core v0.9.3
│   │   ├── subtle v2.6.1
│   │   └── zeroize v1.8.1
│   ├── ff v0.14.0-pre.0
│   │   ├── rand_core v0.9.3
│   │   └── subtle v2.6.1
│   ├── group v0.14.0-pre.0
│   │   ├── ff v0.14.0-pre.0 (*)
│   │   ├── rand_core v0.9.3
│   │   └── subtle v2.6.1
│   ├── hybrid-array v0.3.1 (*)
│   ├── rand_core v0.9.3
│   ├── subtle v2.6.1
│   └── zeroize v1.8.1
├── ff v0.14.0-pre.0 (*)
└── subtle v2.6.1

Without:

hash2curve v0.14.0-rc.0
├── digest v0.11.0-rc.0
│   ├── block-buffer v0.11.0-rc.4
│   │   └── hybrid-array v0.3.1
│   │       └── typenum v1.18.0
│   └── crypto-common v0.2.0-rc.3
│       └── hybrid-array v0.3.1 (*)
├── ff v0.14.0-pre.0
│   ├── rand_core v0.9.3
│   └── subtle v2.6.1
├── group v0.14.0-pre.0
│   ├── ff v0.14.0-pre.0 (*)
│   ├── rand_core v0.9.3
│   └── subtle v2.6.1
└── subtle v2.6.1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the hash2curve crate's existing GroupDigest, MapToCurve, hash_to_field, Expander, and ExpandMsg APIs, along with its elliptic-curve dependency. Done means implementing the proposed breaking API changes, replacing Result with Option where specified, removing the dependency, and benchmarking the iterator-based ExpandMsg approach; no specific files or tests are named.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.