You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

450 lines
16 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>elliptic - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package elliptic</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "crypto/elliptic"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package elliptic implements several standard elliptic curves over prime
  68. fields.
  69. </p>
  70. </div>
  71. </div>
  72. <div id="pkg-index" class="toggleVisible">
  73. <div class="collapsed">
  74. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  75. </div>
  76. <div class="expanded">
  77. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  78. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  79. <div id="manual-nav">
  80. <dl>
  81. <dd><a href="index.html#GenerateKey">func GenerateKey(curve Curve, rand io.Reader) (priv []byte, x, y *big.Int, err error)</a></dd>
  82. <dd><a href="index.html#Marshal">func Marshal(curve Curve, x, y *big.Int) []byte</a></dd>
  83. <dd><a href="index.html#Unmarshal">func Unmarshal(curve Curve, data []byte) (x, y *big.Int)</a></dd>
  84. <dd><a href="index.html#Curve">type Curve</a></dd>
  85. <dd>&nbsp; &nbsp; <a href="index.html#P224">func P224() Curve</a></dd>
  86. <dd>&nbsp; &nbsp; <a href="index.html#P256">func P256() Curve</a></dd>
  87. <dd>&nbsp; &nbsp; <a href="index.html#P384">func P384() Curve</a></dd>
  88. <dd>&nbsp; &nbsp; <a href="index.html#P521">func P521() Curve</a></dd>
  89. <dd><a href="index.html#CurveParams">type CurveParams</a></dd>
  90. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.Add">func (curve *CurveParams) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)</a></dd>
  91. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.Double">func (curve *CurveParams) Double(x1, y1 *big.Int) (*big.Int, *big.Int)</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.IsOnCurve">func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.Params">func (curve *CurveParams) Params() *CurveParams</a></dd>
  94. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.ScalarBaseMult">func (curve *CurveParams) ScalarBaseMult(k []byte) (*big.Int, *big.Int)</a></dd>
  95. <dd>&nbsp; &nbsp; <a href="index.html#CurveParams.ScalarMult">func (curve *CurveParams) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)</a></dd>
  96. </dl>
  97. </div><!-- #manual-nav -->
  98. <h4>Package files</h4>
  99. <p>
  100. <span style="font-size:90%">
  101. <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go">elliptic.go</a>
  102. <a href="http://localhost:6060/src/crypto/elliptic/p224.go">p224.go</a>
  103. <a href="http://localhost:6060/src/crypto/elliptic/p256_amd64.go">p256_amd64.go</a>
  104. </span>
  105. </p>
  106. </div><!-- .expanded -->
  107. </div><!-- #pkg-index -->
  108. <div id="pkg-callgraph" class="toggle" style="display: none">
  109. <div class="collapsed">
  110. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  111. </div> <!-- .expanded -->
  112. <div class="expanded">
  113. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  114. <p>
  115. In the call graph viewer below, each node
  116. is a function belonging to this package
  117. and its children are the functions it
  118. calls&mdash;perhaps dynamically.
  119. </p>
  120. <p>
  121. The root nodes are the entry points of the
  122. package: functions that may be called from
  123. outside the package.
  124. There may be non-exported or anonymous
  125. functions among them if they are called
  126. dynamically from another package.
  127. </p>
  128. <p>
  129. Click a node to visit that function's source code.
  130. From there you can visit its callers by
  131. clicking its declaring <code>func</code>
  132. token.
  133. </p>
  134. <p>
  135. Functions may be omitted if they were
  136. determined to be unreachable in the
  137. particular programs or tests that were
  138. analyzed.
  139. </p>
  140. <!-- Zero means show all package entry points. -->
  141. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  142. </div>
  143. </div> <!-- #pkg-callgraph -->
  144. <h2 id="GenerateKey">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=7368:7453#L266">GenerateKey</a></h2>
  145. <pre>func GenerateKey(curve <a href="index.html#Curve">Curve</a>, rand <a href="../../io/index.html">io</a>.<a href="../../io/index.html#Reader">Reader</a>) (priv []<a href="../../builtin/index.html#byte">byte</a>, x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
  146. <p>
  147. GenerateKey returns a public/private key pair. The private key is
  148. generated using the given reader, which must return random data.
  149. </p>
  150. <h2 id="Marshal">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=8216:8263#L295">Marshal</a></h2>
  151. <pre>func Marshal(curve <a href="index.html#Curve">Curve</a>, x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) []<a href="../../builtin/index.html#byte">byte</a></pre>
  152. <p>
  153. Marshal converts a point into the form specified in section 4.3.6 of ANSI X9.62.
  154. </p>
  155. <h2 id="Unmarshal">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=8671:8727#L310">Unmarshal</a></h2>
  156. <pre>func Unmarshal(curve <a href="index.html#Curve">Curve</a>, data []<a href="../../builtin/index.html#byte">byte</a>) (x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)</pre>
  157. <p>
  158. Unmarshal converts a point, serialized by Marshal, into an x, y pair.
  159. It is an error if the point is not on the curve. On error, x = nil.
  160. </p>
  161. <h2 id="Curve">type <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=871:1509#L14">Curve</a></h2>
  162. <pre>type Curve interface {
  163. <span class="comment">// Params returns the parameters for the curve.</span>
  164. Params() *<a href="index.html#CurveParams">CurveParams</a>
  165. <span class="comment">// IsOnCurve reports whether the given (x,y) lies on the curve.</span>
  166. IsOnCurve(x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) <a href="../../builtin/index.html#bool">bool</a>
  167. <span class="comment">// Add returns the sum of (x1,y1) and (x2,y2)</span>
  168. Add(x1, y1, x2, y2 *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) (x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)
  169. <span class="comment">// Double returns 2*(x,y)</span>
  170. Double(x1, y1 *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) (x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)
  171. <span class="comment">// ScalarMult returns k*(Bx,By) where k is a number in big-endian form.</span>
  172. ScalarMult(x1, y1 *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, k []<a href="../../builtin/index.html#byte">byte</a>) (x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)
  173. <span class="comment">// ScalarBaseMult returns k*G, where G is the base point of the group</span>
  174. <span class="comment">// and k is an integer in big-endian form.</span>
  175. ScalarBaseMult(k []<a href="../../builtin/index.html#byte">byte</a>) (x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)
  176. }</pre>
  177. <p>
  178. A Curve represents a short-form Weierstrass curve with a=-3.
  179. See <a href="http://www.hyperelliptic.org/EFD/g1p/auto-shortw.html">http://www.hyperelliptic.org/EFD/g1p/auto-shortw.html</a>
  180. </p>
  181. <h3 id="P224">func <a href="http://localhost:6060/src/crypto/elliptic/p224.go?s=1291:1308#L29">P224</a></h3>
  182. <pre>func P224() <a href="index.html#Curve">Curve</a></pre>
  183. <p>
  184. P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
  185. </p>
  186. <h3 id="P256">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=11132:11149#L360">P256</a></h3>
  187. <pre>func P256() <a href="index.html#Curve">Curve</a></pre>
  188. <p>
  189. P256 returns a Curve which implements P-256 (see FIPS 186-3, section D.2.3)
  190. </p>
  191. <h3 id="P384">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=11269:11286#L366">P384</a></h3>
  192. <pre>func P384() <a href="index.html#Curve">Curve</a></pre>
  193. <p>
  194. P384 returns a Curve which implements P-384 (see FIPS 186-3, section D.2.4)
  195. </p>
  196. <h3 id="P521">func <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=11406:11423#L372">P521</a></h3>
  197. <pre>func P521() <a href="index.html#Curve">Curve</a></pre>
  198. <p>
  199. P521 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
  200. </p>
  201. <h2 id="CurveParams">type <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=1646:1985#L32">CurveParams</a></h2>
  202. <pre>type CurveParams struct {
  203. P *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a> <span class="comment">// the order of the underlying field</span>
  204. N *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a> <span class="comment">// the order of the base point</span>
  205. B *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a> <span class="comment">// the constant of the curve equation</span>
  206. Gx, Gy *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a> <span class="comment">// (x,y) of the base point</span>
  207. BitSize <a href="../../builtin/index.html#int">int</a> <span class="comment">// the size of the underlying field</span>
  208. Name <a href="../../builtin/index.html#string">string</a> <span class="comment">// the canonical name of the curve</span>
  209. }</pre>
  210. <p>
  211. CurveParams contains the parameters of an elliptic curve and also provides
  212. a generic, non-constant time implementation of Curve.
  213. </p>
  214. <h3 id="CurveParams.Add">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=3249:3324#L92">Add</a></h3>
  215. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) Add(x1, y1, x2, y2 *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) (*<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)</pre>
  216. <h3 id="CurveParams.Double">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=5095:5165#L176">Double</a></h3>
  217. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) Double(x1, y1 *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) (*<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)</pre>
  218. <h3 id="CurveParams.IsOnCurve">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=2054:2109#L45">IsOnCurve</a></h3>
  219. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) IsOnCurve(x, y *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
  220. <h3 id="CurveParams.Params">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=1987:2034#L41">Params</a></h3>
  221. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) Params() *<a href="index.html#CurveParams">CurveParams</a></pre>
  222. <h3 id="CurveParams.ScalarBaseMult">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=7043:7114#L258">ScalarBaseMult</a></h3>
  223. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) ScalarBaseMult(k []<a href="../../builtin/index.html#byte">byte</a>) (*<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)</pre>
  224. <h3 id="CurveParams.ScalarMult">func (*CurveParams) <a href="http://localhost:6060/src/crypto/elliptic/elliptic.go?s=6608:6692#L241">ScalarMult</a></h3>
  225. <pre>func (curve *<a href="index.html#CurveParams">CurveParams</a>) ScalarMult(Bx, By *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, k []<a href="../../builtin/index.html#byte">byte</a>) (*<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>, *<a href="../../math/big/index.html">big</a>.<a href="../../math/big/index.html#Int">Int</a>)</pre>
  226. <div id="footer">
  227. Build version go1.6.<br>
  228. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  229. the content of this page is licensed under the
  230. Creative Commons Attribution 3.0 License,
  231. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  232. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  233. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  234. </div>
  235. </div><!-- .container -->
  236. </div><!-- #page -->
  237. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  238. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  239. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  240. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  241. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  242. </body>
  243. </html>