p384.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  2. import { sha384 } from '@noble/hashes/sha512';
  3. import { createCurve } from './_shortw_utils.js';
  4. import { createHasher } from './abstract/hash-to-curve.js';
  5. import { Field } from './abstract/modular.js';
  6. import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
  7. // NIST secp384r1 aka p384
  8. // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
  9. // Field over which we'll do calculations.
  10. // prettier-ignore
  11. const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
  12. const Fp = Field(P);
  13. const CURVE_A = Fp.create(BigInt('-3'));
  14. // prettier-ignore
  15. const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
  16. // prettier-ignore
  17. export const p384 = createCurve({
  18. a: CURVE_A, // Equation params: a, b
  19. b: CURVE_B,
  20. Fp, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
  21. // Curve order, total count of valid points in the field.
  22. n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
  23. // Base (generator) point (x, y)
  24. Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
  25. Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
  26. h: BigInt(1),
  27. lowS: false,
  28. }, sha384);
  29. export const secp384r1 = p384;
  30. const mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fp, {
  31. A: CURVE_A,
  32. B: CURVE_B,
  33. Z: Fp.create(BigInt('-12')),
  34. }))();
  35. const htf = /* @__PURE__ */ (() => createHasher(secp384r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
  36. DST: 'P384_XMD:SHA-384_SSWU_RO_',
  37. encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
  38. p: Fp.ORDER,
  39. m: 1,
  40. k: 192,
  41. expand: 'xmd',
  42. hash: sha384,
  43. }))();
  44. export const hashToCurve = /* @__PURE__ */ (() => htf.hashToCurve)();
  45. export const encodeToCurve = /* @__PURE__ */ (() => htf.encodeToCurve)();
  46. //# sourceMappingURL=p384.js.map