p384.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.encodeToCurve = exports.hashToCurve = exports.secp384r1 = exports.p384 = 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 secp384r1 aka p384
  11. // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
  12. // Field over which we'll do calculations.
  13. // prettier-ignore
  14. const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
  15. const Fp = (0, modular_js_1.Field)(P);
  16. const CURVE_A = Fp.create(BigInt('-3'));
  17. // prettier-ignore
  18. const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
  19. // prettier-ignore
  20. exports.p384 = (0, _shortw_utils_js_1.createCurve)({
  21. a: CURVE_A, // Equation params: a, b
  22. b: CURVE_B,
  23. Fp, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
  24. // Curve order, total count of valid points in the field.
  25. n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
  26. // Base (generator) point (x, y)
  27. Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
  28. Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
  29. h: BigInt(1),
  30. lowS: false,
  31. }, sha512_1.sha384);
  32. exports.secp384r1 = exports.p384;
  33. const mapSWU = /* @__PURE__ */ (() => (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
  34. A: CURVE_A,
  35. B: CURVE_B,
  36. Z: Fp.create(BigInt('-12')),
  37. }))();
  38. const htf = /* @__PURE__ */ (() => (0, hash_to_curve_js_1.createHasher)(exports.secp384r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
  39. DST: 'P384_XMD:SHA-384_SSWU_RO_',
  40. encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
  41. p: Fp.ORDER,
  42. m: 1,
  43. k: 192,
  44. expand: 'xmd',
  45. hash: sha512_1.sha384,
  46. }))();
  47. exports.hashToCurve = (() => htf.hashToCurve)();
  48. exports.encodeToCurve = (() => htf.encodeToCurve)();
  49. //# sourceMappingURL=p384.js.map