Leaked source code of windows server 2003
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.

78 lines
2.0 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. ULONG *pHash,
  10. bool CaseInsensitive
  11. )
  12. {
  13. if (CaseInsensitive)
  14. *pHash = ::FusionpHashUnicodeStringCaseInsensitive(String, Cch);
  15. else
  16. *pHash = ::FusionpHashUnicodeStringCaseSensitive(String, Cch);
  17. return TRUE;
  18. }
  19. ULONG
  20. __fastcall
  21. FusionpHashUnicodeStringCaseSensitive(
  22. PCWSTR String,
  23. SIZE_T cch
  24. )
  25. {
  26. ULONG TmpHashValue = 0;
  27. //
  28. // Note that if you change this implementation, you have to have the implementation inside
  29. // ntdll change to match it. Since that's hard and will affect everyone else in the world,
  30. // DON'T CHANGE THIS ALGORITHM NO MATTER HOW GOOD OF AN IDEA IT SEEMS TO BE! This isn't the
  31. // most perfect hashing algorithm, but its stability is critical to being able to match
  32. // previously persisted hash values.
  33. //
  34. while (cch-- != 0)
  35. TmpHashValue = (TmpHashValue * 65599) + *String++;
  36. return TmpHashValue;
  37. }
  38. ULONG
  39. __fastcall
  40. FusionpHashUnicodeStringCaseInsensitive(
  41. PCWSTR String,
  42. SIZE_T cch
  43. )
  44. {
  45. ULONG TmpHashValue = 0;
  46. //
  47. // Note that if you change this implementation, you have to have the implementation inside
  48. // ntdll change to match it. Since that's hard and will affect everyone else in the world,
  49. // DON'T CHANGE THIS ALGORITHM NO MATTER HOW GOOD OF AN IDEA IT SEEMS TO BE! This isn't the
  50. // most perfect hashing algorithm, but its stability is critical to being able to match
  51. // previously persisted hash values.
  52. //
  53. while (cch-- != 0)
  54. {
  55. WCHAR Char = *String++;
  56. if (Char < 128)
  57. {
  58. if ((Char >= L'a') && (Char <= L'z'))
  59. Char = (WCHAR) ((Char - L'a') + L'A');
  60. }
  61. else
  62. Char = ::FusionpRtlUpcaseUnicodeChar(Char);
  63. TmpHashValue = (TmpHashValue * 65599) + Char;
  64. }
  65. return TmpHashValue;
  66. }