63 this.version = version; 64 this.rounds = rounds; 65 this.wordSize = wordSize; 66 } 67 68 /** 69 * Constructs a parameter set for RC5 from the given version, number of 70 * rounds, word size (in bits), and IV. 71 * 72 * <p> Note that the size of the IV (block size) must be twice the word 73 * size. The bytes that constitute the IV are those between 74 * <code>iv[0]</code> and <code>iv[2*(wordSize/8)-1]</code> inclusive. 75 * 76 * @param version the version. 77 * @param rounds the number of rounds. 78 * @param wordSize the word size in bits. 79 * @param iv the buffer with the IV. The first <code>2*(wordSize/8) 80 * </code> bytes of the buffer are copied to protect against subsequent 81 * modification. 82 * @exception IllegalArgumentException if <code>iv</code> is 83 * <code>null</code> or <code>(iv.length < 2 * (wordSize / 8))</code> 84 */ 85 public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) { 86 this(version, rounds, wordSize, iv, 0); 87 } 88 89 /** 90 * Constructs a parameter set for RC5 from the given version, number of 91 * rounds, word size (in bits), and IV. 92 * 93 * <p> The IV is taken from <code>iv</code>, starting at 94 * <code>offset</code> inclusive. 95 * Note that the size of the IV (block size), starting at 96 * <code>offset</code> inclusive, must be twice the word size. 97 * The bytes that constitute the IV are those between 98 * <code>iv[offset]</code> and <code>iv[offset+2*(wordSize/8)-1]</code> 99 * inclusive. 100 * 101 * @param version the version. 102 * @param rounds the number of rounds. 103 * @param wordSize the word size in bits. 104 * @param iv the buffer with the IV. The first <code>2*(wordSize/8) 105 * </code> bytes of the buffer beginning at <code>offset</code> 106 * inclusive are copied to protect against subsequent modification. 107 * @param offset the offset in <code>iv</code> where the IV starts. 108 * @exception IllegalArgumentException if <code>iv</code> is 109 * <code>null</code> or 110 * <code>(iv.length - offset < 2 * (wordSize / 8))</code> 111 */ 112 public RC5ParameterSpec(int version, int rounds, int wordSize, 113 byte[] iv, int offset) { 114 this.version = version; 115 this.rounds = rounds; 116 this.wordSize = wordSize; 117 if (iv == null) throw new IllegalArgumentException("IV missing"); 118 int blockSize = (wordSize / 8) * 2; 119 if (iv.length - offset < blockSize) { 120 throw new IllegalArgumentException("IV too short"); 121 } 122 this.iv = new byte[blockSize]; 123 System.arraycopy(iv, offset, this.iv, 0, blockSize); 124 } 125 126 /** 127 * Returns the version. 128 * 129 * @return the version. 130 */ | 63 this.version = version; 64 this.rounds = rounds; 65 this.wordSize = wordSize; 66 } 67 68 /** 69 * Constructs a parameter set for RC5 from the given version, number of 70 * rounds, word size (in bits), and IV. 71 * 72 * <p> Note that the size of the IV (block size) must be twice the word 73 * size. The bytes that constitute the IV are those between 74 * <code>iv[0]</code> and <code>iv[2*(wordSize/8)-1]</code> inclusive. 75 * 76 * @param version the version. 77 * @param rounds the number of rounds. 78 * @param wordSize the word size in bits. 79 * @param iv the buffer with the IV. The first <code>2*(wordSize/8) 80 * </code> bytes of the buffer are copied to protect against subsequent 81 * modification. 82 * @exception IllegalArgumentException if <code>iv</code> is 83 * <code>null</code> or {@code (iv.length < 2 * (wordSize / 8))} 84 */ 85 public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) { 86 this(version, rounds, wordSize, iv, 0); 87 } 88 89 /** 90 * Constructs a parameter set for RC5 from the given version, number of 91 * rounds, word size (in bits), and IV. 92 * 93 * <p> The IV is taken from <code>iv</code>, starting at 94 * <code>offset</code> inclusive. 95 * Note that the size of the IV (block size), starting at 96 * <code>offset</code> inclusive, must be twice the word size. 97 * The bytes that constitute the IV are those between 98 * <code>iv[offset]</code> and <code>iv[offset+2*(wordSize/8)-1]</code> 99 * inclusive. 100 * 101 * @param version the version. 102 * @param rounds the number of rounds. 103 * @param wordSize the word size in bits. 104 * @param iv the buffer with the IV. The first <code>2*(wordSize/8) 105 * </code> bytes of the buffer beginning at <code>offset</code> 106 * inclusive are copied to protect against subsequent modification. 107 * @param offset the offset in <code>iv</code> where the IV starts. 108 * @exception IllegalArgumentException if <code>iv</code> is 109 * <code>null</code> or 110 * {@code (iv.length - offset < 2 * (wordSize / 8))} 111 */ 112 public RC5ParameterSpec(int version, int rounds, int wordSize, 113 byte[] iv, int offset) { 114 this.version = version; 115 this.rounds = rounds; 116 this.wordSize = wordSize; 117 if (iv == null) throw new IllegalArgumentException("IV missing"); 118 int blockSize = (wordSize / 8) * 2; 119 if (iv.length - offset < blockSize) { 120 throw new IllegalArgumentException("IV too short"); 121 } 122 this.iv = new byte[blockSize]; 123 System.arraycopy(iv, offset, this.iv, 0, blockSize); 124 } 125 126 /** 127 * Returns the version. 128 * 129 * @return the version. 130 */ |