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.

163 lines
3.8 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: hashmd5.cpp
  4. //
  5. // Synopsis: Implementation of CHashMD5 class methods
  6. //
  7. //
  8. // History: 10/2/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "hashmd5.h"
  16. #include <md5.h>
  17. //++--------------------------------------------------------------
  18. //
  19. // Function: CHashMD5
  20. //
  21. // Synopsis: This is CHashMD5 class constructor
  22. //
  23. // Arguments: NONE
  24. //
  25. // Returns: NONE
  26. //
  27. //
  28. // History: MKarki Created 10/2/97
  29. //
  30. //----------------------------------------------------------------
  31. CHashMD5::CHashMD5()
  32. {
  33. }
  34. //++--------------------------------------------------------------
  35. //
  36. // Function: ~CHashMD5
  37. //
  38. // Synopsis: This is ~CHashMD5 class constructor
  39. //
  40. // Arguments: NONE
  41. //
  42. // Returns: NONE
  43. //
  44. //
  45. // History: MKarki Created 10/2/97
  46. //
  47. //----------------------------------------------------------------
  48. CHashMD5::~CHashMD5()
  49. {
  50. }
  51. //++--------------------------------------------------------------
  52. //
  53. // Function: HashIt
  54. //
  55. // Synopsis: This is HashIt CHashMD5 class public method used
  56. // carry out hashing of the buffers provided
  57. //
  58. // Arguments: NONE
  59. //
  60. // Returns: NONE
  61. //
  62. //
  63. // History: MKarki Created 10/2/97
  64. //
  65. //----------------------------------------------------------------
  66. BOOL
  67. CHashMD5::HashIt (
  68. PBYTE pbyAuthenticator,
  69. PBYTE pKey = NULL,
  70. DWORD dwKeySize = 0,
  71. PBYTE pBuffer1 = NULL,
  72. DWORD dwSize1 = 0,
  73. PBYTE pBuffer2 = NULL,
  74. DWORD dwSize2 = 0,
  75. PBYTE pBuffer3 = NULL,
  76. DWORD dwSize3 = 0,
  77. PBYTE pBuffer4 = NULL,
  78. DWORD dwSize4 = 0,
  79. PBYTE pBuffer5 = NULL,
  80. DWORD dwSize5 = 0
  81. )
  82. {
  83. BOOL bRetVal = FALSE;
  84. MD5_CTX md5Context;
  85. __try
  86. {
  87. if (NULL == pbyAuthenticator)
  88. __leave;
  89. MD5Init (&md5Context);
  90. if ((NULL != pBuffer1) && (0 != dwSize1))
  91. {
  92. MD5Update (
  93. &md5Context,
  94. reinterpret_cast <const unsigned char * > (pBuffer1),
  95. dwSize1
  96. );
  97. }
  98. if ((NULL != pBuffer2) && (0 != dwSize2))
  99. {
  100. MD5Update (
  101. &md5Context,
  102. reinterpret_cast <const unsigned char * > (pBuffer2),
  103. dwSize2
  104. );
  105. }
  106. if ((NULL != pBuffer3) && (0 != dwSize3))
  107. {
  108. MD5Update (
  109. &md5Context,
  110. reinterpret_cast <const unsigned char * > (pBuffer3),
  111. dwSize3
  112. );
  113. }
  114. if ((NULL != pBuffer4) && (0 != dwSize4))
  115. {
  116. MD5Update (
  117. &md5Context,
  118. reinterpret_cast <const unsigned char * > (pBuffer4),
  119. dwSize4
  120. );
  121. }
  122. if ((NULL != pBuffer5) && (0 != dwSize5))
  123. {
  124. MD5Update (
  125. &md5Context,
  126. reinterpret_cast <const unsigned char * > (pBuffer5),
  127. dwSize5
  128. );
  129. }
  130. MD5Final (&md5Context);
  131. ::memcpy (pbyAuthenticator, md5Context.digest, MD5DIGESTLEN);
  132. //
  133. // done the hashing
  134. //
  135. bRetVal = TRUE;
  136. }
  137. __finally
  138. {
  139. //
  140. // nothing here for now
  141. //
  142. }
  143. return (bRetVal);
  144. } // end of CHashMD5::HashIt method