OSDN Git Service

Missed test data in libgo update.
[pf3gnuchains/gcc-fork.git] / libgo / go / crypto / block / cipher.go
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.
4
5 // The block package is deprecated, use cipher instead.
6 // The block package implements standard block cipher modes
7 // that can be wrapped around low-level block cipher implementations.
8 // See http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html
9 // and NIST Special Publication 800-38A.
10 package block
11
12 // A Cipher represents an implementation of block cipher
13 // using a given key.  It provides the capability to encrypt
14 // or decrypt individual blocks.  The mode implementations
15 // extend that capability to streams of blocks.
16 type Cipher interface {
17         // BlockSize returns the cipher's block size.
18         BlockSize() int
19
20         // Encrypt encrypts the first block in src into dst.
21         // Src and dst may point at the same memory.
22         Encrypt(dst, src []byte)
23
24         // Decrypt decrypts the first block in src into dst.
25         // Src and dst may point at the same memory.
26         Decrypt(dst, src []byte)
27 }
28
29 // Utility routines
30
31 func shift1(dst, src []byte) byte {
32         var b byte
33         for i := len(src) - 1; i >= 0; i-- {
34                 bb := src[i] >> 7
35                 dst[i] = src[i]<<1 | b
36                 b = bb
37         }
38         return b
39 }
40
41 func same(p, q []byte) bool {
42         if len(p) != len(q) {
43                 return false
44         }
45         for i := 0; i < len(p); i++ {
46                 if p[i] != q[i] {
47                         return false
48                 }
49         }
50         return true
51 }
52
53 func dup(p []byte) []byte {
54         q := make([]byte, len(p))
55         copy(q, p)
56         return q
57 }