OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [crypto/] [cipher/] [ofb.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 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
// OFB (Output Feedback) Mode.
6
 
7
package cipher
8
 
9
type ofb struct {
10
        b       Block
11
        out     []byte
12
        outUsed int
13
}
14
 
15
// NewOFB returns a Stream that encrypts or decrypts using the block cipher b
16
// in output feedback mode. The initialization vector iv's length must be equal
17
// to b's block size.
18
func NewOFB(b Block, iv []byte) Stream {
19
        blockSize := b.BlockSize()
20
        if len(iv) != blockSize {
21
                return nil
22
        }
23
 
24
        x := &ofb{
25
                b:       b,
26
                out:     make([]byte, blockSize),
27
                outUsed: 0,
28
        }
29
        b.Encrypt(x.out, iv)
30
 
31
        return x
32
}
33
 
34
func (x *ofb) XORKeyStream(dst, src []byte) {
35
        for i, s := range src {
36
                if x.outUsed == len(x.out) {
37
                        x.b.Encrypt(x.out, x.out)
38
                        x.outUsed = 0
39
                }
40
 
41
                dst[i] = s ^ x.out[x.outUsed]
42
                x.outUsed++
43
        }
44
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.