@noble/curves 1.9.7 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +520 -505
- package/abstract/bls.d.ts +58 -120
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +108 -152
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +18 -54
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +30 -49
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +18 -77
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +68 -144
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.js +14 -27
- package/abstract/fft.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +35 -47
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +42 -46
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +5 -17
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +170 -169
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +7 -12
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +22 -29
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +282 -0
- package/abstract/oprf.d.ts.map +1 -0
- package/abstract/oprf.js +297 -0
- package/abstract/oprf.js.map +1 -0
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +26 -31
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +43 -19
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +77 -168
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +184 -389
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +5 -11
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +161 -181
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +59 -11
- package/bn254.d.ts.map +1 -1
- package/bn254.js +69 -97
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +33 -48
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +147 -161
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +27 -36
- package/ed448.d.ts.map +1 -1
- package/ed448.js +143 -164
- package/ed448.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -4
- package/index.js.map +1 -1
- package/misc.d.ts +10 -14
- package/misc.d.ts.map +1 -1
- package/misc.js +53 -62
- package/misc.js.map +1 -1
- package/nist.d.ts +31 -16
- package/nist.d.ts.map +1 -1
- package/nist.js +75 -64
- package/nist.js.map +1 -1
- package/package.json +20 -234
- package/secp256k1.d.ts +17 -30
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +59 -73
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +207 -354
- package/src/abstract/curve.ts +25 -84
- package/src/abstract/edwards.ts +68 -193
- package/src/abstract/hash-to-curve.ts +71 -85
- package/src/abstract/modular.ts +150 -134
- package/src/abstract/montgomery.ts +28 -35
- package/src/abstract/oprf.ts +600 -0
- package/src/abstract/poseidon.ts +6 -8
- package/src/abstract/tower.ts +0 -3
- package/src/abstract/weierstrass.ts +203 -525
- package/src/bls12-381.ts +133 -139
- package/src/bn254.ts +69 -93
- package/src/ed25519.ts +106 -133
- package/src/ed448.ts +111 -138
- package/src/index.ts +19 -3
- package/src/misc.ts +68 -51
- package/src/nist.ts +77 -70
- package/src/secp256k1.ts +46 -81
- package/src/utils.ts +67 -137
- package/src/webcrypto.ts +403 -0
- package/utils.d.ts +31 -38
- package/utils.d.ts.map +1 -1
- package/utils.js +66 -185
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +99 -0
- package/webcrypto.d.ts.map +1 -0
- package/webcrypto.js +256 -0
- package/webcrypto.js.map +1 -0
- package/_shortw_utils.d.ts +0 -19
- package/_shortw_utils.d.ts.map +0 -1
- package/_shortw_utils.js +0 -20
- package/_shortw_utils.js.map +0 -1
- package/abstract/utils.d.ts +0 -78
- package/abstract/utils.d.ts.map +0 -1
- package/abstract/utils.js +0 -73
- package/abstract/utils.js.map +0 -1
- package/esm/_shortw_utils.d.ts +0 -19
- package/esm/_shortw_utils.d.ts.map +0 -1
- package/esm/_shortw_utils.js +0 -16
- package/esm/_shortw_utils.js.map +0 -1
- package/esm/abstract/bls.d.ts +0 -190
- package/esm/abstract/bls.d.ts.map +0 -1
- package/esm/abstract/bls.js +0 -408
- package/esm/abstract/bls.js.map +0 -1
- package/esm/abstract/curve.d.ts +0 -231
- package/esm/abstract/curve.d.ts.map +0 -1
- package/esm/abstract/curve.js +0 -465
- package/esm/abstract/curve.js.map +0 -1
- package/esm/abstract/edwards.d.ts +0 -243
- package/esm/abstract/edwards.d.ts.map +0 -1
- package/esm/abstract/edwards.js +0 -627
- package/esm/abstract/edwards.js.map +0 -1
- package/esm/abstract/fft.d.ts +0 -122
- package/esm/abstract/fft.d.ts.map +0 -1
- package/esm/abstract/fft.js +0 -425
- package/esm/abstract/fft.js.map +0 -1
- package/esm/abstract/hash-to-curve.d.ts +0 -102
- package/esm/abstract/hash-to-curve.d.ts.map +0 -1
- package/esm/abstract/hash-to-curve.js +0 -203
- package/esm/abstract/hash-to-curve.js.map +0 -1
- package/esm/abstract/modular.d.ts +0 -171
- package/esm/abstract/modular.d.ts.map +0 -1
- package/esm/abstract/modular.js +0 -530
- package/esm/abstract/modular.js.map +0 -1
- package/esm/abstract/montgomery.d.ts +0 -30
- package/esm/abstract/montgomery.d.ts.map +0 -1
- package/esm/abstract/montgomery.js +0 -157
- package/esm/abstract/montgomery.js.map +0 -1
- package/esm/abstract/poseidon.d.ts +0 -68
- package/esm/abstract/poseidon.d.ts.map +0 -1
- package/esm/abstract/poseidon.js +0 -296
- package/esm/abstract/poseidon.js.map +0 -1
- package/esm/abstract/tower.d.ts +0 -95
- package/esm/abstract/tower.d.ts.map +0 -1
- package/esm/abstract/tower.js +0 -714
- package/esm/abstract/tower.js.map +0 -1
- package/esm/abstract/utils.d.ts +0 -78
- package/esm/abstract/utils.d.ts.map +0 -1
- package/esm/abstract/utils.js +0 -70
- package/esm/abstract/utils.js.map +0 -1
- package/esm/abstract/weierstrass.d.ts +0 -416
- package/esm/abstract/weierstrass.d.ts.map +0 -1
- package/esm/abstract/weierstrass.js +0 -1413
- package/esm/abstract/weierstrass.js.map +0 -1
- package/esm/bls12-381.d.ts +0 -16
- package/esm/bls12-381.d.ts.map +0 -1
- package/esm/bls12-381.js +0 -705
- package/esm/bls12-381.js.map +0 -1
- package/esm/bn254.d.ts +0 -18
- package/esm/bn254.d.ts.map +0 -1
- package/esm/bn254.js +0 -214
- package/esm/bn254.js.map +0 -1
- package/esm/ed25519.d.ts +0 -106
- package/esm/ed25519.d.ts.map +0 -1
- package/esm/ed25519.js +0 -467
- package/esm/ed25519.js.map +0 -1
- package/esm/ed448.d.ts +0 -100
- package/esm/ed448.d.ts.map +0 -1
- package/esm/ed448.js +0 -459
- package/esm/ed448.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -17
- package/esm/index.js.map +0 -1
- package/esm/jubjub.d.ts +0 -12
- package/esm/jubjub.d.ts.map +0 -1
- package/esm/jubjub.js +0 -12
- package/esm/jubjub.js.map +0 -1
- package/esm/misc.d.ts +0 -19
- package/esm/misc.d.ts.map +0 -1
- package/esm/misc.js +0 -109
- package/esm/misc.js.map +0 -1
- package/esm/nist.d.ts +0 -21
- package/esm/nist.d.ts.map +0 -1
- package/esm/nist.js +0 -132
- package/esm/nist.js.map +0 -1
- package/esm/p256.d.ts +0 -16
- package/esm/p256.d.ts.map +0 -1
- package/esm/p256.js +0 -16
- package/esm/p256.js.map +0 -1
- package/esm/p384.d.ts +0 -16
- package/esm/p384.d.ts.map +0 -1
- package/esm/p384.js +0 -16
- package/esm/p384.js.map +0 -1
- package/esm/p521.d.ts +0 -16
- package/esm/p521.d.ts.map +0 -1
- package/esm/p521.js +0 -16
- package/esm/p521.js.map +0 -1
- package/esm/package.json +0 -4
- package/esm/pasta.d.ts +0 -10
- package/esm/pasta.d.ts.map +0 -1
- package/esm/pasta.js +0 -10
- package/esm/pasta.js.map +0 -1
- package/esm/secp256k1.d.ts +0 -89
- package/esm/secp256k1.d.ts.map +0 -1
- package/esm/secp256k1.js +0 -294
- package/esm/secp256k1.js.map +0 -1
- package/esm/utils.d.ts +0 -110
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -322
- package/esm/utils.js.map +0 -1
- package/jubjub.d.ts +0 -12
- package/jubjub.d.ts.map +0 -1
- package/jubjub.js +0 -15
- package/jubjub.js.map +0 -1
- package/p256.d.ts +0 -16
- package/p256.d.ts.map +0 -1
- package/p256.js +0 -13
- package/p256.js.map +0 -1
- package/p384.d.ts +0 -16
- package/p384.d.ts.map +0 -1
- package/p384.js +0 -13
- package/p384.js.map +0 -1
- package/p521.d.ts +0 -16
- package/p521.d.ts.map +0 -1
- package/p521.js +0 -13
- package/p521.js.map +0 -1
- package/pasta.d.ts +0 -10
- package/pasta.d.ts.map +0 -1
- package/pasta.js +0 -13
- package/pasta.js.map +0 -1
- package/src/_shortw_utils.ts +0 -21
- package/src/abstract/utils.ts +0 -80
- package/src/jubjub.ts +0 -12
- package/src/p256.ts +0 -15
- package/src/p384.ts +0 -15
- package/src/p521.ts +0 -15
- package/src/package.json +0 -3
- package/src/pasta.ts +0 -9
package/ed448.d.ts
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
1
|
import type { AffinePoint } from './abstract/curve.ts';
|
|
2
|
-
import { PrimeEdwardsPoint, type
|
|
3
|
-
import { type H2CHasher, type H2CHasherBase
|
|
2
|
+
import { PrimeEdwardsPoint, type EdDSA, type EdwardsPoint, type EdwardsPointCons } from './abstract/edwards.ts';
|
|
3
|
+
import { type H2CHasher, type H2CHasherBase } from './abstract/hash-to-curve.ts';
|
|
4
4
|
import { type IField } from './abstract/modular.ts';
|
|
5
|
-
import { type MontgomeryECDH
|
|
6
|
-
import { type
|
|
5
|
+
import { type MontgomeryECDH } from './abstract/montgomery.ts';
|
|
6
|
+
import { type OPRF } from './abstract/oprf.ts';
|
|
7
7
|
/**
|
|
8
8
|
* ed448 EdDSA curve and methods.
|
|
9
9
|
* @example
|
|
10
|
-
*
|
|
10
|
+
* ```js
|
|
11
|
+
* import { ed448 } from '@noble/curves/ed448.js';
|
|
11
12
|
* const { secretKey, publicKey } = ed448.keygen();
|
|
12
|
-
* const
|
|
13
|
+
* // const publicKey = ed448.getPublicKey(secretKey);
|
|
14
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
13
15
|
* const sig = ed448.sign(msg, secretKey);
|
|
14
16
|
* const isValid = ed448.verify(sig, msg, publicKey);
|
|
17
|
+
* ```
|
|
15
18
|
*/
|
|
16
|
-
export declare const ed448:
|
|
17
|
-
/** Prehashed version of ed448.
|
|
18
|
-
export declare const ed448ph:
|
|
19
|
+
export declare const ed448: EdDSA;
|
|
20
|
+
/** Prehashed version of ed448. See {@link ed448} */
|
|
21
|
+
export declare const ed448ph: EdDSA;
|
|
19
22
|
/**
|
|
20
|
-
* E448
|
|
21
|
-
* E448 != edwards448 used in ed448.
|
|
23
|
+
* E448 (NIST) != edwards448 used in ed448.
|
|
22
24
|
* E448 is birationally equivalent to edwards448.
|
|
23
25
|
*/
|
|
24
26
|
export declare const E448: EdwardsPointCons;
|
|
25
27
|
/**
|
|
26
28
|
* ECDH using curve448 aka x448.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* import { x448 } from '@noble/curves/ed448.js';
|
|
33
|
+
* const alice = x448.keygen();
|
|
34
|
+
* const bob = x448.keygen();
|
|
35
|
+
* const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
|
|
36
|
+
* ```
|
|
29
37
|
*/
|
|
30
|
-
export declare const x448:
|
|
38
|
+
export declare const x448: MontgomeryECDH;
|
|
31
39
|
/** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
|
|
32
|
-
export declare const ed448_hasher: H2CHasher<
|
|
40
|
+
export declare const ed448_hasher: H2CHasher<EdwardsPointCons>;
|
|
33
41
|
/**
|
|
34
42
|
* Each ed448/EdwardsPoint has 4 different equivalent points. This can be
|
|
35
43
|
* a source of bugs for protocols like ring signatures. Decaf was created to solve this.
|
|
@@ -46,17 +54,13 @@ declare class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
46
54
|
static fromAffine(ap: AffinePoint<bigint>): _DecafPoint;
|
|
47
55
|
protected assertSame(other: _DecafPoint): void;
|
|
48
56
|
protected init(ep: EdwardsPoint): _DecafPoint;
|
|
49
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
50
|
-
static hashToCurve(hex: Hex): _DecafPoint;
|
|
51
57
|
static fromBytes(bytes: Uint8Array): _DecafPoint;
|
|
52
58
|
/**
|
|
53
59
|
* Converts decaf-encoded string to decaf point.
|
|
54
60
|
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
|
|
55
61
|
* @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
|
|
56
62
|
*/
|
|
57
|
-
static fromHex(hex:
|
|
58
|
-
/** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
|
|
59
|
-
static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint;
|
|
63
|
+
static fromHex(hex: string): _DecafPoint;
|
|
60
64
|
/**
|
|
61
65
|
* Encodes decaf point to Uint8Array.
|
|
62
66
|
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
|
|
@@ -73,7 +77,9 @@ export declare const decaf448: {
|
|
|
73
77
|
Point: typeof _DecafPoint;
|
|
74
78
|
};
|
|
75
79
|
/** Hashing to decaf448 points / field. RFC 9380 methods. */
|
|
76
|
-
export declare const decaf448_hasher: H2CHasherBase<
|
|
80
|
+
export declare const decaf448_hasher: H2CHasherBase<typeof _DecafPoint>;
|
|
81
|
+
/** decaf448 OPRF, defined in RFC 9497. */
|
|
82
|
+
export declare const decaf448_oprf: OPRF;
|
|
77
83
|
/**
|
|
78
84
|
* Weird / bogus points, useful for debugging.
|
|
79
85
|
* Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
|
|
@@ -81,20 +87,5 @@ export declare const decaf448_hasher: H2CHasherBase<bigint>;
|
|
|
81
87
|
* (0, 1), (0, -1), (-1, 0), (1, 0).
|
|
82
88
|
*/
|
|
83
89
|
export declare const ED448_TORSION_SUBGROUP: string[];
|
|
84
|
-
type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
|
|
85
|
-
/** @deprecated use `decaf448.Point` */
|
|
86
|
-
export declare const DecafPoint: typeof _DecafPoint;
|
|
87
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
88
|
-
export declare const hashToCurve: H2CMethod<bigint>;
|
|
89
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
90
|
-
export declare const encodeToCurve: H2CMethod<bigint>;
|
|
91
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
92
|
-
export declare const hashToDecaf448: DcfHasher;
|
|
93
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
94
|
-
export declare const hash_to_decaf448: DcfHasher;
|
|
95
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
96
|
-
export declare function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array;
|
|
97
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
98
|
-
export declare const edwardsToMontgomery: typeof edwardsToMontgomeryPub;
|
|
99
90
|
export {};
|
|
100
91
|
//# sourceMappingURL=ed448.d.ts.map
|
package/ed448.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed448.d.ts","sourceRoot":"","sources":["src/ed448.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ed448.d.ts","sourceRoot":"","sources":["src/ed448.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAGL,iBAAiB,EACjB,KAAK,KAAK,EAGV,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAiD,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAoI3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,EAAE,KAA+B,CAAC;AAGpD,oDAAoD;AACpD,eAAO,MAAM,OAAO,EAAE,KAAqD,CAAC;AAC5E;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,gBAAsD,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,EAAE,cAYf,CAAC;AA+EL,oEAAoE;AACpE,eAAO,MAAM,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAS9C,CAAC;AAkDR;;;;;;GAMG;AACH,cAAM,WAAY,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IAGtD,MAAM,CAAC,IAAI,EAAE,WAAW,CAC0D;IAElF,MAAM,CAAC,IAAI,EAAE,WAAW,CACsC;IAE9D,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CACS;IAElC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CACS;gBAEtB,EAAE,EAAE,YAAY;IAI5B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW;IAIvD,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAI9C,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,GAAG,WAAW;IAI7C,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW;IA6BhD;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;IAIxC;;;OAGG;IACH,OAAO,IAAI,UAAU;IAerB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAQnC,GAAG,IAAI,OAAO;CAGf;AAED,eAAO,MAAM,QAAQ,EAAE;IACrB,KAAK,EAAE,OAAO,WAAW,CAAC;CACF,CAAC;AAE3B,4DAA4D;AAC5D,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,OAAO,WAAW,CAmC7D,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,aAAa,EAAE,IAOrB,CAAC;AAER;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAK1C,CAAC"}
|
package/ed448.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.edwardsToMontgomery = exports.hash_to_decaf448 = exports.hashToDecaf448 = exports.encodeToCurve = exports.hashToCurve = exports.DecafPoint = exports.ED448_TORSION_SUBGROUP = exports.decaf448_hasher = exports.decaf448 = exports.ed448_hasher = exports.x448 = exports.E448 = exports.ed448ph = exports.ed448 = void 0;
|
|
4
|
-
exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
|
5
1
|
/**
|
|
6
2
|
* Edwards448 (not Ed448-Goldilocks) curve with following addons:
|
|
7
3
|
* - X448 ECDH
|
|
@@ -11,61 +7,62 @@ exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
|
|
11
7
|
* @module
|
|
12
8
|
*/
|
|
13
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
import { shake256 } from '@noble/hashes/sha3.js';
|
|
11
|
+
import { concatBytes, hexToBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
|
|
12
|
+
import { eddsa, edwards, PrimeEdwardsPoint, } from "./abstract/edwards.js";
|
|
13
|
+
import { _DST_scalar, createHasher, expand_message_xof, } from "./abstract/hash-to-curve.js";
|
|
14
|
+
import { Field, FpInvertBatch, isNegativeLE, mod, pow2 } from "./abstract/modular.js";
|
|
15
|
+
import { montgomery } from "./abstract/montgomery.js";
|
|
16
|
+
import { createORPF } from "./abstract/oprf.js";
|
|
17
|
+
import { abytes, asciiToBytes, bytesToNumberLE, equalBytes } from "./utils.js";
|
|
22
18
|
// edwards448 curve
|
|
23
19
|
// a = 1n
|
|
24
20
|
// d = Fp.neg(39081n)
|
|
25
21
|
// Finite field 2n**448n - 2n**224n - 1n
|
|
26
22
|
// Subgroup order
|
|
27
23
|
// 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
|
|
28
|
-
const
|
|
29
|
-
|
|
24
|
+
const ed448_CURVE_p = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
25
|
+
const ed448_CURVE = /* @__PURE__ */ (() => ({
|
|
26
|
+
p: ed448_CURVE_p,
|
|
30
27
|
n: BigInt('0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'),
|
|
31
28
|
h: BigInt(4),
|
|
32
29
|
a: BigInt(1),
|
|
33
30
|
d: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffff6756'),
|
|
34
31
|
Gx: BigInt('0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'),
|
|
35
32
|
Gy: BigInt('0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'),
|
|
36
|
-
};
|
|
33
|
+
}))();
|
|
37
34
|
// E448 NIST curve is identical to edwards448, except for:
|
|
38
35
|
// d = 39082/39081
|
|
39
36
|
// Gx = 3/2
|
|
40
|
-
const E448_CURVE = Object.assign({}, ed448_CURVE, {
|
|
37
|
+
const E448_CURVE = /* @__PURE__ */ (() => Object.assign({}, ed448_CURVE, {
|
|
41
38
|
d: BigInt('0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'),
|
|
42
39
|
Gx: BigInt('0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'),
|
|
43
40
|
Gy: BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'),
|
|
44
|
-
});
|
|
45
|
-
const shake256_114 = /* @__PURE__ */ (
|
|
46
|
-
const shake256_64 = /* @__PURE__ */ (
|
|
41
|
+
}))();
|
|
42
|
+
const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
|
|
43
|
+
const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
|
|
47
44
|
// prettier-ignore
|
|
48
|
-
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
|
|
45
|
+
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _11n = BigInt(11);
|
|
49
46
|
// prettier-ignore
|
|
50
47
|
const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
|
|
51
48
|
// powPminus3div4 calculates z = x^k mod p, where k = (p-3)/4.
|
|
52
49
|
// Used for efficient square root calculation.
|
|
53
50
|
// ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
|
|
54
51
|
function ed448_pow_Pminus3div4(x) {
|
|
55
|
-
const P =
|
|
52
|
+
const P = ed448_CURVE_p;
|
|
56
53
|
const b2 = (x * x * x) % P;
|
|
57
54
|
const b3 = (b2 * b2 * x) % P;
|
|
58
|
-
const b6 = (
|
|
59
|
-
const b9 = (
|
|
60
|
-
const b11 = (
|
|
61
|
-
const b22 = (
|
|
62
|
-
const b44 = (
|
|
63
|
-
const b88 = (
|
|
64
|
-
const b176 = (
|
|
65
|
-
const b220 = (
|
|
66
|
-
const b222 = (
|
|
67
|
-
const b223 = (
|
|
68
|
-
return (
|
|
55
|
+
const b6 = (pow2(b3, _3n, P) * b3) % P;
|
|
56
|
+
const b9 = (pow2(b6, _3n, P) * b3) % P;
|
|
57
|
+
const b11 = (pow2(b9, _2n, P) * b2) % P;
|
|
58
|
+
const b22 = (pow2(b11, _11n, P) * b11) % P;
|
|
59
|
+
const b44 = (pow2(b22, _22n, P) * b22) % P;
|
|
60
|
+
const b88 = (pow2(b44, _44n, P) * b44) % P;
|
|
61
|
+
const b176 = (pow2(b88, _88n, P) * b88) % P;
|
|
62
|
+
const b220 = (pow2(b176, _44n, P) * b44) % P;
|
|
63
|
+
const b222 = (pow2(b220, _2n, P) * b2) % P;
|
|
64
|
+
const b223 = (pow2(b222, _1n, P) * x) % P;
|
|
65
|
+
return (pow2(b223, _223n, P) * b222) % P;
|
|
69
66
|
}
|
|
70
67
|
function adjustScalarBytes(bytes) {
|
|
71
68
|
// Section 5: Likewise, for X448, set the two least significant bits of the first byte to 0,
|
|
@@ -79,93 +76,90 @@ function adjustScalarBytes(bytes) {
|
|
|
79
76
|
// Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
|
|
80
77
|
// Uses algo from RFC8032 5.1.3.
|
|
81
78
|
function uvRatio(u, v) {
|
|
82
|
-
const P =
|
|
79
|
+
const P = ed448_CURVE_p;
|
|
83
80
|
// https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
|
|
84
81
|
// To compute the square root of (u/v), the first step is to compute the
|
|
85
82
|
// candidate root x = (u/v)^((p+1)/4). This can be done using the
|
|
86
83
|
// following trick, to use a single modular powering for both the
|
|
87
84
|
// inversion of v and the square root:
|
|
88
85
|
// x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
|
|
89
|
-
const u2v =
|
|
90
|
-
const u3v =
|
|
91
|
-
const u5v3 =
|
|
86
|
+
const u2v = mod(u * u * v, P); // u²v
|
|
87
|
+
const u3v = mod(u2v * u, P); // u³v
|
|
88
|
+
const u5v3 = mod(u3v * u2v * v, P); // u⁵v³
|
|
92
89
|
const root = ed448_pow_Pminus3div4(u5v3);
|
|
93
|
-
const x =
|
|
90
|
+
const x = mod(u3v * root, P);
|
|
94
91
|
// Verify that root is exists
|
|
95
|
-
const x2 =
|
|
92
|
+
const x2 = mod(x * x, P); // x²
|
|
96
93
|
// If vx² = u, the recovered x-coordinate is x. Otherwise, no
|
|
97
94
|
// square root exists, and the decoding fails.
|
|
98
|
-
return { isValid:
|
|
95
|
+
return { isValid: mod(x2 * v, P) === u, value: x };
|
|
99
96
|
}
|
|
100
97
|
// Finite field 2n**448n - 2n**224n - 1n
|
|
101
98
|
// The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
|
|
102
99
|
// - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
|
|
103
100
|
// - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
|
|
104
|
-
const Fp = /* @__PURE__ */ (() =>
|
|
105
|
-
const Fn = /* @__PURE__ */ (() =>
|
|
101
|
+
const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 456, isLE: true }))();
|
|
102
|
+
const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
|
|
106
103
|
// decaf448 uses 448-bit (56-byte) keys
|
|
107
|
-
const Fp448 = /* @__PURE__ */ (() =>
|
|
108
|
-
const Fn448 = /* @__PURE__ */ (() =>
|
|
104
|
+
const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 448, isLE: true }))();
|
|
105
|
+
const Fn448 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
|
|
109
106
|
// SHAKE256(dom4(phflag,context)||x, 114)
|
|
110
107
|
function dom4(data, ctx, phflag) {
|
|
111
108
|
if (ctx.length > 255)
|
|
112
109
|
throw new Error('context must be smaller than 255, got: ' + ctx.length);
|
|
113
|
-
return
|
|
110
|
+
return concatBytes(asciiToBytes('SigEd448'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
|
|
111
|
+
}
|
|
112
|
+
const ed448_Point = /* @__PURE__ */ edwards(ed448_CURVE, { Fp, Fn, uvRatio });
|
|
113
|
+
function ed4(opts) {
|
|
114
|
+
return eddsa(ed448_Point, shake256_114, Object.assign({ adjustScalarBytes, domain: dom4 }, opts));
|
|
114
115
|
}
|
|
115
|
-
// const ed448_eddsa_opts = { adjustScalarBytes, domain: dom4 };
|
|
116
|
-
// const ed448_Point = edwards(ed448_CURVE, { Fp, Fn, uvRatio });
|
|
117
|
-
const ED448_DEF = /* @__PURE__ */ (() => ({
|
|
118
|
-
...ed448_CURVE,
|
|
119
|
-
Fp,
|
|
120
|
-
Fn,
|
|
121
|
-
nBitLength: Fn.BITS,
|
|
122
|
-
hash: shake256_114,
|
|
123
|
-
adjustScalarBytes,
|
|
124
|
-
domain: dom4,
|
|
125
|
-
uvRatio,
|
|
126
|
-
}))();
|
|
127
116
|
/**
|
|
128
117
|
* ed448 EdDSA curve and methods.
|
|
129
118
|
* @example
|
|
130
|
-
*
|
|
119
|
+
* ```js
|
|
120
|
+
* import { ed448 } from '@noble/curves/ed448.js';
|
|
131
121
|
* const { secretKey, publicKey } = ed448.keygen();
|
|
132
|
-
* const
|
|
122
|
+
* // const publicKey = ed448.getPublicKey(secretKey);
|
|
123
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
133
124
|
* const sig = ed448.sign(msg, secretKey);
|
|
134
125
|
* const isValid = ed448.verify(sig, msg, publicKey);
|
|
126
|
+
* ```
|
|
135
127
|
*/
|
|
136
|
-
|
|
128
|
+
export const ed448 = /* @__PURE__ */ ed4({});
|
|
137
129
|
// There is no ed448ctx, since ed448 supports ctx by default
|
|
138
|
-
/** Prehashed version of ed448.
|
|
139
|
-
|
|
140
|
-
...ED448_DEF,
|
|
141
|
-
prehash: shake256_64,
|
|
142
|
-
}))();
|
|
130
|
+
/** Prehashed version of ed448. See {@link ed448} */
|
|
131
|
+
export const ed448ph = /* @__PURE__ */ ed4({ prehash: shake256_64 });
|
|
143
132
|
/**
|
|
144
|
-
* E448
|
|
145
|
-
* E448 != edwards448 used in ed448.
|
|
133
|
+
* E448 (NIST) != edwards448 used in ed448.
|
|
146
134
|
* E448 is birationally equivalent to edwards448.
|
|
147
135
|
*/
|
|
148
|
-
|
|
136
|
+
export const E448 = /* @__PURE__ */ edwards(E448_CURVE);
|
|
149
137
|
/**
|
|
150
138
|
* ECDH using curve448 aka x448.
|
|
151
|
-
*
|
|
152
|
-
*
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```js
|
|
142
|
+
* import { x448 } from '@noble/curves/ed448.js';
|
|
143
|
+
* const alice = x448.keygen();
|
|
144
|
+
* const bob = x448.keygen();
|
|
145
|
+
* const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
|
|
146
|
+
* ```
|
|
153
147
|
*/
|
|
154
|
-
|
|
155
|
-
const P =
|
|
156
|
-
return
|
|
148
|
+
export const x448 = /* @__PURE__ */ (() => {
|
|
149
|
+
const P = ed448_CURVE_p;
|
|
150
|
+
return montgomery({
|
|
157
151
|
P,
|
|
158
152
|
type: 'x448',
|
|
159
153
|
powPminus2: (x) => {
|
|
160
154
|
const Pminus3div4 = ed448_pow_Pminus3div4(x);
|
|
161
|
-
const Pminus3 =
|
|
162
|
-
return
|
|
155
|
+
const Pminus3 = pow2(Pminus3div4, _2n, P);
|
|
156
|
+
return mod(Pminus3 * x, P); // Pminus3 * x = Pminus2
|
|
163
157
|
},
|
|
164
158
|
adjustScalarBytes,
|
|
165
159
|
});
|
|
166
160
|
})();
|
|
167
161
|
// Hash To Curve Elligator2 Map
|
|
168
|
-
const ELL2_C1 = /* @__PURE__ */ (() => (
|
|
162
|
+
const ELL2_C1 = /* @__PURE__ */ (() => (ed448_CURVE_p - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
|
|
169
163
|
const ELL2_J = /* @__PURE__ */ BigInt(156326);
|
|
170
164
|
function map_to_curve_elligator2_curve448(u) {
|
|
171
165
|
let tv1 = Fp.sqr(u); // 1. tv1 = u^2
|
|
@@ -234,18 +228,18 @@ function map_to_curve_elligator2_edwards448(u) {
|
|
|
234
228
|
xEd = Fp.cmov(xEd, Fp.ONE, e); // 35. xEd = CMOV(xEd, 1, e)
|
|
235
229
|
yEn = Fp.cmov(yEn, Fp.ONE, e); // 36. yEn = CMOV(yEn, 1, e)
|
|
236
230
|
yEd = Fp.cmov(yEd, Fp.ONE, e); // 37. yEd = CMOV(yEd, 1, e)
|
|
237
|
-
const inv =
|
|
231
|
+
const inv = FpInvertBatch(Fp, [xEd, yEd], true); // batch division
|
|
238
232
|
return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
|
|
239
233
|
}
|
|
240
234
|
/** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
|
|
241
|
-
|
|
235
|
+
export const ed448_hasher = /* @__PURE__ */ (() => createHasher(ed448_Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
|
|
242
236
|
DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
|
|
243
237
|
encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
|
|
244
|
-
p:
|
|
238
|
+
p: ed448_CURVE_p,
|
|
245
239
|
m: 1,
|
|
246
240
|
k: 224,
|
|
247
241
|
expand: 'xof',
|
|
248
|
-
hash:
|
|
242
|
+
hash: shake256,
|
|
249
243
|
}))();
|
|
250
244
|
// 1-d
|
|
251
245
|
const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
|
|
@@ -263,9 +257,8 @@ const invertSqrt = (number) => uvRatio(_1n, number);
|
|
|
263
257
|
* and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
|
|
264
258
|
*/
|
|
265
259
|
function calcElligatorDecafMap(r0) {
|
|
266
|
-
const { d } = ed448_CURVE;
|
|
267
|
-
const
|
|
268
|
-
const mod = (n) => Fp.create(n);
|
|
260
|
+
const { d, p: P } = ed448_CURVE;
|
|
261
|
+
const mod = (n) => Fp448.create(n);
|
|
269
262
|
const r = mod(-(r0 * r0)); // 1
|
|
270
263
|
const u0 = mod(d * (r - _1n)); // 2
|
|
271
264
|
const u1 = mod((u0 + _1n) * (u0 - r)); // 3
|
|
@@ -278,26 +271,14 @@ function calcElligatorDecafMap(r0) {
|
|
|
278
271
|
sgn = mod(-_1n);
|
|
279
272
|
const s = mod(v_prime * (r + _1n)); // 7
|
|
280
273
|
let s_abs = s;
|
|
281
|
-
if (
|
|
274
|
+
if (isNegativeLE(s, P))
|
|
282
275
|
s_abs = mod(-s);
|
|
283
276
|
const s2 = s * s;
|
|
284
277
|
const W0 = mod(s_abs * _2n); // 8
|
|
285
278
|
const W1 = mod(s2 + _1n); // 9
|
|
286
279
|
const W2 = mod(s2 - _1n); // 10
|
|
287
280
|
const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
|
|
288
|
-
return new
|
|
289
|
-
}
|
|
290
|
-
function decaf448_map(bytes) {
|
|
291
|
-
(0, utils_js_1.abytes)(bytes, 112);
|
|
292
|
-
const skipValidation = true;
|
|
293
|
-
// Note: Similar to the field element decoding described in
|
|
294
|
-
// [RFC7748], and unlike the field element decoding described in
|
|
295
|
-
// Section 5.3.1, non-canonical values are accepted.
|
|
296
|
-
const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
|
|
297
|
-
const R1 = calcElligatorDecafMap(r1);
|
|
298
|
-
const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
|
|
299
|
-
const R2 = calcElligatorDecafMap(r2);
|
|
300
|
-
return new _DecafPoint(R1.add(R2));
|
|
281
|
+
return new ed448_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
|
|
301
282
|
}
|
|
302
283
|
/**
|
|
303
284
|
* Each ed448/EdwardsPoint has 4 different equivalent points. This can be
|
|
@@ -306,12 +287,25 @@ function decaf448_map(bytes) {
|
|
|
306
287
|
* but it should work in its own namespace: do not combine those two.
|
|
307
288
|
* See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
|
|
308
289
|
*/
|
|
309
|
-
class _DecafPoint extends
|
|
290
|
+
class _DecafPoint extends PrimeEdwardsPoint {
|
|
291
|
+
// The following gymnastics is done because typescript strips comments otherwise
|
|
292
|
+
// prettier-ignore
|
|
293
|
+
static BASE =
|
|
294
|
+
/* @__PURE__ */ (() => new _DecafPoint(ed448_Point.BASE).multiplyUnsafe(_2n))();
|
|
295
|
+
// prettier-ignore
|
|
296
|
+
static ZERO =
|
|
297
|
+
/* @__PURE__ */ (() => new _DecafPoint(ed448_Point.ZERO))();
|
|
298
|
+
// prettier-ignore
|
|
299
|
+
static Fp =
|
|
300
|
+
/* @__PURE__ */ (() => Fp448)();
|
|
301
|
+
// prettier-ignore
|
|
302
|
+
static Fn =
|
|
303
|
+
/* @__PURE__ */ (() => Fn448)();
|
|
310
304
|
constructor(ep) {
|
|
311
305
|
super(ep);
|
|
312
306
|
}
|
|
313
307
|
static fromAffine(ap) {
|
|
314
|
-
return new _DecafPoint(
|
|
308
|
+
return new _DecafPoint(ed448_Point.fromAffine(ap));
|
|
315
309
|
}
|
|
316
310
|
assertSame(other) {
|
|
317
311
|
if (!(other instanceof _DecafPoint))
|
|
@@ -320,19 +314,14 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
|
|
|
320
314
|
init(ep) {
|
|
321
315
|
return new _DecafPoint(ep);
|
|
322
316
|
}
|
|
323
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
324
|
-
static hashToCurve(hex) {
|
|
325
|
-
return decaf448_map((0, utils_ts_1.ensureBytes)('decafHash', hex, 112));
|
|
326
|
-
}
|
|
327
317
|
static fromBytes(bytes) {
|
|
328
|
-
|
|
329
|
-
const { d } = ed448_CURVE;
|
|
330
|
-
const P = Fp.ORDER;
|
|
318
|
+
abytes(bytes, 56);
|
|
319
|
+
const { d, p: P } = ed448_CURVE;
|
|
331
320
|
const mod = (n) => Fp448.create(n);
|
|
332
321
|
const s = Fp448.fromBytes(bytes);
|
|
333
322
|
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
|
334
323
|
// 2. Check that s is non-negative, or else abort
|
|
335
|
-
if (!
|
|
324
|
+
if (!equalBytes(Fn448.toBytes(s), bytes) || isNegativeLE(s, P))
|
|
336
325
|
throw new Error('invalid decaf448 encoding 1');
|
|
337
326
|
const s2 = mod(s * s); // 1
|
|
338
327
|
const u1 = mod(_1n + s2); // 2
|
|
@@ -340,14 +329,14 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
|
|
|
340
329
|
const u2 = mod(u1sq - _4n * d * s2); // 3
|
|
341
330
|
const { isValid, value: invsqrt } = invertSqrt(mod(u2 * u1sq)); // 4
|
|
342
331
|
let u3 = mod((s + s) * invsqrt * u1 * SQRT_MINUS_D); // 5
|
|
343
|
-
if (
|
|
332
|
+
if (isNegativeLE(u3, P))
|
|
344
333
|
u3 = mod(-u3);
|
|
345
334
|
const x = mod(u3 * invsqrt * u2 * INVSQRT_MINUS_D); // 6
|
|
346
335
|
const y = mod((_1n - s2) * invsqrt * u1); // 7
|
|
347
336
|
const t = mod(x * y); // 8
|
|
348
337
|
if (!isValid)
|
|
349
338
|
throw new Error('invalid decaf448 encoding 2');
|
|
350
|
-
return new _DecafPoint(new
|
|
339
|
+
return new _DecafPoint(new ed448_Point(x, y, _1n, t));
|
|
351
340
|
}
|
|
352
341
|
/**
|
|
353
342
|
* Converts decaf-encoded string to decaf point.
|
|
@@ -355,11 +344,7 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
|
|
|
355
344
|
* @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
|
|
356
345
|
*/
|
|
357
346
|
static fromHex(hex) {
|
|
358
|
-
return _DecafPoint.fromBytes((
|
|
359
|
-
}
|
|
360
|
-
/** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
|
|
361
|
-
static msm(points, scalars) {
|
|
362
|
-
return (0, curve_ts_1.pippenger)(_DecafPoint, Fn, points, scalars);
|
|
347
|
+
return _DecafPoint.fromBytes(hexToBytes(hex));
|
|
363
348
|
}
|
|
364
349
|
/**
|
|
365
350
|
* Encodes decaf point to Uint8Array.
|
|
@@ -367,17 +352,17 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
|
|
|
367
352
|
*/
|
|
368
353
|
toBytes() {
|
|
369
354
|
const { X, Z, T } = this.ep;
|
|
370
|
-
const P =
|
|
371
|
-
const mod = (n) =>
|
|
355
|
+
const P = ed448_CURVE.p;
|
|
356
|
+
const mod = (n) => Fp448.create(n);
|
|
372
357
|
const u1 = mod(mod(X + T) * mod(X - T)); // 1
|
|
373
358
|
const x2 = mod(X * X);
|
|
374
359
|
const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
|
|
375
360
|
let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
|
|
376
|
-
if (
|
|
361
|
+
if (isNegativeLE(ratio, P))
|
|
377
362
|
ratio = mod(-ratio);
|
|
378
363
|
const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
|
|
379
364
|
let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
|
|
380
|
-
if (
|
|
365
|
+
if (isNegativeLE(s, P))
|
|
381
366
|
s = mod(-s);
|
|
382
367
|
return Fn448.toBytes(s);
|
|
383
368
|
}
|
|
@@ -390,74 +375,68 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
|
|
|
390
375
|
const { X: X1, Y: Y1 } = this.ep;
|
|
391
376
|
const { X: X2, Y: Y2 } = other.ep;
|
|
392
377
|
// (x1 * y2 == y1 * x2)
|
|
393
|
-
return
|
|
378
|
+
return Fp448.create(X1 * Y2) === Fp448.create(Y1 * X2);
|
|
394
379
|
}
|
|
395
380
|
is0() {
|
|
396
381
|
return this.equals(_DecafPoint.ZERO);
|
|
397
382
|
}
|
|
398
383
|
}
|
|
399
|
-
|
|
400
|
-
// prettier-ignore
|
|
401
|
-
_DecafPoint.BASE =
|
|
402
|
-
/* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.BASE).multiplyUnsafe(_2n))();
|
|
403
|
-
// prettier-ignore
|
|
404
|
-
_DecafPoint.ZERO =
|
|
405
|
-
/* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.ZERO))();
|
|
406
|
-
// prettier-ignore
|
|
407
|
-
_DecafPoint.Fp =
|
|
408
|
-
/* @__PURE__ */ (() => Fp448)();
|
|
409
|
-
// prettier-ignore
|
|
410
|
-
_DecafPoint.Fn =
|
|
411
|
-
/* @__PURE__ */ (() => Fn448)();
|
|
412
|
-
exports.decaf448 = { Point: _DecafPoint };
|
|
384
|
+
export const decaf448 = { Point: _DecafPoint };
|
|
413
385
|
/** Hashing to decaf448 points / field. RFC 9380 methods. */
|
|
414
|
-
|
|
386
|
+
export const decaf448_hasher = {
|
|
387
|
+
Point: _DecafPoint,
|
|
415
388
|
hashToCurve(msg, options) {
|
|
416
389
|
const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
|
|
417
|
-
return
|
|
390
|
+
return decaf448_hasher.deriveToCurve(expand_message_xof(msg, DST, 112, 224, shake256));
|
|
418
391
|
},
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Warning: has big modulo bias of 2^-64.
|
|
394
|
+
* RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
|
|
395
|
+
* it must use 84-byte xof (56+56/2), not 64.
|
|
396
|
+
*/
|
|
397
|
+
hashToScalar(msg, options = { DST: _DST_scalar }) {
|
|
423
398
|
// Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
|
|
424
|
-
const xof =
|
|
425
|
-
return Fn448.create(
|
|
399
|
+
const xof = expand_message_xof(msg, options.DST, 64, 256, shake256);
|
|
400
|
+
return Fn448.create(bytesToNumberLE(xof));
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* HashToCurve-like construction based on RFC 9496 (Element Derivation).
|
|
404
|
+
* Converts 112 uniform random bytes into a curve point.
|
|
405
|
+
*
|
|
406
|
+
* WARNING: This represents an older hash-to-curve construction, preceding the finalization of RFC 9380.
|
|
407
|
+
* It was later reused as a component in the newer `hash_to_ristretto255` function defined in RFC 9380.
|
|
408
|
+
*/
|
|
409
|
+
deriveToCurve(bytes) {
|
|
410
|
+
abytes(bytes, 112);
|
|
411
|
+
const skipValidation = true;
|
|
412
|
+
// Note: Similar to the field element decoding described in
|
|
413
|
+
// [RFC7748], and unlike the field element decoding described in
|
|
414
|
+
// Section 5.3.1, non-canonical values are accepted.
|
|
415
|
+
const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
|
|
416
|
+
const R1 = calcElligatorDecafMap(r1);
|
|
417
|
+
const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
|
|
418
|
+
const R2 = calcElligatorDecafMap(r2);
|
|
419
|
+
return new _DecafPoint(R1.add(R2));
|
|
426
420
|
},
|
|
427
421
|
};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
422
|
+
/** decaf448 OPRF, defined in RFC 9497. */
|
|
423
|
+
export const decaf448_oprf = /* @__PURE__ */ (() => createORPF({
|
|
424
|
+
name: 'decaf448-SHAKE256',
|
|
425
|
+
Point: _DecafPoint,
|
|
426
|
+
hash: (msg) => shake256(msg, { dkLen: 64 }),
|
|
427
|
+
hashToGroup: decaf448_hasher.hashToCurve,
|
|
428
|
+
hashToScalar: decaf448_hasher.hashToScalar,
|
|
429
|
+
}))();
|
|
435
430
|
/**
|
|
436
431
|
* Weird / bogus points, useful for debugging.
|
|
437
432
|
* Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
|
|
438
433
|
* Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
|
|
439
434
|
* (0, 1), (0, -1), (-1, 0), (1, 0).
|
|
440
435
|
*/
|
|
441
|
-
|
|
436
|
+
export const ED448_TORSION_SUBGROUP = [
|
|
442
437
|
'010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
443
438
|
'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
|
|
444
439
|
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
445
440
|
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
|
|
446
441
|
];
|
|
447
|
-
/** @deprecated use `decaf448.Point` */
|
|
448
|
-
exports.DecafPoint = _DecafPoint;
|
|
449
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
450
|
-
exports.hashToCurve = (() => exports.ed448_hasher.hashToCurve)();
|
|
451
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
452
|
-
exports.encodeToCurve = (() => exports.ed448_hasher.encodeToCurve)();
|
|
453
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
454
|
-
exports.hashToDecaf448 = (() => exports.decaf448_hasher.hashToCurve)();
|
|
455
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
456
|
-
exports.hash_to_decaf448 = (() => exports.decaf448_hasher.hashToCurve)();
|
|
457
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
458
|
-
function edwardsToMontgomeryPub(edwardsPub) {
|
|
459
|
-
return exports.ed448.utils.toMontgomery((0, utils_ts_1.ensureBytes)('pub', edwardsPub));
|
|
460
|
-
}
|
|
461
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
462
|
-
exports.edwardsToMontgomery = edwardsToMontgomeryPub;
|
|
463
442
|
//# sourceMappingURL=ed448.js.map
|