1 // Copyright 2010 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.
20 "golang.org/x/crypto/chacha20poly1305"
23 // CipherSuite is a TLS cipher suite. Note that most functions in this package
24 // accept and expose cipher suite IDs instead of this type.
25 type CipherSuite struct {
29 // Supported versions is the list of TLS protocol versions that can
30 // negotiate this cipher suite.
31 SupportedVersions []uint16
33 // Insecure is true if the cipher suite has known security issues
34 // due to its primitives, design, or implementation.
39 supportedUpToTLS12 = []uint16{VersionTLS10, VersionTLS11, VersionTLS12}
40 supportedOnlyTLS12 = []uint16{VersionTLS12}
41 supportedOnlyTLS13 = []uint16{VersionTLS13}
44 // CipherSuites returns a list of cipher suites currently implemented by this
45 // package, excluding those with security issues, which are returned by
46 // InsecureCipherSuites.
48 // The list is sorted by ID. Note that the default cipher suites selected by
49 // this package might depend on logic that can't be captured by a static list.
50 func CipherSuites() []*CipherSuite {
51 return []*CipherSuite{
52 {TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_RSA_WITH_3DES_EDE_CBC_SHA", supportedUpToTLS12, false},
53 {TLS_RSA_WITH_AES_128_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA", supportedUpToTLS12, false},
54 {TLS_RSA_WITH_AES_256_CBC_SHA, "TLS_RSA_WITH_AES_256_CBC_SHA", supportedUpToTLS12, false},
55 {TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS_RSA_WITH_AES_128_GCM_SHA256", supportedOnlyTLS12, false},
56 {TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS_RSA_WITH_AES_256_GCM_SHA384", supportedOnlyTLS12, false},
58 {TLS_AES_128_GCM_SHA256, "TLS_AES_128_GCM_SHA256", supportedOnlyTLS13, false},
59 {TLS_AES_256_GCM_SHA384, "TLS_AES_256_GCM_SHA384", supportedOnlyTLS13, false},
60 {TLS_CHACHA20_POLY1305_SHA256, "TLS_CHACHA20_POLY1305_SHA256", supportedOnlyTLS13, false},
62 {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", supportedUpToTLS12, false},
63 {TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", supportedUpToTLS12, false},
64 {TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", supportedUpToTLS12, false},
65 {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", supportedUpToTLS12, false},
66 {TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", supportedUpToTLS12, false},
67 {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", supportedOnlyTLS12, false},
68 {TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", supportedOnlyTLS12, false},
69 {TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", supportedOnlyTLS12, false},
70 {TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", supportedOnlyTLS12, false},
71 {TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", supportedOnlyTLS12, false},
72 {TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", supportedOnlyTLS12, false},
76 // InsecureCipherSuites returns a list of cipher suites currently implemented by
77 // this package and which have security issues.
79 // Most applications should not use the cipher suites in this list, and should
80 // only use those returned by CipherSuites.
81 func InsecureCipherSuites() []*CipherSuite {
82 // RC4 suites are broken because RC4 is.
83 // CBC-SHA256 suites have no Lucky13 countermeasures.
84 return []*CipherSuite{
85 {TLS_RSA_WITH_RC4_128_SHA, "TLS_RSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
86 {TLS_RSA_WITH_AES_128_CBC_SHA256, "TLS_RSA_WITH_AES_128_CBC_SHA256", supportedOnlyTLS12, true},
87 {TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
88 {TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS_ECDHE_RSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
89 {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", supportedOnlyTLS12, true},
90 {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", supportedOnlyTLS12, true},
94 // CipherSuiteName returns the standard name for the passed cipher suite ID
95 // (e.g. "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"), or a fallback representation
96 // of the ID value if the cipher suite is not implemented by this package.
97 func CipherSuiteName(id uint16) string {
98 for _, c := range CipherSuites() {
103 for _, c := range InsecureCipherSuites() {
108 return fmt.Sprintf("0x%04X", id)
111 // a keyAgreement implements the client and server side of a TLS key agreement
112 // protocol by generating and processing key exchange messages.
113 type keyAgreement interface {
114 // On the server side, the first two methods are called in order.
116 // In the case that the key agreement protocol doesn't use a
117 // ServerKeyExchange message, generateServerKeyExchange can return nil,
119 generateServerKeyExchange(*Config, *Certificate, *clientHelloMsg, *serverHelloMsg) (*serverKeyExchangeMsg, error)
120 processClientKeyExchange(*Config, *Certificate, *clientKeyExchangeMsg, uint16) ([]byte, error)
122 // On the client side, the next two methods are called in order.
124 // This method may not be called if the server doesn't send a
125 // ServerKeyExchange message.
126 processServerKeyExchange(*Config, *clientHelloMsg, *serverHelloMsg, *x509.Certificate, *serverKeyExchangeMsg) error
127 generateClientKeyExchange(*Config, *clientHelloMsg, *x509.Certificate) ([]byte, *clientKeyExchangeMsg, error)
131 // suiteECDHE indicates that the cipher suite involves elliptic curve
132 // Diffie-Hellman. This means that it should only be selected when the
133 // client indicates that it supports ECC with a curve and point format
134 // that we're happy with.
135 suiteECDHE = 1 << iota
136 // suiteECSign indicates that the cipher suite involves an ECDSA or
137 // EdDSA signature and therefore may only be selected when the server's
138 // certificate is ECDSA or EdDSA. If this is not set then the cipher suite
141 // suiteTLS12 indicates that the cipher suite should only be advertised
142 // and accepted when using TLS 1.2.
144 // suiteSHA384 indicates that the cipher suite uses SHA384 as the
147 // suiteDefaultOff indicates that this cipher suite is not included by
152 // A cipherSuite is a specific combination of key agreement, cipher and MAC function.
153 type cipherSuite struct {
155 // the lengths, in bytes, of the key material needed for each component.
159 ka func(version uint16) keyAgreement
160 // flags is a bitmask of the suite* values, above.
162 cipher func(key, iv []byte, isRead bool) interface{}
163 mac func(key []byte) hash.Hash
164 aead func(key, fixedNonce []byte) aead
167 var cipherSuites = []*cipherSuite{
168 // Ciphersuite order is chosen so that ECDHE comes before plain RSA and
169 // AEADs are the top preference.
170 {TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, 32, 0, 12, ecdheRSAKA, suiteECDHE | suiteTLS12, nil, nil, aeadChaCha20Poly1305},
171 {TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, 32, 0, 12, ecdheECDSAKA, suiteECDHE | suiteECSign | suiteTLS12, nil, nil, aeadChaCha20Poly1305},
172 {TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheRSAKA, suiteECDHE | suiteTLS12, nil, nil, aeadAESGCM},
173 {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheECDSAKA, suiteECDHE | suiteECSign | suiteTLS12, nil, nil, aeadAESGCM},
174 {TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, ecdheRSAKA, suiteECDHE | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
175 {TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, ecdheECDSAKA, suiteECDHE | suiteECSign | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
176 {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, ecdheRSAKA, suiteECDHE | suiteTLS12 | suiteDefaultOff, cipherAES, macSHA256, nil},
177 {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
178 {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, ecdheECDSAKA, suiteECDHE | suiteECSign | suiteTLS12 | suiteDefaultOff, cipherAES, macSHA256, nil},
179 {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECSign, cipherAES, macSHA1, nil},
180 {TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
181 {TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECSign, cipherAES, macSHA1, nil},
182 {TLS_RSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, rsaKA, suiteTLS12, nil, nil, aeadAESGCM},
183 {TLS_RSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, rsaKA, suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
184 {TLS_RSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, rsaKA, suiteTLS12 | suiteDefaultOff, cipherAES, macSHA256, nil},
185 {TLS_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
186 {TLS_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
187 {TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, ecdheRSAKA, suiteECDHE, cipher3DES, macSHA1, nil},
188 {TLS_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, rsaKA, 0, cipher3DES, macSHA1, nil},
190 // RC4-based cipher suites are disabled by default.
191 {TLS_RSA_WITH_RC4_128_SHA, 16, 20, 0, rsaKA, suiteDefaultOff, cipherRC4, macSHA1, nil},
192 {TLS_ECDHE_RSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheRSAKA, suiteECDHE | suiteDefaultOff, cipherRC4, macSHA1, nil},
193 {TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheECDSAKA, suiteECDHE | suiteECSign | suiteDefaultOff, cipherRC4, macSHA1, nil},
196 // selectCipherSuite returns the first cipher suite from ids which is also in
197 // supportedIDs and passes the ok filter.
198 func selectCipherSuite(ids, supportedIDs []uint16, ok func(*cipherSuite) bool) *cipherSuite {
199 for _, id := range ids {
200 candidate := cipherSuiteByID(id)
201 if candidate == nil || !ok(candidate) {
205 for _, suppID := range supportedIDs {
214 // A cipherSuiteTLS13 defines only the pair of the AEAD algorithm and hash
215 // algorithm to be used with HKDF. See RFC 8446, Appendix B.4.
216 type cipherSuiteTLS13 struct {
219 aead func(key, fixedNonce []byte) aead
223 var cipherSuitesTLS13 = []*cipherSuiteTLS13{
224 {TLS_AES_128_GCM_SHA256, 16, aeadAESGCMTLS13, crypto.SHA256},
225 {TLS_CHACHA20_POLY1305_SHA256, 32, aeadChaCha20Poly1305, crypto.SHA256},
226 {TLS_AES_256_GCM_SHA384, 32, aeadAESGCMTLS13, crypto.SHA384},
229 func cipherRC4(key, iv []byte, isRead bool) interface{} {
230 cipher, _ := rc4.NewCipher(key)
234 func cipher3DES(key, iv []byte, isRead bool) interface{} {
235 block, _ := des.NewTripleDESCipher(key)
237 return cipher.NewCBCDecrypter(block, iv)
239 return cipher.NewCBCEncrypter(block, iv)
242 func cipherAES(key, iv []byte, isRead bool) interface{} {
243 block, _ := aes.NewCipher(key)
245 return cipher.NewCBCDecrypter(block, iv)
247 return cipher.NewCBCEncrypter(block, iv)
250 // macSHA1 returns a SHA-1 based constant time MAC.
251 func macSHA1(key []byte) hash.Hash {
252 return hmac.New(newConstantTimeHash(sha1.New), key)
255 // macSHA256 returns a SHA-256 based MAC. This is only supported in TLS 1.2 and
256 // is currently only used in disabled-by-default cipher suites.
257 func macSHA256(key []byte) hash.Hash {
258 return hmac.New(sha256.New, key)
261 type aead interface {
264 // explicitNonceLen returns the number of bytes of explicit nonce
265 // included in each record. This is eight for older AEADs and
266 // zero for modern ones.
267 explicitNonceLen() int
272 noncePrefixLength = 4
275 // prefixNonceAEAD wraps an AEAD and prefixes a fixed portion of the nonce to
277 type prefixNonceAEAD struct {
278 // nonce contains the fixed part of the nonce in the first four bytes.
279 nonce [aeadNonceLength]byte
283 func (f *prefixNonceAEAD) NonceSize() int { return aeadNonceLength - noncePrefixLength }
284 func (f *prefixNonceAEAD) Overhead() int { return f.aead.Overhead() }
285 func (f *prefixNonceAEAD) explicitNonceLen() int { return f.NonceSize() }
287 func (f *prefixNonceAEAD) Seal(out, nonce, plaintext, additionalData []byte) []byte {
288 copy(f.nonce[4:], nonce)
289 return f.aead.Seal(out, f.nonce[:], plaintext, additionalData)
292 func (f *prefixNonceAEAD) Open(out, nonce, ciphertext, additionalData []byte) ([]byte, error) {
293 copy(f.nonce[4:], nonce)
294 return f.aead.Open(out, f.nonce[:], ciphertext, additionalData)
297 // xoredNonceAEAD wraps an AEAD by XORing in a fixed pattern to the nonce
299 type xorNonceAEAD struct {
300 nonceMask [aeadNonceLength]byte
304 func (f *xorNonceAEAD) NonceSize() int { return 8 } // 64-bit sequence number
305 func (f *xorNonceAEAD) Overhead() int { return f.aead.Overhead() }
306 func (f *xorNonceAEAD) explicitNonceLen() int { return 0 }
308 func (f *xorNonceAEAD) Seal(out, nonce, plaintext, additionalData []byte) []byte {
309 for i, b := range nonce {
310 f.nonceMask[4+i] ^= b
312 result := f.aead.Seal(out, f.nonceMask[:], plaintext, additionalData)
313 for i, b := range nonce {
314 f.nonceMask[4+i] ^= b
320 func (f *xorNonceAEAD) Open(out, nonce, ciphertext, additionalData []byte) ([]byte, error) {
321 for i, b := range nonce {
322 f.nonceMask[4+i] ^= b
324 result, err := f.aead.Open(out, f.nonceMask[:], ciphertext, additionalData)
325 for i, b := range nonce {
326 f.nonceMask[4+i] ^= b
332 func aeadAESGCM(key, noncePrefix []byte) aead {
333 if len(noncePrefix) != noncePrefixLength {
334 panic("tls: internal error: wrong nonce length")
336 aes, err := aes.NewCipher(key)
340 aead, err := cipher.NewGCM(aes)
345 ret := &prefixNonceAEAD{aead: aead}
346 copy(ret.nonce[:], noncePrefix)
350 func aeadAESGCMTLS13(key, nonceMask []byte) aead {
351 if len(nonceMask) != aeadNonceLength {
352 panic("tls: internal error: wrong nonce length")
354 aes, err := aes.NewCipher(key)
358 aead, err := cipher.NewGCM(aes)
363 ret := &xorNonceAEAD{aead: aead}
364 copy(ret.nonceMask[:], nonceMask)
368 func aeadChaCha20Poly1305(key, nonceMask []byte) aead {
369 if len(nonceMask) != aeadNonceLength {
370 panic("tls: internal error: wrong nonce length")
372 aead, err := chacha20poly1305.New(key)
377 ret := &xorNonceAEAD{aead: aead}
378 copy(ret.nonceMask[:], nonceMask)
382 type constantTimeHash interface {
384 ConstantTimeSum(b []byte) []byte
387 // cthWrapper wraps any hash.Hash that implements ConstantTimeSum, and replaces
388 // with that all calls to Sum. It's used to obtain a ConstantTimeSum-based HMAC.
389 type cthWrapper struct {
393 func (c *cthWrapper) Size() int { return c.h.Size() }
394 func (c *cthWrapper) BlockSize() int { return c.h.BlockSize() }
395 func (c *cthWrapper) Reset() { c.h.Reset() }
396 func (c *cthWrapper) Write(p []byte) (int, error) { return c.h.Write(p) }
397 func (c *cthWrapper) Sum(b []byte) []byte { return c.h.ConstantTimeSum(b) }
399 func newConstantTimeHash(h func() hash.Hash) func() hash.Hash {
400 return func() hash.Hash {
401 return &cthWrapper{h().(constantTimeHash)}
405 // tls10MAC implements the TLS 1.0 MAC function. RFC 2246, Section 6.2.3.
406 func tls10MAC(h hash.Hash, out, seq, header, data, extra []byte) []byte {
418 func rsaKA(version uint16) keyAgreement {
419 return rsaKeyAgreement{}
422 func ecdheECDSAKA(version uint16) keyAgreement {
423 return &ecdheKeyAgreement{
429 func ecdheRSAKA(version uint16) keyAgreement {
430 return &ecdheKeyAgreement{
436 // mutualCipherSuite returns a cipherSuite given a list of supported
437 // ciphersuites and the id requested by the peer.
438 func mutualCipherSuite(have []uint16, want uint16) *cipherSuite {
439 for _, id := range have {
441 return cipherSuiteByID(id)
447 func cipherSuiteByID(id uint16) *cipherSuite {
448 for _, cipherSuite := range cipherSuites {
449 if cipherSuite.id == id {
456 func mutualCipherSuiteTLS13(have []uint16, want uint16) *cipherSuiteTLS13 {
457 for _, id := range have {
459 return cipherSuiteTLS13ByID(id)
465 func cipherSuiteTLS13ByID(id uint16) *cipherSuiteTLS13 {
466 for _, cipherSuite := range cipherSuitesTLS13 {
467 if cipherSuite.id == id {
474 // A list of cipher suite IDs that are, or have been, implemented by this
477 // See https://www.iana.org/assignments/tls-parameters/tls-parameters.xml
479 // TLS 1.0 - 1.2 cipher suites.
480 TLS_RSA_WITH_RC4_128_SHA uint16 = 0x0005
481 TLS_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0x000a
482 TLS_RSA_WITH_AES_128_CBC_SHA uint16 = 0x002f
483 TLS_RSA_WITH_AES_256_CBC_SHA uint16 = 0x0035
484 TLS_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0x003c
485 TLS_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0x009c
486 TLS_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0x009d
487 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA uint16 = 0xc007
488 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA uint16 = 0xc009
489 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA uint16 = 0xc00a
490 TLS_ECDHE_RSA_WITH_RC4_128_SHA uint16 = 0xc011
491 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc012
492 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA uint16 = 0xc013
493 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 = 0xc014
494 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc023
495 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc027
496 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02f
497 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02b
498 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc030
499 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc02c
500 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca8
501 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca9
503 // TLS 1.3 cipher suites.
504 TLS_AES_128_GCM_SHA256 uint16 = 0x1301
505 TLS_AES_256_GCM_SHA384 uint16 = 0x1302
506 TLS_CHACHA20_POLY1305_SHA256 uint16 = 0x1303
508 // TLS_FALLBACK_SCSV isn't a standard cipher suite but an indicator
509 // that the client is doing version fallback. See RFC 7507.
510 TLS_FALLBACK_SCSV uint16 = 0x5600
512 // Legacy names for the corresponding cipher suites with the correct _SHA256
513 // suffix, retained for backward compatibility.
514 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 = TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
515 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 = TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256