LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package rsa | 5 package rsa |
6 | 6 |
7 import ( | 7 import ( |
8 "crypto" | 8 "crypto" |
9 "crypto/subtle" | 9 "crypto/subtle" |
10 "errors" | 10 "errors" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // DigestInfo ::= SEQUENCE { | 144 // DigestInfo ::= SEQUENCE { |
145 // digestAlgorithm AlgorithmIdentifier, | 145 // digestAlgorithm AlgorithmIdentifier, |
146 // digest OCTET STRING | 146 // digest OCTET STRING |
147 // } | 147 // } |
148 // For performance, we don't use the generic ASN1 encoder. Rather, we | 148 // For performance, we don't use the generic ASN1 encoder. Rather, we |
149 // precompute a prefix of the digest value that makes a valid ASN1 DER string | 149 // precompute a prefix of the digest value that makes a valid ASN1 DER string |
150 // with the correct contents. | 150 // with the correct contents. |
151 var hashPrefixes = map[crypto.Hash][]byte{ | 151 var hashPrefixes = map[crypto.Hash][]byte{ |
152 crypto.MD5: {0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10}, | 152 crypto.MD5: {0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10}, |
153 crypto.SHA1: {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}, | 153 crypto.SHA1: {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}, |
| 154 crypto.SHA224: {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c}, |
154 crypto.SHA256: {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}, | 155 crypto.SHA256: {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}, |
155 crypto.SHA384: {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}, | 156 crypto.SHA384: {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}, |
156 crypto.SHA512: {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}, | 157 crypto.SHA512: {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}, |
157 crypto.MD5SHA1: {}, // A special TLS case which doesn't use an ASN1 pr
efix. | 158 crypto.MD5SHA1: {}, // A special TLS case which doesn't use an ASN1 pr
efix. |
158 crypto.RIPEMD160: {0x30, 0x20, 0x30, 0x08, 0x06, 0x06, 0x28, 0xcf, 0x06,
0x03, 0x00, 0x31, 0x04, 0x14}, | 159 crypto.RIPEMD160: {0x30, 0x20, 0x30, 0x08, 0x06, 0x06, 0x28, 0xcf, 0x06,
0x03, 0x00, 0x31, 0x04, 0x14}, |
159 } | 160 } |
160 | 161 |
161 // SignPKCS1v15 calculates the signature of hashed using RSASSA-PKCS1-V1_5-SIGN
from RSA PKCS#1 v1.5. | 162 // SignPKCS1v15 calculates the signature of hashed using RSASSA-PKCS1-V1_5-SIGN
from RSA PKCS#1 v1.5. |
162 // Note that hashed must be the result of hashing the input message using the | 163 // Note that hashed must be the result of hashing the input message using the |
163 // given hash function. | 164 // given hash function. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 hashLen = hash.Size() | 234 hashLen = hash.Size() |
234 if inLen != hashLen { | 235 if inLen != hashLen { |
235 return 0, nil, errors.New("crypto/rsa: input must be hashed mess
age") | 236 return 0, nil, errors.New("crypto/rsa: input must be hashed mess
age") |
236 } | 237 } |
237 prefix, ok := hashPrefixes[hash] | 238 prefix, ok := hashPrefixes[hash] |
238 if !ok { | 239 if !ok { |
239 return 0, nil, errors.New("crypto/rsa: unsupported hash function
") | 240 return 0, nil, errors.New("crypto/rsa: unsupported hash function
") |
240 } | 241 } |
241 return | 242 return |
242 } | 243 } |
LEFT | RIGHT |