Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. #include "stdinc.h"
  2. #include "debmacro.h"
  3. #include "util.h"
  4. #include "fusiontrace.h"
  5. BOOL
  6. FusionpHashUnicodeString(
  7. PCWSTR String,
  8. SIZE_T cch,
  9. PULONG HashValue,
  10. bool fCaseInsensitive
  11. )
  12. {
  13. BOOL fSuccess = FALSE;
  14. FN_TRACE_WIN32(fSuccess);
  15. ULONG TmpHashValue = 0;
  16. if (HashValue != NULL)
  17. *HashValue = 0;
  18. PARAMETER_CHECK(HashValue != NULL);
  19. //
  20. // Note that if you change this implementation, you have to have the implementation inside
  21. // ntdll change to match it. Since that's hard and will affect everyone else in the world,
  22. // DON'T CHANGE THIS ALGORITHM NO MATTER HOW GOOD OF AN IDEA IT SEEMS TO BE! This isn't the
  23. // most perfect hashing algorithm, but its stability is critical to being able to match
  24. // previously persisted hash values.
  25. //
  26. if (fCaseInsensitive)
  27. {
  28. while (cch-- != 0)
  29. {
  30. WCHAR Char = *String++;
  31. TmpHashValue = (TmpHashValue * 65599) + ::FusionpRtlUpcaseUnicodeChar(Char);
  32. }
  33. }
  34. else
  35. {
  36. while (cch-- != 0)
  37. TmpHashValue = (TmpHashValue * 65599) + *String++;
  38. }
  39. *HashValue = TmpHashValue;
  40. fSuccess = TRUE;
  41. Exit:
  42. return fSuccess;
  43. }