Top Description Fields Constructors Methods
org.bouncycastle.crypto.engines

public Class RC564Engine

extends Object
implements BlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.BlockCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .CryptoServicesRegistrar, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.params.RC5Parameters

The specification for RC5 came from the RC5 Encryption Algorithm publication in RSA CryptoBytes, Spring of 1995. https://www.rsasecurity.com/rsalabs/cryptobytes.

This implementation is set to work with a 64 bit word size.

Field Summary

Modifier and TypeField and Description
private int
private long[]
private static final int
private boolean
private static final long
private static final long
private static final int

Constructor Summary

AccessConstructor and Description
public
RC564Engine()

Create an instance of the RC5 encryption algorithm and set some defaults

Method Summary

Modifier and TypeMethod and Description
private long
bytesToWord(byte[] src, int srcOff)

private int
decryptBlock(byte[] in, int inOff, byte[] out, int outOff)

private int
encryptBlock(byte[]
in byte buffer containing data to encrypt
in
,
int
offset into src buffer
inOff
,
byte[]
out buffer where encrypted data is written
out
,
int
offset into out buffer
outOff
)

Encrypt the given block starting at the given offset and place the result in the provided buffer starting at the given offset.

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

public int
getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).

public void
init(boolean
whether or not we are for encryption.
forEncryption
,
CipherParameters
the parameters required to set up the cipher.
params
)

Implements org.bouncycastle.crypto.BlockCipher.init.

initialise a RC5-64 cipher.

public int
processBlock(byte[]
the array containing the input data.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the output data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.

public void
reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

Reset the cipher.

private long
rotateLeft(long
word to rotate
x
,
long
number of bits to rotate % wordSize
y
)

Perform a left "spin" of the word.

private long
rotateRight(long
word to rotate
x
,
long
number of bits to rotate % wordSize
y
)

Perform a right "spin" of the word.

private void
setKey(byte[]
the key to be used
key
)

Re-key the cipher.

private void
wordToBytes(long word, byte[] dst, int dstOff)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_noRoundsback to summary
private int _noRounds
_Sback to summary
private long[] _S
bytesPerWordback to summary
private static final int bytesPerWord
forEncryptionback to summary
private boolean forEncryption
P64back to summary
private static final long P64
Q64back to summary
private static final long Q64
wordSizeback to summary
private static final int wordSize

Constructor Detail

RC564Engineback to summary
public RC564Engine()

Create an instance of the RC5 encryption algorithm and set some defaults

Method Detail

bytesToWordback to summary
private long bytesToWord(byte[] src, int srcOff)
decryptBlockback to summary
private int decryptBlock(byte[] in, int inOff, byte[] out, int outOff)
encryptBlockback to summary
private int encryptBlock(byte[] in, int inOff, byte[] out, int outOff)

Encrypt the given block starting at the given offset and place the result in the provided buffer starting at the given offset.

Parameters
in:byte[]

in byte buffer containing data to encrypt

inOff:int

offset into src buffer

out:byte[]

out buffer where encrypted data is written

outOff:int

offset into out buffer

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Doc from org.bouncycastle.crypto.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).

Returns:int

the block size for this cipher in bytes.

initback to summary
public void init(boolean forEncryption, CipherParameters params)

Implements org.bouncycastle.crypto.BlockCipher.init.

initialise a RC5-64 cipher.

Parameters
forEncryption:boolean

whether or not we are for encryption.

params:CipherParameters

the parameters required to set up the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Doc from org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.

Parameters
in:byte[]

the array containing the input data.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the output data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

Doc from org.bouncycastle.crypto.BlockCipher.reset.

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

rotateLeftback to summary
private long rotateLeft(long x, long y)

Perform a left "spin" of the word. The rotation of the given word x is rotated left by y bits. Only the lg(wordSize) low-order bits of y are used to determine the rotation amount. Here it is assumed that the wordsize used is a power of 2.

Parameters
x:long

word to rotate

y:long

number of bits to rotate % wordSize

rotateRightback to summary
private long rotateRight(long x, long y)

Perform a right "spin" of the word. The rotation of the given word x is rotated left by y bits. Only the lg(wordSize) low-order bits of y are used to determine the rotation amount. Here it is assumed that the wordsize used is a power of 2.

Parameters
x:long

word to rotate

y:long

number of bits to rotate % wordSize

setKeyback to summary
private void setKey(byte[] key)

Re-key the cipher.

Parameters
key:byte[]

the key to be used

wordToBytesback to summary
private void wordToBytes(long word, byte[] dst, int dstOff)