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.

150 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1989-1997 Microsoft Corporation
  3. Module Name:
  4. owf.c
  5. Abstract:
  6. Implentation of the one-way-functions used to implement password hashing.
  7. RtlCalculateLmOwfPassword
  8. RtlCalculateNtOwfPassword
  9. Author:
  10. David Chalmers (Davidc) 10-21-91
  11. Revision History:
  12. Adam Barr (AdamBa) 12-15-97
  13. Modified from private\security\lsa\crypt\dll
  14. --*/
  15. #include <rdrssp.h>
  16. NTSTATUS
  17. RtlCalculateLmOwfPassword(
  18. IN PLM_PASSWORD LmPassword,
  19. OUT PLM_OWF_PASSWORD LmOwfPassword
  20. )
  21. /*++
  22. Routine Description:
  23. Takes the passed LmPassword and performs a one-way-function on it.
  24. The current implementation does this by using the password as a key
  25. to encrypt a known block of text.
  26. Arguments:
  27. LmPassword - The password to perform the one-way-function on.
  28. LmOwfPassword - The hashed password is returned here
  29. Return Values:
  30. STATUS_SUCCESS - The function was completed successfully. The hashed
  31. password is in LmOwfPassword.
  32. STATUS_UNSUCCESSFUL - Something failed. The LmOwfPassword is undefined.
  33. --*/
  34. {
  35. NTSTATUS Status;
  36. BLOCK_KEY Key[2];
  37. PCHAR pKey;
  38. // Copy the password into our key buffer and zero pad to fill the 2 keys
  39. pKey = (PCHAR)(&Key[0]);
  40. while (*LmPassword && (pKey < (PCHAR)(&Key[2]))) {
  41. *pKey++ = *LmPassword++;
  42. }
  43. while (pKey < (PCHAR)(&Key[2])) {
  44. *pKey++ = 0;
  45. }
  46. // Use the keys to encrypt the standard text
  47. Status = RtlEncryptStdBlock(&Key[0], &(LmOwfPassword->data[0]));
  48. if (!NT_SUCCESS(Status)) {
  49. return(Status);
  50. }
  51. Status = RtlEncryptStdBlock(&Key[1], &(LmOwfPassword->data[1]));
  52. //
  53. // clear our copy of the cleartext password
  54. //
  55. pKey = (PCHAR)(&Key[0]);
  56. while (pKey < (PCHAR)(&Key[2])) {
  57. *pKey++ = 0;
  58. }
  59. return(Status);
  60. }
  61. NTSTATUS
  62. RtlCalculateNtOwfPassword(
  63. IN PNT_PASSWORD NtPassword,
  64. OUT PNT_OWF_PASSWORD NtOwfPassword
  65. )
  66. /*++
  67. Routine Description:
  68. Takes the passed NtPassword and performs a one-way-function on it.
  69. Uses the RSA MD4 function
  70. Arguments:
  71. NtPassword - The password to perform the one-way-function on.
  72. NtOwfPassword - The hashed password is returned here
  73. Return Values:
  74. STATUS_SUCCESS - The function was completed successfully. The hashed
  75. password is in NtOwfPassword.
  76. --*/
  77. {
  78. MD4_CTX MD4_Context;
  79. MD4Init(&MD4_Context);
  80. MD4Update(&MD4_Context, (PCHAR)NtPassword->Buffer, NtPassword->Length);
  81. MD4Final(&MD4_Context);
  82. // Copy the digest into our return data area
  83. ASSERT(sizeof(*NtOwfPassword) == sizeof(MD4_Context.digest));
  84. RtlMoveMemory((PVOID)NtOwfPassword, (PVOID)MD4_Context.digest,
  85. sizeof(*NtOwfPassword));
  86. return(STATUS_SUCCESS);
  87. }