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.

744 lines
21 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>crypto - 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 crypto</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"</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. <dd><a href="index.html#pkg-subdirectories">Subdirectories</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package crypto collects common cryptographic constants.
  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#RegisterHash">func RegisterHash(h Hash, f func() hash.Hash)</a></dd>
  82. <dd><a href="index.html#Decrypter">type Decrypter</a></dd>
  83. <dd><a href="index.html#DecrypterOpts">type DecrypterOpts</a></dd>
  84. <dd><a href="index.html#Hash">type Hash</a></dd>
  85. <dd>&nbsp; &nbsp; <a href="index.html#Hash.Available">func (h Hash) Available() bool</a></dd>
  86. <dd>&nbsp; &nbsp; <a href="index.html#Hash.HashFunc">func (h Hash) HashFunc() Hash</a></dd>
  87. <dd>&nbsp; &nbsp; <a href="index.html#Hash.New">func (h Hash) New() hash.Hash</a></dd>
  88. <dd>&nbsp; &nbsp; <a href="index.html#Hash.Size">func (h Hash) Size() int</a></dd>
  89. <dd><a href="index.html#PrivateKey">type PrivateKey</a></dd>
  90. <dd><a href="index.html#PublicKey">type PublicKey</a></dd>
  91. <dd><a href="index.html#Signer">type Signer</a></dd>
  92. <dd><a href="index.html#SignerOpts">type SignerOpts</a></dd>
  93. </dl>
  94. </div><!-- #manual-nav -->
  95. <h4>Package files</h4>
  96. <p>
  97. <span style="font-size:90%">
  98. <a href="http://localhost:6060/src/crypto/crypto.go">crypto.go</a>
  99. </span>
  100. </p>
  101. </div><!-- .expanded -->
  102. </div><!-- #pkg-index -->
  103. <div id="pkg-callgraph" class="toggle" style="display: none">
  104. <div class="collapsed">
  105. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  106. </div> <!-- .expanded -->
  107. <div class="expanded">
  108. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  109. <p>
  110. In the call graph viewer below, each node
  111. is a function belonging to this package
  112. and its children are the functions it
  113. calls&mdash;perhaps dynamically.
  114. </p>
  115. <p>
  116. The root nodes are the entry points of the
  117. package: functions that may be called from
  118. outside the package.
  119. There may be non-exported or anonymous
  120. functions among them if they are called
  121. dynamically from another package.
  122. </p>
  123. <p>
  124. Click a node to visit that function's source code.
  125. From there you can visit its callers by
  126. clicking its declaring <code>func</code>
  127. token.
  128. </p>
  129. <p>
  130. Functions may be omitted if they were
  131. determined to be unreachable in the
  132. particular programs or tests that were
  133. analyzed.
  134. </p>
  135. <!-- Zero means show all package entry points. -->
  136. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  137. </div>
  138. </div> <!-- #pkg-callgraph -->
  139. <h2 id="RegisterHash">func <a href="http://localhost:6060/src/crypto/crypto.go?s=2728:2773#L82">RegisterHash</a></h2>
  140. <pre>func RegisterHash(h <a href="index.html#Hash">Hash</a>, f func() <a href="../hash/index.html">hash</a>.<a href="../hash/index.html#Hash">Hash</a>)</pre>
  141. <p>
  142. RegisterHash registers a function that returns a new instance of the given
  143. hash function. This is intended to be called from the init function in
  144. packages that implement hash functions.
  145. </p>
  146. <h2 id="Decrypter">type <a href="http://localhost:6060/src/crypto/crypto.go?s=4661:5033#L129">Decrypter</a></h2>
  147. <pre>type Decrypter interface {
  148. <span class="comment">// Public returns the public key corresponding to the opaque,</span>
  149. <span class="comment">// private key.</span>
  150. Public() <a href="index.html#PublicKey">PublicKey</a>
  151. <span class="comment">// Decrypt decrypts msg. The opts argument should be appropriate for</span>
  152. <span class="comment">// the primitive used. See the documentation in each implementation for</span>
  153. <span class="comment">// details.</span>
  154. Decrypt(rand <a href="../io/index.html">io</a>.<a href="../io/index.html#Reader">Reader</a>, msg []<a href="../builtin/index.html#byte">byte</a>, opts <a href="index.html#DecrypterOpts">DecrypterOpts</a>) (plaintext []<a href="../builtin/index.html#byte">byte</a>, err <a href="../builtin/index.html#error">error</a>)
  155. }</pre>
  156. <p>
  157. Decrypter is an interface for an opaque private key that can be used for
  158. asymmetric decryption operations. An example would be an RSA key
  159. kept in a hardware module.
  160. </p>
  161. <h2 id="DecrypterOpts">type <a href="http://localhost:6060/src/crypto/crypto.go?s=5035:5065#L140">DecrypterOpts</a></h2>
  162. <pre>type DecrypterOpts interface{}</pre>
  163. <h2 id="Hash">type <a href="http://localhost:6060/src/crypto/crypto.go?s=364:378#L6">Hash</a></h2>
  164. <pre>type Hash <a href="../builtin/index.html#uint">uint</a></pre>
  165. <p>
  166. Hash identifies a cryptographic hash function that is implemented in another
  167. package.
  168. </p>
  169. <pre>const (
  170. <span id="MD4">MD4</span> <a href="index.html#Hash">Hash</a> = 1 + <a href="../builtin/index.html#iota">iota</a> <span class="comment">// import golang.org/x/crypto/md4</span>
  171. <span id="MD5">MD5</span> <span class="comment">// import crypto/md5</span>
  172. <span id="SHA1">SHA1</span> <span class="comment">// import crypto/sha1</span>
  173. <span id="SHA224">SHA224</span> <span class="comment">// import crypto/sha256</span>
  174. <span id="SHA256">SHA256</span> <span class="comment">// import crypto/sha256</span>
  175. <span id="SHA384">SHA384</span> <span class="comment">// import crypto/sha512</span>
  176. <span id="SHA512">SHA512</span> <span class="comment">// import crypto/sha512</span>
  177. <span id="MD5SHA1">MD5SHA1</span> <span class="comment">// no implementation; MD5+SHA1 used for TLS RSA</span>
  178. <span id="RIPEMD160">RIPEMD160</span> <span class="comment">// import golang.org/x/crypto/ripemd160</span>
  179. <span id="SHA3_224">SHA3_224</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
  180. <span id="SHA3_256">SHA3_256</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
  181. <span id="SHA3_384">SHA3_384</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
  182. <span id="SHA3_512">SHA3_512</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
  183. <span id="SHA512_224">SHA512_224</span> <span class="comment">// import crypto/sha512</span>
  184. <span id="SHA512_256">SHA512_256</span> <span class="comment">// import crypto/sha512</span>
  185. )</pre>
  186. <h3 id="Hash.Available">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=2457:2487#L75">Available</a></h3>
  187. <pre>func (h <a href="index.html#Hash">Hash</a>) Available() <a href="../builtin/index.html#bool">bool</a></pre>
  188. <p>
  189. Available reports whether the given hash function is linked into the binary.
  190. </p>
  191. <h3 id="Hash.HashFunc">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=458:487#L9">HashFunc</a></h3>
  192. <pre>func (h <a href="index.html#Hash">Hash</a>) HashFunc() <a href="index.html#Hash">Hash</a></pre>
  193. <p>
  194. HashFunc simply returns the value of h so that Hash implements SignerOpts.
  195. </p>
  196. <h3 id="Hash.New">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=2174:2203#L64">New</a></h3>
  197. <pre>func (h <a href="index.html#Hash">Hash</a>) New() <a href="../hash/index.html">hash</a>.<a href="../hash/index.html#Hash">Hash</a></pre>
  198. <p>
  199. New returns a new hash.Hash calculating the given hash function. New panics
  200. if the hash function is not linked into the binary.
  201. </p>
  202. <h3 id="Hash.Size">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=1855:1879#L53">Size</a></h3>
  203. <pre>func (h <a href="index.html#Hash">Hash</a>) Size() <a href="../builtin/index.html#int">int</a></pre>
  204. <p>
  205. Size returns the length, in bytes, of a digest resulting from the given hash
  206. function. It doesn&#39;t require that the hash function in question be linked
  207. into the program.
  208. </p>
  209. <h2 id="PrivateKey">type <a href="http://localhost:6060/src/crypto/crypto.go?s=3041:3068#L93">PrivateKey</a></h2>
  210. <pre>type PrivateKey interface{}</pre>
  211. <p>
  212. PrivateKey represents a private key using an unspecified algorithm.
  213. </p>
  214. <h2 id="PublicKey">type <a href="http://localhost:6060/src/crypto/crypto.go?s=2942:2968#L90">PublicKey</a></h2>
  215. <pre>type PublicKey interface{}</pre>
  216. <p>
  217. PublicKey represents a public key using an unspecified algorithm.
  218. </p>
  219. <h2 id="Signer">type <a href="http://localhost:6060/src/crypto/crypto.go?s=3217:4212#L97">Signer</a></h2>
  220. <pre>type Signer interface {
  221. <span class="comment">// Public returns the public key corresponding to the opaque,</span>
  222. <span class="comment">// private key.</span>
  223. Public() <a href="index.html#PublicKey">PublicKey</a>
  224. <span class="comment">// Sign signs digest with the private key, possibly using entropy from</span>
  225. <span class="comment">// rand. For an RSA key, the resulting signature should be either a</span>
  226. <span class="comment">// PKCS#1 v1.5 or PSS signature (as indicated by opts). For an (EC)DSA</span>
  227. <span class="comment">// key, it should be a DER-serialised, ASN.1 signature structure.</span>
  228. <span class="comment">//</span>
  229. <span class="comment">// Hash implements the SignerOpts interface and, in most cases, one can</span>
  230. <span class="comment">// simply pass in the hash function used as opts. Sign may also attempt</span>
  231. <span class="comment">// to type assert opts to other types in order to obtain algorithm</span>
  232. <span class="comment">// specific values. See the documentation in each package for details.</span>
  233. <span class="comment">//</span>
  234. <span class="comment">// Note that when a signature of a hash of a larger message is needed,</span>
  235. <span class="comment">// the caller is responsible for hashing the larger message and passing</span>
  236. <span class="comment">// the hash (as digest) and the hash function (as opts) to Sign.</span>
  237. Sign(rand <a href="../io/index.html">io</a>.<a href="../io/index.html#Reader">Reader</a>, digest []<a href="../builtin/index.html#byte">byte</a>, opts <a href="index.html#SignerOpts">SignerOpts</a>) (signature []<a href="../builtin/index.html#byte">byte</a>, err <a href="../builtin/index.html#error">error</a>)
  238. }</pre>
  239. <p>
  240. Signer is an interface for an opaque private key that can be used for
  241. signing operations. For example, an RSA key kept in a hardware module.
  242. </p>
  243. <h2 id="SignerOpts">type <a href="http://localhost:6060/src/crypto/crypto.go?s=4272:4485#L119">SignerOpts</a></h2>
  244. <pre>type SignerOpts interface {
  245. <span class="comment">// HashFunc returns an identifier for the hash function used to produce</span>
  246. <span class="comment">// the message passed to Signer.Sign, or else zero to indicate that no</span>
  247. <span class="comment">// hashing was done.</span>
  248. HashFunc() <a href="index.html#Hash">Hash</a>
  249. }</pre>
  250. <p>
  251. SignerOpts contains options for signing with a Signer.
  252. </p>
  253. <h2 id="pkg-subdirectories">Subdirectories</h2>
  254. <div class="pkg-dir">
  255. <table>
  256. <tr>
  257. <th class="pkg-name">Name</th>
  258. <th class="pkg-synopsis">Synopsis</th>
  259. </tr>
  260. <tr>
  261. <td colspan="2"><a href="http://localhost:6060/pkg/">..</a></td>
  262. </tr>
  263. <tr>
  264. <td class="pkg-name" style="padding-left: 0px;">
  265. <a href="aes/index.html">aes</a>
  266. </td>
  267. <td class="pkg-synopsis">
  268. Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
  269. </td>
  270. </tr>
  271. <tr>
  272. <td class="pkg-name" style="padding-left: 0px;">
  273. <a href="cipher/index.html">cipher</a>
  274. </td>
  275. <td class="pkg-synopsis">
  276. Package cipher implements standard block cipher modes that can be wrapped around low-level block cipher implementations.
  277. </td>
  278. </tr>
  279. <tr>
  280. <td class="pkg-name" style="padding-left: 0px;">
  281. <a href="des/index.html">des</a>
  282. </td>
  283. <td class="pkg-synopsis">
  284. Package des implements the Data Encryption Standard (DES) and the Triple Data Encryption Algorithm (TDEA) as defined in U.S. Federal Information Processing Standards Publication 46-3.
  285. </td>
  286. </tr>
  287. <tr>
  288. <td class="pkg-name" style="padding-left: 0px;">
  289. <a href="dsa/index.html">dsa</a>
  290. </td>
  291. <td class="pkg-synopsis">
  292. Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3.
  293. </td>
  294. </tr>
  295. <tr>
  296. <td class="pkg-name" style="padding-left: 0px;">
  297. <a href="ecdsa/index.html">ecdsa</a>
  298. </td>
  299. <td class="pkg-synopsis">
  300. Package ecdsa implements the Elliptic Curve Digital Signature Algorithm, as defined in FIPS 186-3.
  301. </td>
  302. </tr>
  303. <tr>
  304. <td class="pkg-name" style="padding-left: 0px;">
  305. <a href="elliptic/index.html">elliptic</a>
  306. </td>
  307. <td class="pkg-synopsis">
  308. Package elliptic implements several standard elliptic curves over prime fields.
  309. </td>
  310. </tr>
  311. <tr>
  312. <td class="pkg-name" style="padding-left: 0px;">
  313. <a href="hmac/index.html">hmac</a>
  314. </td>
  315. <td class="pkg-synopsis">
  316. Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.
  317. </td>
  318. </tr>
  319. <tr>
  320. <td class="pkg-name" style="padding-left: 0px;">
  321. <a href="md5/index.html">md5</a>
  322. </td>
  323. <td class="pkg-synopsis">
  324. Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
  325. </td>
  326. </tr>
  327. <tr>
  328. <td class="pkg-name" style="padding-left: 0px;">
  329. <a href="rand/index.html">rand</a>
  330. </td>
  331. <td class="pkg-synopsis">
  332. Package rand implements a cryptographically secure pseudorandom number generator.
  333. </td>
  334. </tr>
  335. <tr>
  336. <td class="pkg-name" style="padding-left: 0px;">
  337. <a href="rc4/index.html">rc4</a>
  338. </td>
  339. <td class="pkg-synopsis">
  340. Package rc4 implements RC4 encryption, as defined in Bruce Schneier&#39;s Applied Cryptography.
  341. </td>
  342. </tr>
  343. <tr>
  344. <td class="pkg-name" style="padding-left: 0px;">
  345. <a href="rsa/index.html">rsa</a>
  346. </td>
  347. <td class="pkg-synopsis">
  348. Package rsa implements RSA encryption as specified in PKCS#1.
  349. </td>
  350. </tr>
  351. <tr>
  352. <td class="pkg-name" style="padding-left: 0px;">
  353. <a href="sha1/index.html">sha1</a>
  354. </td>
  355. <td class="pkg-synopsis">
  356. Package sha1 implements the SHA1 hash algorithm as defined in RFC 3174.
  357. </td>
  358. </tr>
  359. <tr>
  360. <td class="pkg-name" style="padding-left: 0px;">
  361. <a href="sha256/index.html">sha256</a>
  362. </td>
  363. <td class="pkg-synopsis">
  364. Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
  365. </td>
  366. </tr>
  367. <tr>
  368. <td class="pkg-name" style="padding-left: 0px;">
  369. <a href="sha512/index.html">sha512</a>
  370. </td>
  371. <td class="pkg-synopsis">
  372. Package sha512 implements the SHA-384, SHA-512, SHA-512/224, and SHA-512/256 hash algorithms as defined in FIPS 180-4.
  373. </td>
  374. </tr>
  375. <tr>
  376. <td class="pkg-name" style="padding-left: 0px;">
  377. <a href="subtle/index.html">subtle</a>
  378. </td>
  379. <td class="pkg-synopsis">
  380. Package subtle implements functions that are often useful in cryptographic code but require careful thought to use correctly.
  381. </td>
  382. </tr>
  383. <tr>
  384. <td class="pkg-name" style="padding-left: 0px;">
  385. <a href="tls/index.html">tls</a>
  386. </td>
  387. <td class="pkg-synopsis">
  388. Package tls partially implements TLS 1.2, as specified in RFC 5246.
  389. </td>
  390. </tr>
  391. <tr>
  392. <td class="pkg-name" style="padding-left: 0px;">
  393. <a href="x509/index.html">x509</a>
  394. </td>
  395. <td class="pkg-synopsis">
  396. Package x509 parses X.509-encoded keys and certificates.
  397. </td>
  398. </tr>
  399. <tr>
  400. <td class="pkg-name" style="padding-left: 20px;">
  401. <a href="x509/pkix/index.html">pkix</a>
  402. </td>
  403. <td class="pkg-synopsis">
  404. Package pkix contains shared, low level structures used for ASN.1 parsing and serialization of X.509 certificates, CRL and OCSP.
  405. </td>
  406. </tr>
  407. </table>
  408. </div>
  409. <div id="footer">
  410. Build version go1.6.<br>
  411. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  412. the content of this page is licensed under the
  413. Creative Commons Attribution 3.0 License,
  414. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  415. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  416. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  417. </div>
  418. </div><!-- .container -->
  419. </div><!-- #page -->
  420. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  421. <script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
  422. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
  423. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
  424. <script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
  425. </body>
  426. </html>