Skip to content

hash2curve: Bringing breaking changes to ease maintainability & usability. #1295

@carloskiki

Description

@carloskiki

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions