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.

161 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. owf.c
  5. Abstract:
  6. Implentation of the one-way-functions used to implement password hashing.
  7. CalculateLmOwfPassword
  8. Author:
  9. David Chalmers (Davidc) 10-21-91
  10. David Arnold (DavidAr) 12-15-93 (Adapted for WfW RPC SSP)
  11. Revision History:
  12. --*/
  13. #ifdef BLDR_KERNEL_RUNTIME
  14. #include <bootdefs.h>
  15. #endif
  16. #include <descrypt.h>
  17. #include <ntlmsspi.h>
  18. #include <crypt.h>
  19. #include <descrypt.h>
  20. #include <md4.h>
  21. #include <string.h>
  22. BOOL
  23. CalculateLmOwfPassword(
  24. IN PLM_PASSWORD LmPassword,
  25. OUT PLM_OWF_PASSWORD LmOwfPassword
  26. )
  27. /*++
  28. Routine Description:
  29. Takes the passed LmPassword and performs a one-way-function on it.
  30. The current implementation does this by using the password as a key
  31. to encrypt a known block of text.
  32. Arguments:
  33. LmPassword - The password to perform the one-way-function on.
  34. LmOwfPassword - The hashed password is returned here
  35. Return Values:
  36. TRUE - The function was completed successfully. The hashed
  37. password is in LmOwfPassword.
  38. FALSE - Something failed. The LmOwfPassword is undefined.
  39. --*/
  40. {
  41. char StdEncrPwd[] = "KGS!@#$%";
  42. BLOCK_KEY Key[2];
  43. PCHAR pKey;
  44. // Copy the password into our key buffer and zero pad to fill the 2 keys
  45. pKey = (PCHAR)(&Key[0]);
  46. while (*LmPassword && (pKey < (PCHAR)(&Key[2]))) {
  47. *pKey++ = *LmPassword++;
  48. }
  49. while (pKey < (PCHAR)(&Key[2])) {
  50. *pKey++ = 0;
  51. }
  52. // Use the keys to encrypt the standard text
  53. if (DES_ECB_LM(ENCR_KEY,
  54. (char *)&Key[0],
  55. (unsigned char *)StdEncrPwd,
  56. (unsigned char *)&LmOwfPassword->data[0]
  57. ) != CRYPT_OK) {
  58. return (FALSE);
  59. }
  60. if (DES_ECB_LM(ENCR_KEY,
  61. (char *)&Key[1],
  62. (unsigned char *)StdEncrPwd,
  63. (unsigned char *)&LmOwfPassword->data[1]
  64. ) != CRYPT_OK) {
  65. return (FALSE);
  66. }
  67. //
  68. // clear our copy of the cleartext password
  69. //
  70. pKey = (PCHAR)(&Key[0]);
  71. while (pKey < (PCHAR)(&Key[2])) {
  72. *pKey++ = 0;
  73. }
  74. return(TRUE);
  75. }
  76. BOOL
  77. CalculateNtOwfPassword(
  78. IN PNT_PASSWORD NtPassword,
  79. OUT PNT_OWF_PASSWORD NtOwfPassword
  80. )
  81. /*++
  82. Routine Description:
  83. Takes the passed NtPassword and performs a one-way-function on it.
  84. Uses the RSA MD4 function
  85. Arguments:
  86. NtPassword - The password to perform the one-way-function on.
  87. NtOwfPassword - The hashed password is returned here
  88. Return Values:
  89. STATUS_SUCCESS - The function was completed successfully. The hashed
  90. password is in NtOwfPassword.
  91. --*/
  92. {
  93. MD4_CTX MD4_Context;
  94. MD4Init(&MD4_Context);
  95. MD4Update(&MD4_Context, (PUCHAR)NtPassword->Buffer, NtPassword->Length);
  96. MD4Final(&MD4_Context);
  97. if (sizeof(*NtOwfPassword) != sizeof(MD4_Context.digest)) {
  98. return(FALSE);
  99. }
  100. memcpy(NtOwfPassword, MD4_Context.digest, sizeof(*NtOwfPassword));
  101. return(TRUE);
  102. }