Skip to content

Commit

Permalink
Backed out 2 changesets (bug 1887161) for causing build bustages @ si…
Browse files Browse the repository at this point in the history
…phash.h CLOSED TREE

Backed out changeset bd63a7c8f39e (bug 1887161)
Backed out changeset 856d5366ba4b (bug 1887161)
  • Loading branch information
Sandor Molnar committed Jul 17, 2024
1 parent a056c94 commit bfc37d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 45 deletions.
5 changes: 0 additions & 5 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14398,11 +14398,6 @@
value: false
mirror: always

# Control whether we use the SipHash to generate the canvas random key.
- name: privacy.resistFingerprinting.randomization.canvas.use_siphash
type: RelaxedAtomicBool
value: false
mirror: always

# Anti-tracking permission expiration.
- name: privacy.restrict3rdpartystorage.expiration
Expand Down
1 change: 0 additions & 1 deletion parser/expat/lib/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ include("sources.mozbuild")
EXPORTS += [
'expat.h',
'expat_external.h',
'siphash.h',
]

if CONFIG["MOZ_WASM_SANDBOXING_EXPAT"]:
Expand Down
49 changes: 10 additions & 39 deletions toolkit/components/resistfingerprinting/nsRFPService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "mozilla/MacroForEach.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/Preferences.h"
#include "mozilla/ProfilerMarkers.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
#include "mozilla/Sprintf.h"
Expand Down Expand Up @@ -90,7 +89,6 @@
#include "nscore.h"
#include "prenv.h"
#include "prtime.h"
#include "siphash.h"
#include "xpcpublic.h"

#include "js/Date.h"
Expand Down Expand Up @@ -1515,8 +1513,6 @@ nsresult nsRFPService::GenerateCanvasKeyFromImageData(
nsICookieJarSettings* aCookieJarSettings, uint8_t* aImageData,
uint32_t aSize, nsTArray<uint8_t>& aCanvasKey) {
NS_ENSURE_ARG_POINTER(aCookieJarSettings);
AUTO_PROFILER_MARKER_TEXT("nsRFPService", OTHER, {},
"nsRFPService::GenerateCanvasKeyFromImageData"_ns);

nsTArray<uint8_t> randomKey;
nsresult rv =
Expand All @@ -1529,44 +1525,19 @@ nsresult nsRFPService::GenerateCanvasKeyFromImageData(
return NS_ERROR_FAILURE;
}

if (StaticPrefs::
privacy_resistFingerprinting_randomization_canvas_use_siphash()) {
struct sipkey key = {{0, 0}};

// SipHash takes 128 bits data as the key. So, we will only use the first
// half of the random key.
sip_tokey(&key, randomKey.Elements());
uint64_t digest = siphash24(aImageData, aSize, &key);

aCanvasKey.SetLength(32);
aCanvasKey.ClearAndRetainStorage();

// SipHash outputs 64 bits data as the hash result. But we need a 256 bits
// canvas key. So, we use a random number generator to expand the key.
non_crypto::XorShift128PlusRNG rng(digest, ~digest);

for (size_t i = 0; i < 4; ++i) {
uint64_t val = rng.next();
for (size_t j = 0; j < 8; ++j) {
uint8_t data = static_cast<uint8_t>((val >> (j * 8)) & 0xFF);
aCanvasKey.InsertElementAt((i * 8) + j, data);
}
}
} else {
// Generate the key for randomizing the canvas data using hMAC. The key is
// based on the random key of the document and the canvas data itself. So,
// different canvas would have different keys.
HMAC hmac;
// Generate the key for randomizing the canvas data using hMAC. The key is
// based on the random key of the document and the canvas data itself. So,
// different canvas would have different keys.
HMAC hmac;

rv = hmac.Begin(SEC_OID_SHA256, Span(randomKey));
NS_ENSURE_SUCCESS(rv, rv);
rv = hmac.Begin(SEC_OID_SHA256, Span(randomKey));
NS_ENSURE_SUCCESS(rv, rv);

rv = hmac.Update(aImageData, aSize);
NS_ENSURE_SUCCESS(rv, rv);
rv = hmac.Update(aImageData, aSize);
NS_ENSURE_SUCCESS(rv, rv);

rv = hmac.End(aCanvasKey);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = hmac.End(aCanvasKey);
NS_ENSURE_SUCCESS(rv, rv);

return NS_OK;
}
Expand Down

0 comments on commit bfc37d1

Please sign in to comment.