protected SequenceGenerator( Random _generator, RC4Engine _cipher, boolean _in ) { generator = _generator; cipher = _cipher; in = _in; seq_memory = new int[MAX_SEQ_MEMORY]; alt_seq_memory = new int[MAX_SEQ_MEMORY]; Arrays.fill( seq_memory, -1 ); Arrays.fill( alt_seq_memory, -1 ); }
public void performTest() throws Exception { testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), random(8))); testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new XSalsa20Engine(), new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), random(24))); testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(32)), random(8))); testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new RC4Engine(), new RC4Engine(), new KeyParameter(random(16))); testReset(new ISAACEngine(), new ISAACEngine(), new KeyParameter(random(16))); testReset(new HC128Engine(), new HC128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); testReset(new HC256Engine(), new HC256Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); testReset(new Grainv1Engine(), new Grainv1Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new Grain128Engine(), new Grain128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(12))); }
/** * Creates new encrypted handshake. Input and output streams will be * automatically buffered if they aren't already. * * @param is * input stream * @param os * output stream */ public EncryptedHandshake(InputStream is, OutputStream os) { { byte[] test = bigIntegerToByteArray(P, 96); if (96 != test.length) { throw new IllegalArgumentException( "P is NOT 768 bits long! Length of P is " + (8 * test.length)); } } // create encrypted input and output streams with uninitialized ciphers eis = new EncryptedInputStream(is instanceof BufferedInputStream ? is : new BufferedInputStream(is), new RC4Engine()); eos = new EncryptedOutputStream(os instanceof BufferedOutputStream ? os : new BufferedOutputStream(os), new RC4Engine()); // en/decryption is disabled by default eis.setEnabled(false); eos.setEnabled(false); dis = new DataInputStream(eis); dos = new DataOutputStream(eos); }
@Override public int getIVSize() { if (ivSize < 0) { if (delegate instanceof Grainv1Engine) ivSize = 8; else if (delegate instanceof Grain128Engine) ivSize = 12; else if (delegate instanceof HC128Engine) ivSize = 16; else if (delegate instanceof HC256Engine) ivSize = 32; else if (delegate instanceof ISAACEngine) ivSize = 0; else if (delegate instanceof RC4Engine) ivSize = 0; else if (delegate instanceof Salsa20Engine) ivSize = 8; else throw new UnsupportedOperationException("For this delegate cipher type, this operation is not yet supported!"); } return ivSize; }
protected int cipherInt( RC4Engine cipher, int i ) { byte[] bytes = intToBytes( i ); cipher.processBytes( bytes, 0, bytes.length, bytes, 0 ); return( bytesToInt( bytes, 0 )); }
private void performTests() throws Exception { testModes(new BlowfishEngine(), new BlowfishEngine(), 16); testModes(new DESEngine(), new DESEngine(), 8); testModes(new DESedeEngine(), new DESedeEngine(), 24); testModes(new TEAEngine(), new TEAEngine(), 16); testModes(new CAST5Engine(), new CAST5Engine(), 16); testModes(new RC2Engine(), new RC2Engine(), 16); testModes(new XTEAEngine(), new XTEAEngine(), 16); testModes(new AESEngine(), new AESEngine(), 16); testModes(new NoekeonEngine(), new NoekeonEngine(), 16); testModes(new TwofishEngine(), new TwofishEngine(), 16); testModes(new CAST6Engine(), new CAST6Engine(), 16); testModes(new SEEDEngine(), new SEEDEngine(), 16); testModes(new SerpentEngine(), new SerpentEngine(), 16); testModes(new RC6Engine(), new RC6Engine(), 16); testModes(new CamelliaEngine(), new CamelliaEngine(), 16); testModes(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), 64); testMode(new RC4Engine(), new KeyParameter(new byte[16])); testMode(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[32]), new byte[24])); testMode(new ChaChaEngine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grainv1Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grain128Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[12])); testMode(new HC128Engine(), new KeyParameter(new byte[16])); testMode(new HC256Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); testSkipping(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testSkipping(new SICBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); }
protected StreamCipher createRC4StreamCipher() { return new RC4Engine(); }
public Base() { super(new RC4Engine(), 0); }
public PBEWithSHAAnd128Bit() { super(new RC4Engine(), 0); }
public PBEWithSHAAnd40Bit() { super(new RC4Engine(), 0); }
@Override protected StreamCipher getCipher() { return new RC4Engine(); }
@Override protected StreamCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException { return new RC4Engine(); }
public byte[] obfuscate( byte[] data ) { RC4Engine engine = new RC4Engine(); CipherParameters params = new KeyParameter( new SHA1Simple().calculateHash( getOBSID())); engine.init( true, params ); byte[] temp = new byte[1024]; engine.processBytes( temp, 0, 1024, temp, 0 ); final byte[] obs_value = new byte[ data.length ]; engine.processBytes( data, 0, data.length, obs_value, 0 ); return( obs_value ); }
protected byte[] getObfuscatedValue( byte[] plain_key ) { RC4Engine engine = new RC4Engine(); CipherParameters params = new KeyParameter( new SHA1Simple().calculateHash( plain_key )); engine.init( true, params ); byte[] temp = new byte[1024]; engine.processBytes( temp, 0, 1024, temp, 0 ); final byte[] obs_value = new byte[ plain_key.length ]; engine.processBytes( plain_key, 0, plain_key.length, obs_value, 0 ); return( obs_value ); }
protected RC4Engine getCipher( byte[] key ) { SecretKeySpec secret_key_spec = new SecretKeySpec( key, "RC4" ); RC4Engine rc4_engine = new RC4Engine(); CipherParameters params_a = new KeyParameter( secret_key_spec.getEncoded()); // for RC4 enc/dec is irrelevant rc4_engine.init( true, params_a ); // skip first 1024 bytes of stream to protected against a Fluhrer, Mantin and Shamir attack byte[] temp = new byte[1024]; rc4_engine.processBytes( temp, 0, temp.length, temp, 0 ); return( rc4_engine ); }
public PBEWithSHAAnd128Bit() { super(new RC4Engine(), 0, 128, SHA1); }
public PBEWithSHAAnd40Bit() { super(new RC4Engine(), 0, 40, SHA1); }
public void test() throws Exception { assertTrue(PLAIN_TEXT.length() > 255); // test streams with both disabled and enabled encryption // 1x disabled, 99x enabled for (int i = 0; i < 100; i++) { // prepare random info hash final byte[] infoHash = new byte[20]; random.nextBytes(infoHash); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // D-H key exchange KeyAgreement senderKeyAgreement = KeyAgreement.getInstance("DH"); DHPublicKey senderPublicKey = startKeyExchange(senderKeyAgreement); KeyAgreement receiverKeyAgreement = KeyAgreement.getInstance("DH"); DHPublicKey receiverPublicKey = startKeyExchange(receiverKeyAgreement); byte[] receiverSecretBytes = finishKeyExchange(receiverKeyAgreement, senderPublicKey.getY()); byte[] senderSecretBytes = finishKeyExchange(senderKeyAgreement, receiverPublicKey.getY()); assertTrue(Arrays.equals(senderSecretBytes, receiverSecretBytes)); { // prepare encrypted output stream StreamCipher outCipher = new RC4Engine(); setupStreamCipher(outCipher, senderSecretBytes, false, infoHash); EncryptedOutputStream eos = new EncryptedOutputStream(baos, outCipher); eos.setEnabled(0 != i); DataOutputStream dos = new DataOutputStream(eos); // write text dos.write(PLAIN_TEXT.getBytes()); dos.flush(); // close eos.close(); if (0 == i) { assertTrue(Arrays.equals(PLAIN_TEXT.getBytes(), baos .toByteArray())); } else { assertFalse(Arrays.equals(PLAIN_TEXT.getBytes(), baos .toByteArray())); } } { // prepare encrypted input stream StreamCipher inCipher = new RC4Engine(); setupStreamCipher(inCipher, receiverSecretBytes, true, infoHash); EncryptedInputStream eis = new EncryptedInputStream(new ByteArrayInputStream(baos .toByteArray()), inCipher); eis.setEnabled(0 != i); DataInputStream dis = new DataInputStream(eis); // read text byte[] tmp = new byte[PLAIN_TEXT.getBytes().length]; dis.readFully(tmp); // close eis.close(); assertTrue(Arrays.equals(PLAIN_TEXT.getBytes(), tmp)); } } }
public ARC4Engine() { cipher = new RC4Engine(); }
private RC4Engine getCipher( byte[] key ) { SecretKeySpec secret_key_spec = new SecretKeySpec( key, "RC4" ); RC4Engine rc4_engine = new RC4Engine(); CipherParameters params_a = new KeyParameter( secret_key_spec.getEncoded()); // for RC4 enc/dec is irrelevant rc4_engine.init( true, params_a ); // skip first 1024 bytes of stream to protected against a Fluhrer, Mantin and Shamir attack byte[] temp = new byte[1024]; rc4_engine.processBytes( temp, 0, temp.length, temp, 0 ); return( rc4_engine ); }