| // Copyright 2011 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // OFB (Output Feedback) Mode. |
| // NewOFB returns a Stream that encrypts or decrypts using the block cipher b |
| // in output feedback mode. The initialization vector iv's length must be equal |
| func NewOFB(b Block, iv []byte) Stream { |
| blockSize := b.BlockSize() |
| if len(iv) != blockSize { |
| out: make([]byte, blockSize), |
| func (x *ofb) XORKeyStream(dst, src []byte) { |
| if x.outUsed == len(x.out) { |
| x.b.Encrypt(x.out, x.out) |
| dst[i] = s ^ x.out[x.outUsed] |