summaryrefslogtreecommitdiffhomepage
path: root/src/libDDK/DriverKit/ObjectKit/checksum.h
blob: 92c636034b06ddca5da8b3b7482b177c0a4e5c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/nekernel-org/nekernel

#ifndef DRIVERKIT_CHECKSUM_H
#define DRIVERKIT_CHECKSUM_H

#include <DriverKit/ObjectKit/driver_base.h>

namespace Kernel::DDK {

using IndexableBlob = char*;
using Indexable     = char;

/// @note This uses the FNV 64-bit variant.
/// @brief Performs a checksum computation for a memory region.
inline uintptr_t rtl_checksum(const IndexableBlob path) {
  if (!path || *path == 0) return 0;

  const uintptr_t kFNVSeed  = 0xcbf29ce484222325ULL;
  const uintptr_t kFNVPrime = 0x100000001b3ULL;

  uintptr_t hash = kFNVSeed;

  IndexableBlob path_ = path;

  while (*path_) {
    hash ^= (Indexable) (*path_++);
    hash *= kFNVPrime;
  }

  return hash;
}

using Blob = void*;

}  // namespace Kernel::DDK

#endif