public void engineSetSeed(byte[] seed) { HashMap attributes = new HashMap(); attributes.put(ARCFour.ARCFOUR_KEY_MATERIAL, seed); adaptee.init(attributes); virgin = false; } }
byte[] applyARCFOUR(IRandom keystream, byte[] data) throws IllegalStateException, LimitReachedException { byte[] retData = new byte[data.length]; for (int i = 0; i < data.length; i++) { retData[i] = (byte) (data[i] ^ keystream.nextByte()); } return retData; }
public void engineNextBytes(byte[] bytes) { if (virgin) { this.engineSetSeed(new byte[0]); } try { adaptee.nextBytes(bytes, 0, bytes.length); } catch (LimitReachedException ignored) { } }
singleton.nextBytes(buffer, offset, length); } catch (LimitReachedException x) { // re-initialise try { map.put(MDGenerator.SEEED, seed); singleton.init(map); // default is to use SHA-1 hash singleton.nextBytes(buffer, offset, length); } catch (Exception y) { throw new ExceptionInInitializerError(y);
/** * <p>Private constructor for cloning purposes.</p> * * @param that the instance to clone. */ private TMMH16(TMMH16 that) { this(); this.tagWords = that.tagWords; this.keystream = (IRandom) that.keystream.clone(); this.keyWords = that.keyWords; this.msgLength = that.msgLength; this.msgWords = that.msgWords; this.context = (int[]) that.context.clone(); this.prefix = (byte[]) that.prefix.clone(); this.K0 = (int[]) that.K0.clone(); this.Ki = (int[]) that.Ki.clone(); this.Mi = that.Mi; }
keystream.nextBytes(cpKey, 0, keysize); cpAttributes.put(IBlockCipher.KEY_MATERIAL, cpKey); if (cpStream instanceof ICMGenerator) { cpStream.init(cpAttributes); keystream.nextBytes(ipKey, 0, keysize); ipAttributes.put(IBlockCipher.KEY_MATERIAL, ipKey); if (ipStream instanceof ICMGenerator) { ipStream.init(ipAttributes); cpStream.nextBytes(prefix, 0, macLength); macAttributes.put(TMMH16.PREFIX, prefix);
private SecretKeySpec genkey(PBEKey key) throws InvalidKeyException { IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName); if (kdf == null) { throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName); } HashMap attrib = new HashMap(); attrib.put(IPBE.ITERATION_COUNT, new Integer(key.getIterationCount())); attrib.put(IPBE.PASSWORD, key.getPassword()); attrib.put(IPBE.SALT, key.getSalt()); try { kdf.init(attrib); } catch (IllegalArgumentException iae) { throw new InvalidKeyException(iae.toString()); } byte[] dk = new byte[mode.defaultKeySize()]; try { kdf.nextBytes(dk, 0, dk.length); } catch (LimitReachedException shouldNotHappen) { // throw new Error(shouldNotHappen); throw new Error(String.valueOf(shouldNotHappen)); } return new SecretKeySpec(dk, cipher.name()); }
byte[] applyARCFOUR(IRandom keystream, byte[] data) throws IllegalStateException, LimitReachedException { byte[] retData = new byte[data.length]; for (int i = 0; i < data.length; i++) { retData[i] = (byte) (data[i] ^ keystream.nextByte()); } return retData; }
IRandom getARCFOUR(byte[] key) { HashMap attrib = new HashMap(); IRandom keystream = new ARCFour(); attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key); keystream.init(attrib); return keystream; }
/** * <p>Fills the designated byte array with random data.</p> * * @param buffer the byte array to fill with random data. */ protected void nextRandomBytes(byte[] buffer) { if (rnd != null) { rnd.nextBytes(buffer); } else if (irnd != null) { try { irnd.nextBytes(buffer, 0, buffer.length); } catch (IllegalStateException x) { throw new RuntimeException("nextRandomBytes(): "+String.valueOf(x)); } catch (LimitReachedException x) { throw new RuntimeException("nextRandomBytes(): "+String.valueOf(x)); } } else { PRNG.nextBytes(buffer); } }
map.put(IBlockCipher.KEY_MATERIAL, K); map.put(UMacGenerator.INDEX, new Integer(0)); kdf1.init(map); map.put(UMacGenerator.INDEX, new Integer(1)); kdf2.init(map); map.put(UMacGenerator.INDEX, new Integer(2)); kdf3.init(map); map.put(UMacGenerator.INDEX, new Integer(3)); kdf4.init(map); kdf1.nextBytes(L1Key, 0, L1Key.length); } catch (LimitReachedException x) { x.printStackTrace(System.err); byte[] k2 = new byte[24]; try { kdf2.nextBytes(k2, 0, 24); } catch (LimitReachedException x) { x.printStackTrace(System.err); kdf3.nextBytes(k31, 0, 64); } catch (LimitReachedException x) { x.printStackTrace(System.err); kdf4.nextBytes(k32, 0, 4); } catch (LimitReachedException x) { x.printStackTrace(System.err);
void signingPt2(byte[] verifier, IRandom rc4) throws IllegalStateException, LimitReachedException { for (int i = 0; i < 8; i++) { verifier[i+4] = (byte) (verifier[i+4] ^ rc4.nextByte()); } }
IRandom getARCFOUR(byte[] key) { HashMap attrib = new HashMap(); IRandom keystream = new ARCFour(); attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key); keystream.init(attrib); return keystream; }
void signingPt2(byte[] verifier, IRandom rc4) throws IllegalStateException, LimitReachedException { for (int i = 0; i < 8; i++) { verifier[i+4] = (byte) (verifier[i+4] ^ rc4.nextByte()); } }
protected void engineInit(int mode, Key key, SecureRandom r) throws InvalidKeyException { if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE) { throw new IllegalArgumentException("arcfour is for encryption or decryption only"); } if (key == null || !key.getFormat().equalsIgnoreCase("RAW")) { throw new InvalidKeyException("key must be non-null raw bytes"); } HashMap attrib = new HashMap(); attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key.getEncoded()); keystream.init(attrib); }
cpStream.nextBytes(suffix, 0, length); for (int i = 0; i < length; ) { out[outOffset++] = (byte)(in[inOffset++] ^ suffix[i++]);
protected byte[] engineUpdate(byte[] in, int offset, int length) { if (length < 0 || offset < 0 || length+offset > in.length) { throw new ArrayIndexOutOfBoundsException(); } byte[] result = new byte[length]; try { for (int i = 0; i < length; i++) { result[i] = (byte) (in[i+offset] ^ keystream.nextByte()); } } catch (LimitReachedException wontHappen) { } return result; }