wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.bouncycastle.shaded.crypto;
 
/**
 * A parent class for block cipher modes that do not require block aligned data to be processed, but can function in
 * a streaming mode.
 */
public abstract class StreamBlockCipher
    extends DefaultMultiBlockCipher
    implements StreamCipher
{
    private final BlockCipher cipher;
 
    protected StreamBlockCipher(BlockCipher cipher)
    {
        this.cipher = cipher;
    }
 
    /**
     * return the underlying block cipher that we are wrapping.
     *
     * @return the underlying block cipher that we are wrapping.
     */
    public BlockCipher getUnderlyingCipher()
    {
        return cipher;
    }
 
    public final byte returnByte(byte in)
    {
        return calculateByte(in);
    }
 
    public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff)
        throws DataLengthException
    {
        if (inOff + len > in.length)
        {
            throw new DataLengthException("input buffer too small");
        }
        if (outOff + len > out.length)
        {
            throw new OutputLengthException("output buffer too short");
        }
 
        int inStart = inOff;
        int inEnd = inOff + len;
        int outStart = outOff;
 
        while (inStart < inEnd)
        {
             out[outStart++] = calculateByte(in[inStart++]);
        }
 
        return len;
    }
 
    protected abstract byte calculateByte(byte b);
}