use of org.gudy.bouncycastle.crypto.engines.RC4Engine in project BiglyBT by BiglySoftware.
the class CryptoManagerImpl method obfuscate.
@Override
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);
}
use of org.gudy.bouncycastle.crypto.engines.RC4Engine in project BiglyBT by BiglySoftware.
the class UDPConnectionSet method getCipher.
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);
}
use of org.gudy.bouncycastle.crypto.engines.RC4Engine in project BiglyBT by BiglySoftware.
the class UDPConnectionSet method setSecret.
protected void setSecret(UDPConnection connection, byte[] session_secret) {
try {
if (connection == lead_connection) {
if (manager.trace()) {
trace("crypto done");
}
SHA1Hasher hasher = new SHA1Hasher();
hasher.update(KEYA_IV);
hasher.update(session_secret);
byte[] a_key = hasher.getDigest();
hasher = new SHA1Hasher();
hasher.update(KEYB_IV);
hasher.update(session_secret);
byte[] b_key = hasher.getDigest();
hasher = new SHA1Hasher();
hasher.update(KEYC_IV);
hasher.update(session_secret);
byte[] c_key = hasher.getDigest();
hasher = new SHA1Hasher();
hasher.update(KEYD_IV);
hasher.update(session_secret);
byte[] d_key = hasher.getDigest();
// for RC4 enc/dec is irrelevant
RC4Engine rc4_engine_a = getCipher(a_key);
RC4Engine rc4_engine_b = getCipher(b_key);
RC4Engine rc4_engine_c = getCipher(c_key);
RC4Engine rc4_engine_d = getCipher(d_key);
if (lead_connection.isIncoming()) {
header_cipher_out = rc4_engine_a;
header_cipher_in = rc4_engine_b;
out_seq_generator = new SequenceGenerator(new Random(bytesToLong(d_key)), rc4_engine_c, false);
in_seq_generator = new SequenceGenerator(new Random(bytesToLong(c_key)), rc4_engine_d, true);
random = new Random(bytesToLong(d_key, 8));
} else {
header_cipher_out = rc4_engine_b;
header_cipher_in = rc4_engine_a;
in_seq_generator = new SequenceGenerator(new Random(bytesToLong(d_key)), rc4_engine_c, true);
out_seq_generator = new SequenceGenerator(new Random(bytesToLong(c_key)), rc4_engine_d, false);
random = new Random(bytesToLong(c_key, 8));
}
// as the first packet each way is crypto we skip a sequence number from each generator
// to represent this and initialise the last-in-order seq appropriately so a sensible value is
// spliced into the next packet
out_seq_generator.getNextSequenceNumber();
int[] initial_in_seqs = in_seq_generator.getNextSequenceNumber();
receive_last_inorder_alt_sequence = initial_in_seqs[3];
crypto_done = true;
} else if (!crypto_done) {
Debug.out("Secondary setSecret but crypto not done");
}
} catch (Throwable e) {
Debug.printStackTrace(e);
connection.close("Crypto problems: " + Debug.getNestedExceptionMessage(e));
}
}
use of org.gudy.bouncycastle.crypto.engines.RC4Engine in project BiglyBT by BiglySoftware.
the class DHTControlImpl method getObfuscatedValue.
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);
}
Aggregations