p256.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.encodeToCurve = exports.hashToCurve = exports.secp256r1 = exports.p256 = void 0;
  4. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  5. const sha256_1 = require("@noble/hashes/sha256");
  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 secp256r1 aka p256
  11. // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
  12. const Fp = (0, modular_js_1.Field)(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
  13. const CURVE_A = Fp.create(BigInt('-3'));
  14. const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
  15. // prettier-ignore
  16. exports.p256 = (0, _shortw_utils_js_1.createCurve)({
  17. a: CURVE_A, // Equation params: a, b
  18. b: CURVE_B,
  19. Fp, // Field: 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
  20. // Curve order, total count of valid points in the field
  21. n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
  22. // Base (generator) point (x, y)
  23. Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
  24. Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
  25. h: BigInt(1),
  26. lowS: false,
  27. }, sha256_1.sha256);
  28. exports.secp256r1 = exports.p256;
  29. const mapSWU = /* @__PURE__ */ (() => (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
  30. A: CURVE_A,
  31. B: CURVE_B,
  32. Z: Fp.create(BigInt('-10')),
  33. }))();
  34. const htf = /* @__PURE__ */ (() => (0, hash_to_curve_js_1.createHasher)(exports.secp256r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
  35. DST: 'P256_XMD:SHA-256_SSWU_RO_',
  36. encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
  37. p: Fp.ORDER,
  38. m: 1,
  39. k: 128,
  40. expand: 'xmd',
  41. hash: sha256_1.sha256,
  42. }))();
  43. exports.hashToCurve = (() => htf.hashToCurve)();
  44. exports.encodeToCurve = (() => htf.encodeToCurve)();
  45. //# sourceMappingURL=p256.js.map