Hash to curve and field
Hash-to-field turns a message into uniform elements of a prime field or an extension field. Hash-to-curve builds on that result to turn the elements into points in a selected elliptic-curve group. Together, these flows give protocols such as BLS signatures a deterministic way to treat a message as a curve point while keeping the hash, field, and curve domains separate.
Hash-to-field flow
Hash-to-field is the byte-to-field stage used on its own or as the first stage of hash-to-curve. It expands the message into a uniform byte string, divides that string into field-sized values, and reduces each value into the target field. The same process supports base fields and the extension fields used by groups such as BLS12-381 G2.
The flow uses an optional message augmentation and a domain separation tag (DST). A DST identifies the protocol suite so that messages used by different suites do not share the same hash domain. If the DST is longer than the format permits, the flow first hashes it into a short DST.
flowchart LR
A[augmentation and message] --> B[expand message with XMD]
D[domain separation tag] --> B
B --> C[uniform bytes]
C --> E[split into field-sized values]
E --> F[reduce into field elements]
F --> G[prime or extension field output]
expandMessageXMD provides the uniform byte stream with a cryptographic hash such as SHA-256. hashToField requests the byte length needed for a fixed number of field elements and converts the result into field values. For an extension field, the flow creates the needed number of base-field components for each output element.
References: constantine/…/h2c_hash_to_field.nim• L41-55 constantine/…/h2c_hash_to_field.nim• L56-149 constantine/…/h2c_hash_to_field.nim• L166-239
Hash-to-curve flow
Hash-to-curve composes hash-to-field with a deterministic map from field elements to curve points. The public operation hashes one message into two field elements, maps both elements to the curve, adds the resulting points, and clears the cofactor so the result belongs to the requested prime-order subgroup.
The selected mapping depends on the configured curve suite. BLS12-381 uses the simplified Shallue–van de Woestijne map (SSWU) through an isogenous curve. BN254 Snarks uses the Shallue–van de Woestijne map (SVDW). The generic entry point selects the suite mapping and can return a Jacobian, projective, or affine point representation.
flowchart TD
A[message and suite inputs] --> B[hash-to-field]
B --> C[u0 and u1]
C --> D1[map u0 to curve point]
C --> D2[map u1 to curve point]
D1 --> E[add points]
D2 --> E
E --> F[clear cofactor]
F --> G[prime-order curve point]
An SSWU path maps through a curve that is isogenous to the target, then applies the isogeny map to the target curve. The SVDW path maps directly to the configured curve. The two mapping paths share the same hash-to-field input and subgroup step, but their curve-map rules and suite constants differ.
References: constantine/…/hash_to_curve.nim• L212-249 constantine/…/hash_to_curve.nim• L251-288 constantine/…/hash_to_curve.nim• L290-323 constantine/…/h2c_map_to_isocurve_swu.nim• L116-219
Suite inputs and downstream use
The hash-to-curve result is defined by more than the message. The hash function, security level, augmentation, DST, target field, target group, and mapping suite must agree between the producer and consumer. A change to any suite input changes the resulting point.
The main inputs have these roles:
| Input | Role |
|---|---|
| Cryptographic hash | Supplies the message expansion function. |
Security level k | Sets the amount of expanded material needed for the target security strength. |
| Augmentation | Adds protocol context before the message. BLS message augmentation uses the public key here. |
| DST | Separates one protocol suite from another. |
| Field and group | Selects the base or extension field and the target curve group. |
| Mapping suite | Selects SSWU or SVDW and its curve-specific parameters. |
BLS signature operations use hash-to-curve to turn the signed message into a point before group and pairing checks. The hash-to-curve API therefore sits between general hash functions and the elliptic-curve operations described in Elliptic curves and pairings. Its field conversion stage relies on the field operations described in Finite-field arithmetic, while its use of a cryptographic hash and domain-separated expansion is related to Randomness, KDFs, and MACs. This page is a child of Hashing and symmetric primitives.
The public BLS path passes the message, optional augmentation, and DST to hash-to-curve. It then uses the returned point as the message representative for signing or verification.
References: constantine/…/bls_signatures.nim• L60-100 constantine/…/bls_signatures.nim• L165-195
Curve mapping support
Curve mapping support supplies deterministic field-to-curve maps and the curve-specific data that makes each map match its target group. The supported paths cover BLS12-381 G1 and G2 with SSWU and BN254 Snarks G1 and G2 with SVDW.
For BLS12-381, the map uses a suitable isogenous curve because the simplified map has useful conditions on the curve equation. The map computes a point on that intermediate curve and then applies the stored isogeny to reach G1 or G2. For G2, the field input is an element of the quadratic extension field, so the map uses extension-field square-root and sign rules.
The curve constants and isogeny data are generated from curve parameters and the hash-to-curve suite rules. The generated values define the map rather than changing the message-expansion or field-conversion stages.
References: constantine/…/zoo_hash_to_curve.nim• L20-33 sage/derive_hash_to_curve.sage• L145-187 sage/derive_hash_to_curve.sage• L283-395 sage/derive_hash_to_curve.sage• L397-566
Conformance and performance checks
The hash-to-field tests compare message expansion and field outputs with published hash-to-curve vectors. The hash-to-curve tests compare complete points for several specification versions and both SSWU and SVDW paths. These checks protect the suite contract across hashing, field conversion, curve mapping, and subgroup selection.
The benchmark cases measure hash-to-G1 and hash-to-G2 operations for BLS12-381 and BN254 Snarks. They also measure the conversion of the resulting Jacobian point to affine form when a later pairing operation needs that representation.
References: tests/t_hash_to_field.nim• L17-40 tests/t_hash_to_field.nim• L146-181 tests/t_hash_to_curve.nim• L104-172 benchmarks/bench_hash_to_curve.nim• L36-124
Change checklist
When these files or sections are changed, remember to consider these:
- A change to
expandMessageXMD, DST handling, augmentation order, or output sizing must preserve the published hash-to-field and hash-to-curve suite vectors. - A change to field or extension-field conversion must preserve the byte order, reduction domain, and component order expected by each target group.
- A change to a map, isogeny, curve constant, or cofactor rule must be checked for every affected G1 and G2 suite. The selected mapping must still match the DST and suite name used by callers.
- A change to the point output representation must preserve the affine conversion expected by downstream pairing and signature paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Producer and verifier use different DSTs or suite parameters | They derive different curve points for the same message, so signature verification or another protocol check fails. | Keep the suite identifier and DST aligned across callers and test vectors. |
| An oversized DST is passed without the required short-DST step | The expanded byte stream does not follow the hash-to-curve suite rules. | Reduce oversized DSTs before message expansion. |
| Field elements are built with the wrong byte order or extension-field component order | The map receives different field values and returns a different point. | Compare hash-to-field outputs with the published vectors for the target field. |
| The cofactor step is omitted or uses the wrong target group | The point may not be in the required prime-order subgroup. | Complete hash-to-curve through subgroup clearing before exposing the point. |
| Mapping constants do not match the selected curve or group | The map can produce an invalid point or a point for a different suite. | Keep generated constants and isogeny data tied to the named curve and group. |
Key files
| File | Why to read it |
|---|---|
constantine/hash_to_curve/h2c_hash_to_field.nim | Defines message expansion, DST reduction, and conversion from uniform bytes to prime-field or extension-field elements. |
constantine/hash_to_curve/hash_to_curve.nim | Defines the composition of hash-to-field, curve mapping, point addition, subgroup clearing, and output conversion. |
constantine/hash_to_curve/h2c_map_to_isocurve_swu.nim | Shows the BLS12-381 SSWU mapping path through an isogenous curve. |
constantine/named/zoo_hash_to_curve.nim | Connects each named curve and group to its hash-to-curve constants and isogeny data. |
constantine/signatures/bls_signatures.nim | Shows how BLS signing and verification consume the hash-to-curve result. |
tests/t_hash_to_field.nim | Shows conformance checks for message expansion and hash-to-field outputs. |
tests/t_hash_to_curve.nim | Shows complete-point checks against published hash-to-curve vectors across supported mappings. |
sage/derive_hash_to_curve.sage | Explains the source of curve-map parameters and generated constants when suite data changes. |