Round NTCP timestamps to reduce clock bias

This commit is contained in:
zzz
2010-11-26 14:04:49 +00:00
parent 7f1ace4dbe
commit e1e6db2b3c
2 changed files with 4 additions and 4 deletions

View File

@ -234,7 +234,7 @@ public class EstablishState {
System.arraycopy(_X, 0, xy, 0, _X.length);
System.arraycopy(_Y, 0, xy, _X.length, _Y.length);
Hash hxy = _context.sha().calculateHash(xy);
_tsB = _context.clock().now()/1000l; // our (Bob's) timestamp in seconds
_tsB = (_context.clock().now() + 500) / 1000l; // our (Bob's) timestamp in seconds
byte padding[] = new byte[12]; // the encrypted data needs an extra 12 bytes
_context.random().nextBytes(padding);
byte toEncrypt[] = new byte[hxy.getData().length+4+padding.length];
@ -387,7 +387,7 @@ public class EstablishState {
return;
}
_tsB = DataHelper.fromLong(hXY_tsB, Hash.HASH_LENGTH, 4); // their (Bob's) timestamp in seconds
_tsA = _context.clock().now()/1000; // our (Alice's) timestamp in seconds
_tsA = (_context.clock().now() + 500) / 1000; // our (Alice's) timestamp in seconds
if (_log.shouldLog(Log.DEBUG))
_log.debug(prefix()+"h(X+Y) is correct, tsA-tsB=" + (_tsA-_tsB));

View File

@ -1035,7 +1035,7 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
*
*/
private void readMeta(byte unencrypted[]) {
long ourTs = _context.clock().now()/1000;
long ourTs = (_context.clock().now() + 500) / 1000;
long ts = DataHelper.fromLong(unencrypted, 2, 4);
Adler32 crc = new Adler32();
crc.update(unencrypted, 0, unencrypted.length-4);
@ -1068,7 +1068,7 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
synchronized (_meta) {
_context.random().nextBytes(_meta); // randomize the uninterpreted, then overwrite w/ data
DataHelper.toLong(_meta, 0, 2, 0);
DataHelper.toLong(_meta, 2, 4, _context.clock().now()/1000);
DataHelper.toLong(_meta, 2, 4, (_context.clock().now() + 500) / 1000);
Adler32 crc = new Adler32();
crc.update(_meta, 0, _meta.length-4);
DataHelper.toLong(_meta, _meta.length-4, 4, crc.getValue());