Secp256k1.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /******************************************************************************
  3. * This file is part of the Phactor PHP project. You can always find the latest
  4. * version of this class and project at: https://github.com/ionux/phactor
  5. *
  6. * Copyright (c) 2015-2018 Rich Morgan, rich@richmorgan.me
  7. *
  8. * The MIT License (MIT)
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  11. * this software and associated documentation files (the "Software"), to deal in
  12. * the Software without restriction, including without limitation the rights to
  13. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  14. * the Software, and to permit persons to whom the Software is furnished to do so,
  15. * subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in all
  18. * copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  22. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  23. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  24. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  25. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. ******************************************************************************/
  27. namespace Phactor;
  28. /**
  29. * This trait specifies the recommended 256-bit elliptic curve domain
  30. * parameters over Fp associated with the Koblitz curve secp256k1.
  31. * @see http://www.secg.org/sec2-v2.pdf
  32. *
  33. * @author Rich Morgan <rich@richmorgan.me>
  34. */
  35. trait Secp256k1
  36. {
  37. /*
  38. * The elliptic curve domain parameters over Fp associated with a Koblitz curve secp256k1 are
  39. * specified by the sextuple T = (p, a, b, G, n, h) where the finite field Fp is defined by:
  40. */
  41. /**
  42. * The base point G in uncompressed form in hex:
  43. *
  44. * @var string
  45. */
  46. public $G = '0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8';
  47. /**
  48. * 2^256 − 2^32 − 2^9 − 2^8 − 2^7 − 2^6 − 2^4 − 1 in hex:
  49. *
  50. * @var string
  51. */
  52. public $p_hex = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f';
  53. /**
  54. * 2^256 − 2^32 − 2^9 − 2^8 − 2^7 − 2^6 − 2^4 − 1 in decimal:
  55. *
  56. * @var string
  57. */
  58. public $p = '115792089237316195423570985008687907853269984665640564039457584007908834671663';
  59. /**
  60. * The curve E: y^2 = x^3 + ax + b over Fp, where a in hex:
  61. *
  62. * @var string
  63. */
  64. public $a_hex = '0x00';
  65. /**
  66. * The curve E: y^2 = x^3 + ax + b over Fp, where a in decimal:
  67. *
  68. * @var string
  69. */
  70. public $a = '0';
  71. /**
  72. * The curve E: y^2 = x^3 + ax + b over Fp, where b in hex:
  73. *
  74. * @var string
  75. */
  76. public $b_hex = '0x07';
  77. /**
  78. * The curve E: y^2 = x^3 + ax + b over Fp, where b in decimal:
  79. *
  80. * @var string
  81. */
  82. public $b = '7';
  83. /**
  84. * The order n of G in hex:
  85. *
  86. * @var string
  87. */
  88. public $n_hex = '0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141';
  89. /**
  90. * The order n of G in decimal:
  91. *
  92. * @var string
  93. */
  94. public $n = '115792089237316195423570985008687907852837564279074904382605163141518161494337';
  95. /**
  96. * The cofactor in hex:
  97. *
  98. * @var string
  99. */
  100. public $h_hex = '0x01';
  101. /**
  102. * The cofactor in decimal:
  103. *
  104. * @var string
  105. */
  106. public $h = '1';
  107. /**
  108. * X-coordinate of G in hex:
  109. *
  110. * @var string
  111. */
  112. public $Gx_hex = '0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798';
  113. /**
  114. * X-coordinate of G in decimal:
  115. *
  116. * @var string
  117. */
  118. public $Gx = '55066263022277343669578718895168534326250603453777594175500187360389116729240';
  119. /**
  120. * Y-coordinate of G in hex:
  121. *
  122. * @var string
  123. */
  124. public $Gy_hex = '0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8';
  125. /**
  126. * Y-coordinate of G in decimal:
  127. *
  128. * @var string
  129. */
  130. public $Gy = '32670510020758816978083085130507043184471273380659243275938904335757337482424';
  131. }