Skip to content

Commit d588039

Browse files
committed
Export map_to_curve_elligator2_curve25519. Closes gh-211.
1 parent 48a97b7 commit d588039

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ed25519.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,14 @@ const ELL2_C1 = /* @__PURE__ */ (() => (ed25519_CURVE_p + _3n) / _8n)(); // 1. c
186186
const ELL2_C2 = /* @__PURE__ */ (() => Fp.pow(_2n, ELL2_C1))(); // 2. c2 = 2^c1
187187
const ELL2_C3 = /* @__PURE__ */ (() => Fp.sqrt(Fp.neg(Fp.ONE)))(); // 3. c3 = sqrt(-1)
188188

189+
/**
190+
* RFC 9380 method `map_to_curve_elligator2_curve25519`. Experimental name: may be renamed later.
191+
* @private
192+
*/
189193
// prettier-ignore
190-
function map_to_curve_elligator2_curve25519(u: bigint) {
194+
export function _map_to_curve_elligator2_curve25519(u: bigint): {
195+
xMn: bigint, xMd: bigint, yMn: bigint, yMd: bigint
196+
} {
191197
const ELL2_C4 = (ed25519_CURVE_p - _5n) / _8n; // 4. c4 = (q - 5) / 8 # Integer arithmetic
192198
const ELL2_J = BigInt(486662);
193199

@@ -234,7 +240,7 @@ function map_to_curve_elligator2_curve25519(u: bigint) {
234240

235241
const ELL2_C1_EDWARDS = /* @__PURE__ */ (() => FpSqrtEven(Fp, Fp.neg(BigInt(486664))))(); // sgn0(c1) MUST equal 0
236242
function map_to_curve_elligator2_edwards25519(u: bigint) {
237-
const { xMn, xMd, yMn, yMd } = map_to_curve_elligator2_curve25519(u); // 1. (xMn, xMd, yMn, yMd) =
243+
const { xMn, xMd, yMn, yMd } = _map_to_curve_elligator2_curve25519(u); // 1. (xMn, xMd, yMn, yMd) =
238244
// map_to_curve_elligator2_curve25519(u)
239245
let xn = Fp.mul(xMn, yMd); // 2. xn = xMn * yMd
240246
xn = Fp.mul(xn, ELL2_C1_EDWARDS); // 3. xn = xn * c1

0 commit comments

Comments
 (0)