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.

180 lines
3.8 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: cryptmgr.c
  8. //
  9. // Contents: Crypto manager
  10. //
  11. //
  12. // History: xx Dec 91 RichardW Created
  13. // 04 Jun 92 RichardW NTized
  14. //
  15. //------------------------------------------------------------------------
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <windows.h>
  20. #include <security.h>
  21. #include <cryptdll.h>
  22. #ifdef KERNEL_MODE
  23. #pragma alloc_text( PAGEMSG, CDRegisterCSystem )
  24. #pragma alloc_text( PAGEMSG, CDBuildVect )
  25. #pragma alloc_text( PAGEMSG, CDBuildIntegrityVect )
  26. #pragma alloc_text( PAGEMSG, CDLocateCSystem )
  27. #pragma alloc_text( PAGEMSG, CDFindCommonCSystem )
  28. #pragma alloc_text( PAGEMSG, CDFindCommonCSystemWithKey )
  29. #endif
  30. #define MAX_CSYSTEMS 16
  31. CRYPTO_SYSTEM CSystems[MAX_CSYSTEMS];
  32. ULONG cCSystems = 0;
  33. ULONG cIntegrityCSystems = 0;
  34. // Register the crypto system
  35. NTSTATUS NTAPI
  36. CDRegisterCSystem( PCRYPTO_SYSTEM pcsNewSystem)
  37. {
  38. if (cCSystems + 1 < MAX_CSYSTEMS)
  39. {
  40. CSystems[cCSystems++] = *pcsNewSystem;
  41. if ((pcsNewSystem->Attributes & CSYSTEM_INTEGRITY_PROTECTED) != 0)
  42. {
  43. cIntegrityCSystems++;
  44. }
  45. return(S_OK);
  46. }
  47. return(STATUS_INSUFFICIENT_RESOURCES);
  48. }
  49. NTSTATUS NTAPI
  50. CDBuildVect( ULONG * pcCSystems,
  51. ULONG * pdwEtypes)
  52. {
  53. ULONG iCS;
  54. *pcCSystems = cCSystems;
  55. if (!pdwEtypes)
  56. {
  57. return(S_OK);
  58. }
  59. for (iCS = 0; iCS < cCSystems; iCS++)
  60. {
  61. *pdwEtypes++ = CSystems[iCS].EncryptionType;
  62. }
  63. return(S_OK);
  64. }
  65. NTSTATUS NTAPI
  66. CDBuildIntegrityVect(
  67. PULONG pcCSystems,
  68. PULONG pdwEtypes)
  69. {
  70. ULONG iCS;
  71. *pcCSystems = cIntegrityCSystems;
  72. if (!pdwEtypes)
  73. {
  74. return(S_OK);
  75. }
  76. for (iCS = 0; iCS < cCSystems; iCS++)
  77. {
  78. if ((CSystems[iCS].Attributes & CSYSTEM_INTEGRITY_PROTECTED) != 0)
  79. {
  80. *pdwEtypes++ = CSystems[iCS].EncryptionType;
  81. }
  82. }
  83. return(S_OK);
  84. }
  85. NTSTATUS NTAPI
  86. CDLocateCSystem(ULONG dwEtype,
  87. PCRYPTO_SYSTEM * ppcsSystem)
  88. {
  89. ULONG iCS = cCSystems;
  90. while (iCS--)
  91. {
  92. if (CSystems[iCS].EncryptionType == dwEtype)
  93. {
  94. *ppcsSystem = &CSystems[iCS];
  95. return(S_OK);
  96. }
  97. }
  98. return(SEC_E_ETYPE_NOT_SUPP);
  99. }
  100. NTSTATUS NTAPI
  101. CDFindCommonCSystem(ULONG cEntries,
  102. ULONG * pdwEtypes,
  103. ULONG * pdwCommonEtype)
  104. {
  105. ULONG i, j;
  106. *pdwCommonEtype = 0;
  107. for (i = 0; i < cEntries ; i++)
  108. {
  109. for (j = 0 ; j < cCSystems ; j++ )
  110. {
  111. if (pdwEtypes[i] == CSystems[j].EncryptionType)
  112. {
  113. *pdwCommonEtype = pdwEtypes[i];
  114. return(STATUS_SUCCESS);
  115. }
  116. }
  117. }
  118. return(SEC_E_ETYPE_NOT_SUPP);
  119. }
  120. NTSTATUS NTAPI
  121. CDFindCommonCSystemWithKey(
  122. IN ULONG EncryptionEntries,
  123. IN PULONG EncryptionTypes,
  124. IN ULONG KeyTypeCount,
  125. IN PULONG KeyTypes,
  126. OUT PULONG CommonEtype)
  127. {
  128. ULONG i, j, k;
  129. *CommonEtype = 0;
  130. for (i = 0; i < EncryptionEntries ; i++)
  131. {
  132. for (j = 0 ; j < cCSystems ; j++ )
  133. {
  134. if (EncryptionTypes[i] == CSystems[j].EncryptionType)
  135. {
  136. //
  137. // Make sure we have a key for this encryption type
  138. //
  139. for (k = 0; k < KeyTypeCount ; k++ )
  140. {
  141. if (KeyTypes[k] == EncryptionTypes[i])
  142. {
  143. *CommonEtype = EncryptionTypes[i];
  144. return(STATUS_SUCCESS);
  145. }
  146. }
  147. }
  148. }
  149. }
  150. return(SEC_E_ETYPE_NOT_SUPP);
  151. }