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.

140 lines
3.4 KiB

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