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.

128 lines
3.5 KiB

  1. /* Copyright (c) 1993, Microsoft Corporation, all rights reserved
  2. **
  3. ** ppputil.h
  4. ** Public header for miscellaneuos PPP common library functions.
  5. */
  6. #ifndef _PWUTIL_H_
  7. #define _PWUTIL_H_
  8. #ifndef USE_PROTECT_MEMORY
  9. #define USE_PROTECT_MEMORY
  10. #endif
  11. VOID
  12. DecodePasswordA(
  13. CHAR* pszPassword
  14. );
  15. VOID
  16. DecodePasswordW(
  17. WCHAR* pszPassword
  18. );
  19. VOID
  20. EncodePasswordA(
  21. CHAR* pszPassword
  22. );
  23. VOID
  24. EncodePasswordW(
  25. WCHAR* pszPassword
  26. );
  27. VOID
  28. WipePasswordA(
  29. CHAR* pszPassword
  30. );
  31. VOID
  32. WipePasswordW(
  33. WCHAR* pszPassword
  34. );
  35. //New safer APIs to protect password. for .Net 534499 and LH 754400
  36. #ifdef USE_PROTECT_MEMORY
  37. //dwInSize has to be multiple of 16 bytes.
  38. DWORD EncryptMemoryInPlace(
  39. IN OUT PBYTE pbIn,
  40. IN DWORD dwInSize);
  41. DWORD DecryptMemoryInPlace(
  42. IN OUT PBYTE pbIn,
  43. IN DWORD dwInSize);
  44. DWORD WipeMemoryInPlace(
  45. IN OUT PBYTE pbIn,
  46. IN DWORD dwInSize);
  47. DWORD CopyMemoryInPlace(
  48. IN OUT PBYTE pbDest,
  49. IN DWORD dwDestSize,
  50. IN PBYTE pbSrc,
  51. IN DWORD dwSrcSize);
  52. DWORD TrimToMul16(
  53. IN DWORD dwSize);
  54. #else
  55. DWORD EncodePasswordInPlace(
  56. IN OUT PBYTE pbIn,
  57. IN DWORD dwInSize);
  58. DWORD DecodePasswordInPlace(
  59. IN OUT PBYTE pbIn,
  60. IN DWORD dwInSize);
  61. DWORD
  62. WipePasswordInPlace(
  63. IN OUT PBYTE pbIn,
  64. IN DWORD dwInSize);
  65. DWORD CopyPasswordInPlace(
  66. IN OUT PBYTE pbDest,
  67. IN DWORD dwDestSize,
  68. IN PBYTE pbSrc,
  69. IN DWORD dwSrcSize);
  70. #endif
  71. #ifdef UNICODE
  72. #define DecodePassword DecodePasswordW
  73. #define EncodePassword EncodePasswordW
  74. #define WipePassword WipePasswordW
  75. #else
  76. #define DecodePassword DecodePasswordA
  77. #define EncodePassword EncodePasswordA
  78. #define WipePassword WipePasswordA
  79. #endif
  80. //!!!
  81. //XXXXBuf macros are only meant for array buffers like szPassword[PWLEN+1];
  82. //for pointers to strings, the calller has to use SafeEncodePassword and as such
  83. //
  84. #ifdef USE_PROTECT_MEMORY
  85. #define SafeEncodePassword EncryptMemoryInPlace
  86. #define SafeDecodePassword DecryptMemoryInPlace
  87. #define SafeWipePassword WipeMemoryInPlace
  88. #define SafeCopyPassword CopyMemoryInPlace
  89. #define SafeCopyPasswordBuf(x,y) CopyMemoryInPlace((PBYTE)(x),TrimToMul16(sizeof((x))),(PBYTE)(y),TrimToMul16(sizeof((y))))
  90. #define SafeEncodePasswordBuf(x) EncryptMemoryInPlace((PBYTE)(x),TrimToMul16(sizeof((x))))
  91. #define SafeDecodePasswordBuf(x) DecryptMemoryInPlace((PBYTE)(x), TrimToMul16(sizeof((x))))
  92. #define SafeWipePasswordBuf(x) WipeMemoryInPlace((PBYTE)(x), sizeof((x)))
  93. #else
  94. #define SafeEncodePassword EncodePasswordInPlace
  95. #define SafeDecodePassword DecodePasswordInPlace
  96. #define SafeWipePassword WipePasswordInPlace
  97. #define SafeCopyPassword CopyPasswordInPlace
  98. #define SafeCopyPasswordBuf(x,y) CopyPasswordInPlace((PBYTE)(x),sizeof((x)),(PBYTE)(y), sizeof((y)))
  99. #define SafeEncodePasswordBuf(x) EncodePasswordInPlace((PBYTE)(x), sizeof((x)))
  100. #define SafeDecodePasswordBuf(x) DecodePasswordInPlace((PBYTE)(x), sizeof((x)))
  101. #define SafeWipePasswordBuf(x) WipePasswordInPlace((PBYTE)(x), sizeof((x)))
  102. #endif
  103. #endif // _PWUTIL_H_
  104.