Source code of Windows XP (NT5)
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.

176 lines
2.9 KiB

  1. //
  2. //
  3. #ifndef KERNEL_MODE
  4. #include <nt.h>
  5. #include <ntrtl.h>
  6. #include <nturtl.h>
  7. #include <windows.h>
  8. #else
  9. #include <ntddk.h>
  10. #include <winerror.h>
  11. #endif
  12. #include <string.h>
  13. #include <malloc.h>
  14. #include <security.h>
  15. #include <cryptdll.h>
  16. #include <kerbcon.h>
  17. #include "sha.h"
  18. NTSTATUS
  19. ShaWrapInitialize(ULONG dwSeed,
  20. PCHECKSUM_BUFFER * ppcsBuffer);
  21. NTSTATUS
  22. ShaWrapInitializeEx(PUCHAR Seed, ULONG dwSeedLength, ULONG MessageType,
  23. PCHECKSUM_BUFFER * ppcsBuffer);
  24. NTSTATUS
  25. ShaWrapSum( PCHECKSUM_BUFFER pcsBuffer,
  26. ULONG cbData,
  27. PUCHAR pbData );
  28. NTSTATUS
  29. ShaWrapFinalize( PCHECKSUM_BUFFER pcsBuffer,
  30. PUCHAR pbSum);
  31. NTSTATUS
  32. ShaWrapFinish(PCHECKSUM_BUFFER * ppcsBuffer);
  33. CHECKSUM_FUNCTION csfSHA = {
  34. KERB_CHECKSUM_SHA1,
  35. A_SHA_DIGEST_LEN,
  36. CKSUM_COLLISION,
  37. ShaWrapInitialize,
  38. ShaWrapSum,
  39. ShaWrapFinalize,
  40. ShaWrapFinish,
  41. ShaWrapInitializeEx,
  42. NULL
  43. };
  44. #ifdef KERNEL_MODE
  45. #pragma alloc_text( PAGEMSG, ShaWrapInitialize )
  46. #pragma alloc_text( PAGEMSG, ShaWrapSum )
  47. #pragma alloc_text( PAGEMSG, ShaWrapFinalize )
  48. #pragma alloc_text( PAGEMSG, ShaWrapFinish )
  49. #pragma alloc_text( PAGEMSG, ShaWrapInitializeEx )
  50. #endif
  51. NTSTATUS
  52. ShaWrapInitialize(
  53. ULONG dwSeed,
  54. PCHECKSUM_BUFFER * ppcsBuffer)
  55. {
  56. A_SHA_CTX * pContext;
  57. #ifdef KERNEL_MODE
  58. pContext = ExAllocatePool( NonPagedPool, sizeof( A_SHA_CTX ) );
  59. #else
  60. pContext = LocalAlloc( LMEM_FIXED, sizeof( A_SHA_CTX ) );
  61. #endif
  62. if ( pContext )
  63. {
  64. A_SHAInit( pContext );
  65. *ppcsBuffer = pContext;
  66. return( SEC_E_OK );
  67. }
  68. return( STATUS_NO_MEMORY );
  69. }
  70. NTSTATUS
  71. ShaWrapInitializeEx(
  72. PUCHAR Seed,
  73. ULONG SeedLength,
  74. ULONG MessageType,
  75. PCHECKSUM_BUFFER * ppcsBuffer)
  76. {
  77. A_SHA_CTX * pContext;
  78. #ifdef KERNEL_MODE
  79. pContext = ExAllocatePool( NonPagedPool, sizeof( A_SHA_CTX ) );
  80. #else
  81. pContext = LocalAlloc( LMEM_FIXED, sizeof( A_SHA_CTX ) );
  82. #endif
  83. if ( pContext )
  84. {
  85. A_SHAInit( pContext );
  86. *ppcsBuffer = pContext;
  87. return( SEC_E_OK );
  88. }
  89. return( STATUS_NO_MEMORY );
  90. }
  91. NTSTATUS
  92. ShaWrapSum(
  93. PCHECKSUM_BUFFER pcsBuffer,
  94. ULONG cbData,
  95. PUCHAR pbData )
  96. {
  97. A_SHA_CTX * pContext;
  98. pContext = (A_SHA_CTX *) pcsBuffer ;
  99. A_SHAUpdate( pContext, pbData, cbData );
  100. return( STATUS_SUCCESS );
  101. }
  102. NTSTATUS
  103. ShaWrapFinalize(
  104. PCHECKSUM_BUFFER pcsBuffer,
  105. PUCHAR pbSum)
  106. {
  107. A_SHA_CTX * pContext;
  108. pContext = (A_SHA_CTX *) pcsBuffer ;
  109. A_SHAFinal( pContext, pbSum );
  110. return( STATUS_SUCCESS );
  111. }
  112. NTSTATUS
  113. ShaWrapFinish(
  114. PCHECKSUM_BUFFER * ppcsBuffer)
  115. {
  116. RtlZeroMemory( *ppcsBuffer, sizeof( A_SHA_CTX ) );
  117. #ifdef KERNEL_MODE
  118. ExFreePool( *ppcsBuffer );
  119. #else
  120. LocalFree( *ppcsBuffer );
  121. #endif
  122. *ppcsBuffer = NULL ;
  123. return( STATUS_SUCCESS );
  124. }