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

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">
<title>crypto - The Go Programming Language</title>
<link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
<link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css">
<script type="text/javascript">window.initFuncs = [];</script>
</head>
<body>
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->
<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="http://localhost:6060/search">
<div id="menu">
<a href="http://localhost:6060/doc/">Documents</a>
<a href="http://localhost:6060/pkg/">Packages</a>
<a href="http://localhost:6060/project/">The Project</a>
<a href="http://localhost:6060/help/">Help</a>
<a href="http://localhost:6060/blog/">Blog</a>
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
</div>
</form>
</div></div>
<div id="page" class="wide">
<div class="container">
<h1>Package crypto</h1>
<div id="nav"></div>
<!--
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
Note: Static (i.e., not template-generated) href and id
attributes start with "pkg-" to make it impossible for
them to conflict with generated attributes (some of which
correspond to Go identifiers).
-->
<script type='text/javascript'>
document.ANALYSIS_DATA = null;
document.CALLGRAPH = null;
</script>
<div id="short-nav">
<dl>
<dd><code>import "crypto"</code></dd>
</dl>
<dl>
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
<dd><a href="index.html#pkg-subdirectories">Subdirectories</a></dd>
</dl>
</div>
<!-- The package's Name is printed as title by the top-level template -->
<div id="pkg-overview" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
<p>
Package crypto collects common cryptographic constants.
</p>
</div>
</div>
<div id="pkg-index" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
<div id="manual-nav">
<dl>
<dd><a href="index.html#RegisterHash">func RegisterHash(h Hash, f func() hash.Hash)</a></dd>
<dd><a href="index.html#Decrypter">type Decrypter</a></dd>
<dd><a href="index.html#DecrypterOpts">type DecrypterOpts</a></dd>
<dd><a href="index.html#Hash">type Hash</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Hash.Available">func (h Hash) Available() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Hash.HashFunc">func (h Hash) HashFunc() Hash</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Hash.New">func (h Hash) New() hash.Hash</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Hash.Size">func (h Hash) Size() int</a></dd>
<dd><a href="index.html#PrivateKey">type PrivateKey</a></dd>
<dd><a href="index.html#PublicKey">type PublicKey</a></dd>
<dd><a href="index.html#Signer">type Signer</a></dd>
<dd><a href="index.html#SignerOpts">type SignerOpts</a></dd>
</dl>
</div><!-- #manual-nav -->
<h4>Package files</h4>
<p>
<span style="font-size:90%">
<a href="http://localhost:6060/src/crypto/crypto.go">crypto.go</a>
</span>
</p>
</div><!-- .expanded -->
</div><!-- #pkg-index -->
<div id="pkg-callgraph" class="toggle" style="display: none">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
</div> <!-- .expanded -->
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
<p>
In the call graph viewer below, each node
is a function belonging to this package
and its children are the functions it
calls&mdash;perhaps dynamically.
</p>
<p>
The root nodes are the entry points of the
package: functions that may be called from
outside the package.
There may be non-exported or anonymous
functions among them if they are called
dynamically from another package.
</p>
<p>
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring <code>func</code>
token.
</p>
<p>
Functions may be omitted if they were
determined to be unreachable in the
particular programs or tests that were
analyzed.
</p>
<!-- Zero means show all package entry points. -->
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
</div>
</div> <!-- #pkg-callgraph -->
<h2 id="RegisterHash">func <a href="http://localhost:6060/src/crypto/crypto.go?s=2728:2773#L82">RegisterHash</a></h2>
<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>
<p>
RegisterHash registers a function that returns a new instance of the given
hash function. This is intended to be called from the init function in
packages that implement hash functions.
</p>
<h2 id="Decrypter">type <a href="http://localhost:6060/src/crypto/crypto.go?s=4661:5033#L129">Decrypter</a></h2>
<pre>type Decrypter interface {
<span class="comment">// Public returns the public key corresponding to the opaque,</span>
<span class="comment">// private key.</span>
Public() <a href="index.html#PublicKey">PublicKey</a>
<span class="comment">// Decrypt decrypts msg. The opts argument should be appropriate for</span>
<span class="comment">// the primitive used. See the documentation in each implementation for</span>
<span class="comment">// details.</span>
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>)
}</pre>
<p>
Decrypter is an interface for an opaque private key that can be used for
asymmetric decryption operations. An example would be an RSA key
kept in a hardware module.
</p>
<h2 id="DecrypterOpts">type <a href="http://localhost:6060/src/crypto/crypto.go?s=5035:5065#L140">DecrypterOpts</a></h2>
<pre>type DecrypterOpts interface{}</pre>
<h2 id="Hash">type <a href="http://localhost:6060/src/crypto/crypto.go?s=364:378#L6">Hash</a></h2>
<pre>type Hash <a href="../builtin/index.html#uint">uint</a></pre>
<p>
Hash identifies a cryptographic hash function that is implemented in another
package.
</p>
<pre>const (
<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>
<span id="MD5">MD5</span> <span class="comment">// import crypto/md5</span>
<span id="SHA1">SHA1</span> <span class="comment">// import crypto/sha1</span>
<span id="SHA224">SHA224</span> <span class="comment">// import crypto/sha256</span>
<span id="SHA256">SHA256</span> <span class="comment">// import crypto/sha256</span>
<span id="SHA384">SHA384</span> <span class="comment">// import crypto/sha512</span>
<span id="SHA512">SHA512</span> <span class="comment">// import crypto/sha512</span>
<span id="MD5SHA1">MD5SHA1</span> <span class="comment">// no implementation; MD5+SHA1 used for TLS RSA</span>
<span id="RIPEMD160">RIPEMD160</span> <span class="comment">// import golang.org/x/crypto/ripemd160</span>
<span id="SHA3_224">SHA3_224</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
<span id="SHA3_256">SHA3_256</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
<span id="SHA3_384">SHA3_384</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
<span id="SHA3_512">SHA3_512</span> <span class="comment">// import golang.org/x/crypto/sha3</span>
<span id="SHA512_224">SHA512_224</span> <span class="comment">// import crypto/sha512</span>
<span id="SHA512_256">SHA512_256</span> <span class="comment">// import crypto/sha512</span>
)</pre>
<h3 id="Hash.Available">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=2457:2487#L75">Available</a></h3>
<pre>func (h <a href="index.html#Hash">Hash</a>) Available() <a href="../builtin/index.html#bool">bool</a></pre>
<p>
Available reports whether the given hash function is linked into the binary.
</p>
<h3 id="Hash.HashFunc">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=458:487#L9">HashFunc</a></h3>
<pre>func (h <a href="index.html#Hash">Hash</a>) HashFunc() <a href="index.html#Hash">Hash</a></pre>
<p>
HashFunc simply returns the value of h so that Hash implements SignerOpts.
</p>
<h3 id="Hash.New">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=2174:2203#L64">New</a></h3>
<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>
<p>
New returns a new hash.Hash calculating the given hash function. New panics
if the hash function is not linked into the binary.
</p>
<h3 id="Hash.Size">func (Hash) <a href="http://localhost:6060/src/crypto/crypto.go?s=1855:1879#L53">Size</a></h3>
<pre>func (h <a href="index.html#Hash">Hash</a>) Size() <a href="../builtin/index.html#int">int</a></pre>
<p>
Size returns the length, in bytes, of a digest resulting from the given hash
function. It doesn&#39;t require that the hash function in question be linked
into the program.
</p>
<h2 id="PrivateKey">type <a href="http://localhost:6060/src/crypto/crypto.go?s=3041:3068#L93">PrivateKey</a></h2>
<pre>type PrivateKey interface{}</pre>
<p>
PrivateKey represents a private key using an unspecified algorithm.
</p>
<h2 id="PublicKey">type <a href="http://localhost:6060/src/crypto/crypto.go?s=2942:2968#L90">PublicKey</a></h2>
<pre>type PublicKey interface{}</pre>
<p>
PublicKey represents a public key using an unspecified algorithm.
</p>
<h2 id="Signer">type <a href="http://localhost:6060/src/crypto/crypto.go?s=3217:4212#L97">Signer</a></h2>
<pre>type Signer interface {
<span class="comment">// Public returns the public key corresponding to the opaque,</span>
<span class="comment">// private key.</span>
Public() <a href="index.html#PublicKey">PublicKey</a>
<span class="comment">// Sign signs digest with the private key, possibly using entropy from</span>
<span class="comment">// rand. For an RSA key, the resulting signature should be either a</span>
<span class="comment">// PKCS#1 v1.5 or PSS signature (as indicated by opts). For an (EC)DSA</span>
<span class="comment">// key, it should be a DER-serialised, ASN.1 signature structure.</span>
<span class="comment">//</span>
<span class="comment">// Hash implements the SignerOpts interface and, in most cases, one can</span>
<span class="comment">// simply pass in the hash function used as opts. Sign may also attempt</span>
<span class="comment">// to type assert opts to other types in order to obtain algorithm</span>
<span class="comment">// specific values. See the documentation in each package for details.</span>
<span class="comment">//</span>
<span class="comment">// Note that when a signature of a hash of a larger message is needed,</span>
<span class="comment">// the caller is responsible for hashing the larger message and passing</span>
<span class="comment">// the hash (as digest) and the hash function (as opts) to Sign.</span>
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>)
}</pre>
<p>
Signer is an interface for an opaque private key that can be used for
signing operations. For example, an RSA key kept in a hardware module.
</p>
<h2 id="SignerOpts">type <a href="http://localhost:6060/src/crypto/crypto.go?s=4272:4485#L119">SignerOpts</a></h2>
<pre>type SignerOpts interface {
<span class="comment">// HashFunc returns an identifier for the hash function used to produce</span>
<span class="comment">// the message passed to Signer.Sign, or else zero to indicate that no</span>
<span class="comment">// hashing was done.</span>
HashFunc() <a href="index.html#Hash">Hash</a>
}</pre>
<p>
SignerOpts contains options for signing with a Signer.
</p>
<h2 id="pkg-subdirectories">Subdirectories</h2>
<div class="pkg-dir">
<table>
<tr>
<th class="pkg-name">Name</th>
<th class="pkg-synopsis">Synopsis</th>
</tr>
<tr>
<td colspan="2"><a href="http://localhost:6060/pkg/">..</a></td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="aes/index.html">aes</a>
</td>
<td class="pkg-synopsis">
Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="cipher/index.html">cipher</a>
</td>
<td class="pkg-synopsis">
Package cipher implements standard block cipher modes that can be wrapped around low-level block cipher implementations.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="des/index.html">des</a>
</td>
<td class="pkg-synopsis">
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.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="dsa/index.html">dsa</a>
</td>
<td class="pkg-synopsis">
Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="ecdsa/index.html">ecdsa</a>
</td>
<td class="pkg-synopsis">
Package ecdsa implements the Elliptic Curve Digital Signature Algorithm, as defined in FIPS 186-3.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="elliptic/index.html">elliptic</a>
</td>
<td class="pkg-synopsis">
Package elliptic implements several standard elliptic curves over prime fields.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="hmac/index.html">hmac</a>
</td>
<td class="pkg-synopsis">
Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="md5/index.html">md5</a>
</td>
<td class="pkg-synopsis">
Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="rand/index.html">rand</a>
</td>
<td class="pkg-synopsis">
Package rand implements a cryptographically secure pseudorandom number generator.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="rc4/index.html">rc4</a>
</td>
<td class="pkg-synopsis">
Package rc4 implements RC4 encryption, as defined in Bruce Schneier&#39;s Applied Cryptography.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="rsa/index.html">rsa</a>
</td>
<td class="pkg-synopsis">
Package rsa implements RSA encryption as specified in PKCS#1.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="sha1/index.html">sha1</a>
</td>
<td class="pkg-synopsis">
Package sha1 implements the SHA1 hash algorithm as defined in RFC 3174.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="sha256/index.html">sha256</a>
</td>
<td class="pkg-synopsis">
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="sha512/index.html">sha512</a>
</td>
<td class="pkg-synopsis">
Package sha512 implements the SHA-384, SHA-512, SHA-512/224, and SHA-512/256 hash algorithms as defined in FIPS 180-4.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="subtle/index.html">subtle</a>
</td>
<td class="pkg-synopsis">
Package subtle implements functions that are often useful in cryptographic code but require careful thought to use correctly.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="tls/index.html">tls</a>
</td>
<td class="pkg-synopsis">
Package tls partially implements TLS 1.2, as specified in RFC 5246.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="x509/index.html">x509</a>
</td>
<td class="pkg-synopsis">
Package x509 parses X.509-encoded keys and certificates.
</td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 20px;">
<a href="x509/pkix/index.html">pkix</a>
</td>
<td class="pkg-synopsis">
Package pkix contains shared, low level structures used for ASN.1 parsing and serialization of X.509 certificates, CRL and OCSP.
</td>
</tr>
</table>
</div>
<div id="footer">
Build version go1.6.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>
</div><!-- .container -->
</div><!-- #page -->
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
<script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
<script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
<script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
<script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
</body>
</html>