1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_METRICS_H_
6 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_METRICS_H_
7 
8 #include <cstdint>
9 #include <cstring>
10 #include <type_traits>
11 
12 #include "base/containers/span.h"
13 #include "third_party/blink/public/common/common_export.h"
14 
15 namespace blink {
16 
17 // IdentifiabilityDigestOfBytes, which is NOT a cryptographic hash function,
18 // takes a span of bytes as input and calculates a digest that can be used with
19 // identifiability metric reporting functions.
20 //
21 // The returned digest ...:
22 //
23 // * Is Stable: The returned digest will be consistent across different versions
24 //   of Chromium. Thus it can be persisted and meaningfully aggregated across
25 //   browser versions.
26 //
27 // * Is approximately uniformly distributed when the input is uniformly
28 //   distributed.
29 //
30 // * Is NOT optimized for any other distribution of input including narrow
31 //   integral ranges.
32 //
33 // * Is NOT collision resistant: Callers should assume that it is easy to come
34 //   up with collisions, and to come up with a pre-image given a digest.
35 //
36 // Note: This is NOT a cryptographic hash function.
37 BLINK_COMMON_EXPORT uint64_t
38 IdentifiabilityDigestOfBytes(base::span<const uint8_t> in);
39 
40 // The zero-length digest, i.e. the digest computed for no bytes.
41 static constexpr uint64_t kIdentifiabilityDigestOfNoBytes =
42     UINT64_C(0x9ae16a3b2f90404f);
43 
44 }  // namespace blink
45 
46 #endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_METRICS_H_
47