1 // Copyright 2009 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.
12 // The AES block size in bytes.
15 // A Cipher is an instance of AES encryption using a particular key.
23 func (k KeySizeError
) String() string {
24 return "crypto/aes: invalid key size " + strconv
.Itoa(int(k
))
27 // NewCipher creates and returns a new Cipher.
28 // The key argument should be the AES key,
29 // either 16, 24, or 32 bytes to select
30 // AES-128, AES-192, or AES-256.
31 func NewCipher(key
[]byte) (*Cipher
, os
.Error
) {
35 return nil, KeySizeError(k
)
41 c
:= &Cipher
{make([]uint32, n
), make([]uint32, n
)}
42 expandKey(key
, c
.enc
, c
.dec
)
46 // BlockSize returns the AES block size, 16 bytes.
47 // It is necessary to satisfy the Cipher interface in the
48 // package "crypto/block".
49 func (c
*Cipher
) BlockSize() int { return BlockSize
}
51 // Encrypt encrypts the 16-byte buffer src using the key k
52 // and stores the result in dst.
53 // Note that for amounts of data larger than a block,
54 // it is not safe to just call Encrypt on successive blocks;
55 // instead, use an encryption mode like CBC (see crypto/block/cbc.go).
56 func (c
*Cipher
) Encrypt(dst
, src
[]byte) { encryptBlock(c
.enc
, dst
, src
) }
58 // Decrypt decrypts the 16-byte buffer src using the key k
59 // and stores the result in dst.
60 func (c
*Cipher
) Decrypt(dst
, src
[]byte) { decryptBlock(c
.dec
, dst
, src
) }
62 // Reset zeros the key data, so that it will no longer
63 // appear in the process's memory.
64 func (c
*Cipher
) Reset() {
65 for i
:= 0; i
< len(c
.enc
); i
++ {
68 for i
:= 0; i
< len(c
.dec
); i
++ {