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.

109 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. data2.c
  5. Abstract:
  6. Arbitrary length data encryption functions implementation :
  7. RtlEncryptData2
  8. RtlDecryptData2
  9. Author:
  10. Richard Ward (richardw) 20 Dec 93
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <crypt.h>
  16. #include <engine.h>
  17. #include <rc4.h>
  18. NTSTATUS
  19. RtlEncryptData2(
  20. IN OUT PCRYPT_BUFFER pData,
  21. IN PDATA_KEY pKey
  22. )
  23. /*++
  24. Routine Description:
  25. Takes an arbitrary length block of data and encrypts it with a
  26. data key producing an encrypted block of data.
  27. Arguments:
  28. pData - The data that will be encrypt, IN PLACE
  29. pKey - The key to use to encrypt the data
  30. Return Values:
  31. STATUS_SUCCESS
  32. --*/
  33. {
  34. struct RC4_KEYSTRUCT Key;
  35. if ( pData->Length != 0 ) {
  36. rc4_key(&Key, pKey->Length, pKey->Buffer);
  37. rc4(&Key, pData->Length, pData->Buffer);
  38. RtlSecureZeroMemory( &Key, sizeof(Key) );
  39. }
  40. return STATUS_SUCCESS;
  41. }
  42. NTSTATUS
  43. RtlDecryptData2(
  44. IN OUT PCRYPT_BUFFER pData,
  45. IN PDATA_KEY pKey
  46. )
  47. /*++
  48. Routine Description:
  49. Takes an arbitrary length block of data and encrypts it with a
  50. data key producing an encrypted block of data.
  51. Arguments:
  52. pData - The data that will be encrypt, IN PLACE
  53. pKey - The key to use to encrypt the data
  54. Return Values:
  55. STATUS_SUCCESS
  56. --*/
  57. {
  58. struct RC4_KEYSTRUCT Key;
  59. if ( pData->Length != 0 ) {
  60. rc4_key(&Key, pKey->Length, pKey->Buffer);
  61. rc4(&Key, pData->Length, pData->Buffer);
  62. RtlSecureZeroMemory( &Key, sizeof(Key) );
  63. }
  64. return STATUS_SUCCESS;
  65. }