~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/crypto/cipher/cbc.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
// mode, using the given Block. The length of iv must be the same as the
34
34
// Block's block size.
35
35
func NewCBCEncrypter(b Block, iv []byte) BlockMode {
 
36
        if len(iv) != b.BlockSize() {
 
37
                panic("cipher.NewCBCEncrypter: IV length must equal block size")
 
38
        }
36
39
        return (*cbcEncrypter)(newCBC(b, iv))
37
40
}
38
41
 
39
42
func (x *cbcEncrypter) BlockSize() int { return x.blockSize }
40
43
 
41
44
func (x *cbcEncrypter) CryptBlocks(dst, src []byte) {
 
45
        if len(src)%x.blockSize != 0 {
 
46
                panic("crypto/cipher: input not full blocks")
 
47
        }
 
48
        if len(dst) < len(src) {
 
49
                panic("crypto/cipher: output smaller than input")
 
50
        }
42
51
        for len(src) > 0 {
43
52
                for i := 0; i < x.blockSize; i++ {
44
53
                        x.iv[i] ^= src[i]
58
67
// mode, using the given Block. The length of iv must be the same as the
59
68
// Block's block size and must match the iv used to encrypt the data.
60
69
func NewCBCDecrypter(b Block, iv []byte) BlockMode {
 
70
        if len(iv) != b.BlockSize() {
 
71
                panic("cipher.NewCBCDecrypter: IV length must equal block size")
 
72
        }
61
73
        return (*cbcDecrypter)(newCBC(b, iv))
62
74
}
63
75
 
64
76
func (x *cbcDecrypter) BlockSize() int { return x.blockSize }
65
77
 
66
78
func (x *cbcDecrypter) CryptBlocks(dst, src []byte) {
 
79
        if len(src)%x.blockSize != 0 {
 
80
                panic("crypto/cipher: input not full blocks")
 
81
        }
 
82
        if len(dst) < len(src) {
 
83
                panic("crypto/cipher: output smaller than input")
 
84
        }
67
85
        for len(src) > 0 {
68
86
                x.b.Decrypt(x.tmp, src[:x.blockSize])
69
87
                for i := 0; i < x.blockSize; i++ {