javax.crypto.spec
public class: RC5ParameterSpec [javadoc |
source]
java.lang.Object
javax.crypto.spec.RC5ParameterSpec
All Implemented Interfaces:
AlgorithmParameterSpec
This class specifies the parameters used with the
RC5
algorithm.
The parameters consist of a version number, a rounds count, a word
size, and optionally an initialization vector (IV) (only in feedback mode).
This class can be used to initialize a Cipher object that
implements the RC5 algorithm as supplied by
RSA Security Inc.,
or any parties authorized by RSA Security.
- author:
Jan - Luehe
- since:
1.4 -
| Constructor: |
public RC5ParameterSpec(int version,
int rounds,
int wordSize) {
// the word size in bits
this.version = version;
this.rounds = rounds;
this.wordSize = wordSize;
}
Constructs a parameter set for RC5 from the given version, number of
rounds and word size (in bits). Parameters:
version - the version.
rounds - the number of rounds.
wordSize - the word size in bits.
|
public RC5ParameterSpec(int version,
int rounds,
int wordSize,
byte[] iv) {
this(version, rounds, wordSize, iv, 0);
}
Constructs a parameter set for RC5 from the given version, number of
rounds, word size (in bits), and IV.
Note that the size of the IV (block size) must be twice the word
size. The bytes that constitute the IV are those between
iv[0] and iv[2*(wordSize/8)-1] inclusive. Parameters:
version - the version.
rounds - the number of rounds.
wordSize - the word size in bits.
iv - the buffer with the IV. The first 2*(wordSize/8)
bytes of the buffer are copied to protect against subsequent
modification.
Throws:
IllegalArgumentException - if iv is
null or (iv.length < 2 * (wordSize / 8))
- exception:
IllegalArgumentException - if iv is
null or (iv.length < 2 * (wordSize / 8))
|
public RC5ParameterSpec(int version,
int rounds,
int wordSize,
byte[] iv,
int offset) {
this.version = version;
this.rounds = rounds;
this.wordSize = wordSize;
if (iv == null) throw new IllegalArgumentException("IV missing");
int blockSize = (wordSize / 8) * 2;
if (iv.length - offset < blockSize) {
throw new IllegalArgumentException("IV too short");
}
this.iv = new byte[blockSize];
System.arraycopy(iv, offset, this.iv, 0, blockSize);
}
Constructs a parameter set for RC5 from the given version, number of
rounds, word size (in bits), and IV.
The IV is taken from iv, starting at
offset inclusive.
Note that the size of the IV (block size), starting at
offset inclusive, must be twice the word size.
The bytes that constitute the IV are those between
iv[offset] and iv[offset+2*(wordSize/8)-1]
inclusive. Parameters:
version - the version.
rounds - the number of rounds.
wordSize - the word size in bits.
iv - the buffer with the IV. The first 2*(wordSize/8)
bytes of the buffer beginning at offset
inclusive are copied to protect against subsequent modification.
offset - the offset in iv where the IV starts.
Throws:
IllegalArgumentException - if iv is
null or
(iv.length - offset < 2 * (wordSize / 8))
- exception:
IllegalArgumentException - if iv is
null or
(iv.length - offset < 2 * (wordSize / 8))
|
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.crypto.spec.RC5ParameterSpec Detail: |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof RC5ParameterSpec)) {
return false;
}
RC5ParameterSpec other = (RC5ParameterSpec) obj;
return ((version == other.version) &&
(rounds == other.rounds) &&
(wordSize == other.wordSize) &&
java.util.Arrays.equals(iv, other.iv));
}
Tests for equality between the specified object and this
object. Two RC5ParameterSpec objects are considered equal if their
version numbers, number of rounds, word sizes, and IVs are equal.
(Two IV references are considered equal if both are null.) |
public byte[] getIV() {
return (iv == null? null:(byte[])iv.clone());
}
Returns the IV or null if this parameter set does not contain an IV. |
public int getRounds() {
return this.rounds;
}
Returns the number of rounds. |
public int getVersion() {
return this.version;
}
|
public int getWordSize() {
return this.wordSize;
}
Returns the word size in bits. |
public int hashCode() {
int retval = 0;
if (iv != null) {
for (int i = 1; i < iv.length; i++) {
retval += iv[i] * i;
}
}
retval += (version + rounds + wordSize);
return retval;
}
Calculates a hash code value for the object.
Objects that are equal will also have the same hashcode. |