p521.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.encodeToCurve = exports.hashToCurve = exports.secp521r1 = exports.p521 = void 0;
  4. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  5. const sha512_1 = require("@noble/hashes/sha512");
  6. const _shortw_utils_js_1 = require("./_shortw_utils.js");
  7. const hash_to_curve_js_1 = require("./abstract/hash-to-curve.js");
  8. const modular_js_1 = require("./abstract/modular.js");
  9. const weierstrass_js_1 = require("./abstract/weierstrass.js");
  10. // NIST secp521r1 aka p521
  11. // Note that it's 521, which differs from 512 of its hash function.
  12. // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
  13. // Field over which we'll do calculations.
  14. // prettier-ignore
  15. const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
  16. const Fp = (0, modular_js_1.Field)(P);
  17. const CURVE = {
  18. a: Fp.create(BigInt('-3')),
  19. b: BigInt('0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'),
  20. Fp,
  21. n: BigInt('0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'),
  22. Gx: BigInt('0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'),
  23. Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
  24. h: BigInt(1),
  25. };
  26. // prettier-ignore
  27. exports.p521 = (0, _shortw_utils_js_1.createCurve)({
  28. a: CURVE.a, // Equation params: a, b
  29. b: CURVE.b,
  30. Fp, // Field: 2n**521n - 1n
  31. // Curve order, total count of valid points in the field
  32. n: CURVE.n,
  33. Gx: CURVE.Gx, // Base point (x, y) aka generator point
  34. Gy: CURVE.Gy,
  35. h: CURVE.h,
  36. lowS: false,
  37. allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
  38. }, sha512_1.sha512);
  39. exports.secp521r1 = exports.p521;
  40. const mapSWU = /* @__PURE__ */ (() => (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
  41. A: CURVE.a,
  42. B: CURVE.b,
  43. Z: Fp.create(BigInt('-4')),
  44. }))();
  45. const htf = /* @__PURE__ */ (() => (0, hash_to_curve_js_1.createHasher)(exports.secp521r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
  46. DST: 'P521_XMD:SHA-512_SSWU_RO_',
  47. encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
  48. p: Fp.ORDER,
  49. m: 1,
  50. k: 256,
  51. expand: 'xmd',
  52. hash: sha512_1.sha512,
  53. }))();
  54. exports.hashToCurve = (() => htf.hashToCurve)();
  55. exports.encodeToCurve = (() => htf.encodeToCurve)();
  56. //# sourceMappingURL=p521.js.map