1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package crypto collects common cryptographic constants.
12 // Hash identifies a cryptographic hash function that is implemented in another
17 MD4 Hash
= 1 + iota // import code.google.com/p/go.crypto/md4
18 MD5
// import crypto/md5
19 SHA1
// import crypto/sha1
20 SHA224
// import crypto/sha256
21 SHA256
// import crypto/sha256
22 SHA384
// import crypto/sha512
23 SHA512
// import crypto/sha512
24 MD5SHA1
// no implementation; MD5+SHA1 used for TLS RSA
25 RIPEMD160
// import code.google.com/p/go.crypto/ripemd160
29 var digestSizes
= []uint8{
41 // Size returns the length, in bytes, of a digest resulting from the given hash
42 // function. It doesn't require that the hash function in question be linked
44 func (h Hash
) Size() int {
45 if h
> 0 && h
< maxHash
{
46 return int(digestSizes
[h
])
48 panic("crypto: Size of unknown hash function")
51 var hashes
= make([]func() hash
.Hash
, maxHash
)
53 // New returns a new hash.Hash calculating the given hash function. New panics
54 // if the hash function is not linked into the binary.
55 func (h Hash
) New() hash
.Hash
{
56 if h
> 0 && h
< maxHash
{
62 panic("crypto: requested hash function is unavailable")
65 // Available reports whether the given hash function is linked into the binary.
66 func (h Hash
) Available() bool {
67 return h
< maxHash
&& hashes
[h
] != nil
70 // RegisterHash registers a function that returns a new instance of the given
71 // hash function. This is intended to be called from the init function in
72 // packages that implement hash functions.
73 func RegisterHash(h Hash
, f
func() hash
.Hash
) {
75 panic("crypto: RegisterHash of unknown hash function")
80 // PrivateKey represents a private key using an unspecified algorithm.
81 type PrivateKey
interface{}