1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<h1> Package dsa </h1> <ul id="short-nav">
<li><code>import "crypto/dsa"</code></li>
<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
<li><a href="#pkg-index" class="indexLink">Index</a></li>
</ul> <h2 id="pkg-overview">Overview </h2> <p>Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3. </p>
<p>The DSA operations in this package are not implemented using constant-time algorithms. </p>
<p>Deprecated: DSA is a legacy algorithm, and modern alternatives such as Ed25519 (implemented by package crypto/ed25519) should be used instead. Keys with 1024-bit moduli (L1024N160 parameters) are cryptographically weak, while bigger keys are not widely supported. Note that FIPS 186-5 no longer approves DSA for signature generation. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
<li><a href="#pkg-variables">Variables</a></li>
<li><a href="#GenerateKey">func GenerateKey(priv *PrivateKey, rand io.Reader) error</a></li>
<li><a href="#GenerateParameters">func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error</a></li>
<li><a href="#Sign">func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)</a></li>
<li><a href="#Verify">func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool</a></li>
<li><a href="#ParameterSizes">type ParameterSizes</a></li>
<li><a href="#Parameters">type Parameters</a></li>
<li><a href="#PrivateKey">type PrivateKey</a></li>
<li><a href="#PublicKey">type PublicKey</a></li>
</ul> <h3>Package files</h3> <p> <span>dsa.go</span> </p> <h2 id="pkg-variables">Variables</h2> <p>ErrInvalidPublicKey results when a public key is not usable by this code. FIPS is quite strict about the format of DSA keys, but other code may be less so. Thus, when using keys which may have been generated by other code, this error must be handled. </p>
<pre data-language="go">var ErrInvalidPublicKey = errors.New("crypto/dsa: invalid public key")</pre> <h2 id="GenerateKey">func <span>GenerateKey</span> </h2> <pre data-language="go">func GenerateKey(priv *PrivateKey, rand io.Reader) error</pre> <p>GenerateKey generates a public&private key pair. The Parameters of the <a href="#PrivateKey">PrivateKey</a> must already be valid (see <a href="#GenerateParameters">GenerateParameters</a>). </p>
<h2 id="GenerateParameters">func <span>GenerateParameters</span> </h2> <pre data-language="go">func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error</pre> <p>GenerateParameters puts a random, valid set of DSA parameters into params. This function can take many seconds, even on fast machines. </p>
<h2 id="Sign">func <span>Sign</span> </h2> <pre data-language="go">func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)</pre> <p>Sign signs an arbitrary length hash (which should be the result of hashing a larger message) using the private key, priv. It returns the signature as a pair of integers. The security of the private key depends on the entropy of rand. </p>
<p>Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated to the byte-length of the subgroup. This function does not perform that truncation itself. </p>
<p>Be aware that calling Sign with an attacker-controlled <a href="#PrivateKey">PrivateKey</a> may require an arbitrary amount of CPU. </p>
<h2 id="Verify">func <span>Verify</span> </h2> <pre data-language="go">func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool</pre> <p>Verify verifies the signature in r, s of hash using the public key, pub. It reports whether the signature is valid. </p>
<p>Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated to the byte-length of the subgroup. This function does not perform that truncation itself. </p>
<h2 id="ParameterSizes">type <span>ParameterSizes</span> </h2> <p>ParameterSizes is an enumeration of the acceptable bit lengths of the primes in a set of DSA parameters. See FIPS 186-3, section 4.2. </p>
<pre data-language="go">type ParameterSizes int</pre> <pre data-language="go">const (
L1024N160 ParameterSizes = iota
L2048N224
L2048N256
L3072N256
)</pre> <h2 id="Parameters">type <span>Parameters</span> </h2> <p>Parameters represents the domain parameters for a key. These parameters can be shared across many keys. The bit length of Q must be a multiple of 8. </p>
<pre data-language="go">type Parameters struct {
P, Q, G *big.Int
}
</pre> <h2 id="PrivateKey">type <span>PrivateKey</span> </h2> <p>PrivateKey represents a DSA private key. </p>
<pre data-language="go">type PrivateKey struct {
PublicKey
X *big.Int
}
</pre> <h2 id="PublicKey">type <span>PublicKey</span> </h2> <p>PublicKey represents a DSA public key. </p>
<pre data-language="go">type PublicKey struct {
Parameters
Y *big.Int
}
</pre><div class="_attribution">
<p class="_attribution-p">
© Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
<a href="http://golang.org/pkg/crypto/dsa/" class="_attribution-link">http://golang.org/pkg/crypto/dsa/</a>
</p>
</div>
|