* Random: Use new nextBytes(buf, off, len) for efficiency

This commit is contained in:
zzz
2011-11-29 13:54:19 +00:00
parent 8480788856
commit d3564dfcb5
6 changed files with 13 additions and 26 deletions

View File

@ -473,12 +473,10 @@ public class ElGamalAESEngine {
//_log.debug("Encrypting to a NEW session");
byte elgSrcData[] = new byte[SessionKey.KEYSIZE_BYTES+32+158];
System.arraycopy(key.getData(), 0, elgSrcData, 0, SessionKey.KEYSIZE_BYTES);
// get both the preIV and the padding at once, then copy to the preIV array
_context.random().nextBytes(elgSrcData, SessionKey.KEYSIZE_BYTES, 32 + 158);
byte preIV[] = SimpleByteCache.acquire(32);
_context.random().nextBytes(preIV);
System.arraycopy(preIV, 0, elgSrcData, SessionKey.KEYSIZE_BYTES, 32);
byte rnd[] = new byte[158];
_context.random().nextBytes(rnd);
System.arraycopy(rnd, 0, elgSrcData, SessionKey.KEYSIZE_BYTES+32, 158);
System.arraycopy(elgSrcData, SessionKey.KEYSIZE_BYTES, preIV, 0, 32);
//_log.debug("Pre IV for encryptNewSession: " + DataHelper.toString(preIV, 32));
//_log.debug("SessionKey for encryptNewSession: " + DataHelper.toString(key.getData(), 32));

View File

@ -393,9 +393,7 @@ public class LeaseSet extends DatabaseEntry {
// pad out to multiple of 36 with random data after encryption
// (even for 4 leases, where 36*4 is a multiple of 16, we add another, just to be consistent)
padlen = enc.length - datalen;
pad = new byte[padlen];
RandomSource.getInstance().nextBytes(pad);
System.arraycopy(pad, 0, enc, datalen, padlen);
RandomSource.getInstance().nextBytes(enc, datalen, padlen);
// add the padded lease...
Lease padLease = new Lease();
padLease.setEndDate(((Lease)_leases.get(0)).getEndDate());