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.

85 lines
2.1 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // This file contains the support routines for computing MD5 on TCP invariants.
  14. //
  15. #define MD5_SCRATCH_LENGTH 4
  16. #define MD5_DATA_LENGTH 16
  17. //
  18. // Data structure for MD5 (Message Digest) computation.
  19. //
  20. // MD5_CONTEXT
  21. //
  22. typedef struct _MD5_CONTEXT {
  23. ULONG Scratch[MD5_SCRATCH_LENGTH];
  24. ULONG Data[MD5_DATA_LENGTH];
  25. } MD5_CONTEXT, *PMD5_CONTEXT;
  26. //
  27. // The Length of TCP connection invariants should be a multiple of 4.
  28. //
  29. C_ASSERT(TCP_MD5_DATA_LENGTH % 4 == 0);
  30. FORCEINLINE
  31. VOID
  32. MD5InitializeScratch(
  33. PMD5_CONTEXT Md5Context
  34. )
  35. {
  36. //
  37. // Load the constants as suggested by RFC 1321, Appendix A.3.
  38. //
  39. Md5Context->Scratch[0] = (UINT32)0x67452301;
  40. Md5Context->Scratch[1] = (UINT32)0xefcdab89;
  41. Md5Context->Scratch[2] = (UINT32)0x98badcfe;
  42. Md5Context->Scratch[3] = (UINT32)0x10325476;
  43. }
  44. FORCEINLINE
  45. VOID
  46. MD5InitializeData(
  47. PMD5_CONTEXT Md5Context,
  48. ULONG RandomValue
  49. )
  50. {
  51. ULONG RandomValueIndex = (TCP_MD5_DATA_LENGTH / 4);
  52. //
  53. // The unused part of the Data buffer should be zero.
  54. //
  55. RtlZeroMemory(&Md5Context->Data, sizeof(ULONG) * MD5_DATA_LENGTH);
  56. Md5Context->Data[RandomValueIndex] = RandomValue;
  57. Md5Context->Data[RandomValueIndex + 1] = 0x80;
  58. ASSERT((RandomValueIndex + 1) < (MD5_DATA_LENGTH - 2));
  59. Md5Context->Data[MD5_DATA_LENGTH - 2] =
  60. (TCP_MD5_DATA_LENGTH + sizeof(ULONG)) * 8;
  61. }
  62. //
  63. // This function will be exported as part of MD5.H; until then,
  64. // we will define it as extern.
  65. //
  66. extern
  67. VOID
  68. TransformMD5(ULONG block[4], ULONG buffer[16]);