FileDocCategorySizeDatePackage
RC5ParameterSpec.javaAPI DocAndroid 1.5 API7012Wed May 06 22:41:02 BST 2009javax.crypto.spec

RC5ParameterSpec

public class RC5ParameterSpec extends Object implements AlgorithmParameterSpec
The algorithm parameter specification for the RC5 algorithm.
since
Android 1.0

Fields Summary
private final int
version
private final int
rounds
private final int
wordSize
private final byte[]
iv
Constructors Summary
public RC5ParameterSpec(int version, int rounds, int wordSize)
Creates a new RC5ParameterSpec instance with the specified version, round count an word size (in bits).

param
version the version.
param
rounds the round count.
param
wordSize the word size (in bits).

        this.version = version;
        this.rounds = rounds;
        this.wordSize = wordSize;
        this.iv = null;
    
public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv)
Creates a new RC5ParameterSpec instance with the specified version, round count, word size (in bits) and an initialization vector.

The size of the initialization vector must be at least 2 * (wordSize / 8) bytes which are copied to protect them against modification.

param
version the version.
param
rounds the round count.
param
wordSize the word size (in bits).
param
iv the initialization vector.
throws
IllegalArgumentException if the initialization vector is null or shorter than 2 * (wordSize / 8).

        if (iv == null) {
            throw new IllegalArgumentException(Messages.getString("crypto.31")); //$NON-NLS-1$
        }
        if (iv.length < 2 * (wordSize / 8)) {
            throw new IllegalArgumentException(
                    Messages.getString("crypto.32")); //$NON-NLS-1$
        }
        this.version = version;
        this.rounds = rounds;
        this.wordSize = wordSize;
        this.iv = new byte[2*(wordSize/8)];
        System.arraycopy(iv, 0, this.iv, 0, 2*(wordSize/8));
    
public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv, int offset)
Creates a new RC5ParameterSpec instance with the specified version, round count, wordSize (in bits), an initialization vector and an offset.

The size of the initialization vector must be at least offset + (2 * (wordSize / 8)) bytes. The bytes starting at offset are copied to protect them against modification.

param
version the version.
param
rounds the round count.
param
wordSize the word size (in bits).
param
iv the initialization vector.
param
offset the offset in the initialization vector.
throws
IllegalArgumentException if the initialization vector is null of shorter than offset + (2 * (wordSize / 8)).
throws
ArrayIndexOutOfBoundsException if offset is negative.

        if (iv == null) {
            throw new IllegalArgumentException(Messages.getString("crypto.31")); //$NON-NLS-1$
        }
        if (offset < 0) {
            throw new ArrayIndexOutOfBoundsException(Messages.getString("crypto.33")); //$NON-NLS-1$
        }
        if (iv.length - offset < 2 * (wordSize / 8)) {
            throw new IllegalArgumentException(
                    Messages.getString("crypto.34")); //$NON-NLS-1$
        }
        this.version = version;
        this.rounds = rounds;
        this.wordSize = wordSize;
        this.iv = new byte[offset+2*(wordSize/8)];
        System.arraycopy(iv, offset, this.iv, 0, 2*(wordSize/8));
    
Methods Summary
public booleanequals(java.lang.Object obj)
Compares the specified object with this RC5ParameterSpec instance.

param
obj the object to compare.
return
true if version, round count, word size and initializaion vector of both objects are equal, otherwise false.

        if (obj == this) {
            return true;
        }
        if (!(obj instanceof RC5ParameterSpec)) {
            return false;
        }
        RC5ParameterSpec ps = (RC5ParameterSpec) obj;
        return (version == ps.version)
            && (rounds == ps.rounds)
            && (wordSize == ps.wordSize)
            && (Arrays.equals(iv, ps.iv));
    
public byte[]getIV()
Returns a copy of the initialization vector.

return
a copy of the initialization vector, or null if none specified.

        if (iv == null) {
            return null;
        }
        byte[] result = new byte[iv.length];
        System.arraycopy(iv, 0, result, 0, iv.length);
        return result;
    
public intgetRounds()
Returns the round count.

return
the round count.

        return rounds;
    
public intgetVersion()
Returns the version.

return
the version.

        return version;
    
public intgetWordSize()
Returns the word size (in bits).

return
the word size (in bits).

        return wordSize;
    
public inthashCode()
Returns the hash code of this RC5ParameterSpec instance.

return
the hash code.

        int result = version + rounds + wordSize;
        if (iv == null) {
            return result;
        }
        for (byte element : iv) {
            result += element & 0xFF;
        }
        return result;