--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -167,24 +167,38 @@ nsRFPService::ReduceTimePrecisionImpl(do
// We think this is okay, and we codify it in some tests.
double timeScaled = aTime * (1000000 / aTimeScale);
//Cut off anything less than a microsecond.
long long timeAsInt = llround(timeScaled);
//Cast the resolution (in microseconds) to an int.
long long resolutionAsInt = aResolutionUSec;
// Perform the clamping.
long long rounded = (timeAsInt / resolutionAsInt) * resolutionAsInt;
+
+ long jitterToAdd = 0;
+ double randomMultiplier = 0;
+ if (jitter && sJitterUSec > 0) {
+ // Get a random value between 0.0 and 1.0
+ if(!NS_FAILED(RandomDouble(&randomMultiplier))) {
+ // Add or Subtract up to the jitter value
+ jitterToAdd = (randomMultiplier * 2 * sJitterUSec) - sJitterUSec;
+ }
+ }
+
// Cast it back to a double and reduce it to the correct units.
- double ret = double(rounded) / (1000000.0 / aTimeScale);
+ double ret = double(rounded + jitterToAdd) / (1000000.0 / aTimeScale);
#if defined(DEBUG)
- MOZ_LOG(gResistFingerprintingLog, LogLevel::Verbose,
- ("Given: (%.*f, Scaled: %.*f, Converted: %lli), Rounding with (%lli, Originally %.*f), Intermediate: (%lli), Got: (%lli Converted: %.*f)",
- DBL_DIG-1, aTime, DBL_DIG-1, timeScaled, timeAsInt, resolutionAsInt, DBL_DIG-1, aResolutionUSec,
- (timeAsInt / resolutionAsInt), rounded, DBL_DIG-1, ret));
+ uint32_t jitterLocal = sJitterUSec;
+ MOZ_LOG(gResistFingerprintingLog, LogLevel::Verbose,
+ ("Given: (%.*f, Scaled: %.*f, Converted: %lli), Rounding with (%lli, Originally %.*f), "
+ "Intermediate: (%lli), Got: (%lli) Jitter: (%s Max: %u Multipler: %f Value: %li) Final: (%lli Converted: %.*f)",
+ DBL_DIG-1, aTime, DBL_DIG-1, timeScaled, timeAsInt, resolutionAsInt, DBL_DIG-1, aResolutionUSec,
+ (timeAsInt / resolutionAsInt), rounded, (jitter && jitterLocal > 0 ? "On" : "Off"), jitterLocal, randomMultiplier,
+ jitterToAdd, (rounded + jitterToAdd), DBL_DIG-1, ret));
#endif
return ret;
}
/* static */
double
nsRFPService::ReduceTimePrecisionAsUSecs(double aTime, bool jitter /* = false */)