📄 cfbblockcipher.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: CFBBlockCipher.java
package org.bouncycastle.crypto.modes;
import org.bouncycastle.crypto.*;
import org.bouncycastle.crypto.params.ParametersWithIV;
public class CFBBlockCipher
implements BlockCipher
{
private byte IV[];
private byte cfbV[];
private byte cfbOutV[];
private int blockSize;
private BlockCipher cipher;
private boolean encrypting;
public CFBBlockCipher(BlockCipher cipher, int bitBlockSize)
{
this.cipher = null;
this.cipher = cipher;
blockSize = bitBlockSize / 8;
IV = new byte[cipher.getBlockSize()];
cfbV = new byte[cipher.getBlockSize()];
cfbOutV = new byte[cipher.getBlockSize()];
}
public BlockCipher getUnderlyingCipher()
{
return cipher;
}
public void init(boolean encrypting, CipherParameters params)
throws IllegalArgumentException
{
this.encrypting = encrypting;
if (params instanceof ParametersWithIV)
{
ParametersWithIV ivParam = (ParametersWithIV)params;
byte iv[] = ivParam.getIV();
if (iv.length < IV.length)
{
System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
for (int i = 0; i < IV.length - iv.length; i++)
IV[i] = 0;
} else
{
System.arraycopy(iv, 0, IV, 0, IV.length);
}
reset();
cipher.init(true, ivParam.getParameters());
} else
{
reset();
cipher.init(true, params);
}
}
public String getAlgorithmName()
{
return (new StringBuilder()).append(cipher.getAlgorithmName()).append("/CFB").append(blockSize * 8).toString();
}
public int getBlockSize()
{
return blockSize;
}
public int processBlock(byte in[], int inOff, byte out[], int outOff)
throws DataLengthException, IllegalStateException
{
return encrypting ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff);
}
public int encryptBlock(byte in[], int inOff, byte out[], int outOff)
throws DataLengthException, IllegalStateException
{
if (inOff + blockSize > in.length)
throw new DataLengthException("input buffer too short");
if (outOff + blockSize > out.length)
throw new DataLengthException("output buffer too short");
cipher.processBlock(cfbV, 0, cfbOutV, 0);
for (int i = 0; i < blockSize; i++)
out[outOff + i] = (byte)(cfbOutV[i] ^ in[inOff + i]);
System.arraycopy(cfbV, blockSize, cfbV, 0, cfbV.length - blockSize);
System.arraycopy(out, outOff, cfbV, cfbV.length - blockSize, blockSize);
return blockSize;
}
public int decryptBlock(byte in[], int inOff, byte out[], int outOff)
throws DataLengthException, IllegalStateException
{
if (inOff + blockSize > in.length)
throw new DataLengthException("input buffer too short");
if (outOff + blockSize > out.length)
throw new DataLengthException("output buffer too short");
cipher.processBlock(cfbV, 0, cfbOutV, 0);
System.arraycopy(cfbV, blockSize, cfbV, 0, cfbV.length - blockSize);
System.arraycopy(in, inOff, cfbV, cfbV.length - blockSize, blockSize);
for (int i = 0; i < blockSize; i++)
out[outOff + i] = (byte)(cfbOutV[i] ^ in[inOff + i]);
return blockSize;
}
public void reset()
{
System.arraycopy(IV, 0, cfbV, 0, IV.length);
cipher.reset();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -