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.
5 // The block package implements standard block cipher modes
6 // that can be wrapped around low-level block cipher implementations.
7 // See http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html
8 // and NIST Special Publication 800-38A.
11 // A Cipher represents an implementation of block cipher
12 // using a given key. It provides the capability to encrypt
13 // or decrypt individual blocks. The mode implementations
14 // extend that capability to streams of blocks.
15 type Cipher
interface {
16 // BlockSize returns the cipher's block size.
19 // Encrypt encrypts the first block in src into dst.
20 // Src and dst may point at the same memory.
21 Encrypt(dst
, src
[]byte)
23 // Decrypt decrypts the first block in src into dst.
24 // Src and dst may point at the same memory.
25 Decrypt(dst
, src
[]byte)
30 func shift1(dst
, src
[]byte) byte {
32 for i
:= len(src
) - 1; i
>= 0; i
-- {
34 dst
[i
] = src
[i
]<<1 | b
40 func same(p
, q
[]byte) bool {
44 for i
:= 0; i
< len(p
); i
++ {
52 func dup(p
[]byte) []byte {
53 q
:= make([]byte, len(p
))