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.

169 lines
5.4 KiB

  1. #ifndef __STRESTST__H__
  2. #define __STRESTST__H__
  3. #include <windows.h>
  4. #include <wincrypt.h>
  5. #define APP_NAME "cspstres"
  6. #define KEY_CONTAINER_NAME "CspStressKey"
  7. #define ERROR_CAPTION "ERROR : cspstres "
  8. #define STRESS_DEFAULT_THREAD_COUNT 8
  9. #define MAX_THREADS MAXIMUM_WAIT_OBJECTS
  10. #define PLAIN_BUFFER_SIZE 30000
  11. #define HASH_DATA_SIZE 14999
  12. #define SIGN_DATA_SIZE 999
  13. #define PROV_PARAM_BUFFER_SIZE 256
  14. #define RSA_AES_CSP "rsaaes.dll"
  15. #define ENUMERATE_REGISTERED_CSP -1
  16. #define GENERIC_FAIL(X) { \
  17. sprintf(szErrorMsg, "%s error 0x%x\n", #X, GetLastError()); \
  18. MessageBox(NULL, szErrorMsg, ERROR_CAPTION, MB_OK | MB_ICONERROR); \
  19. goto ErrorReturn ; \
  20. }
  21. #define ALLOC_FAIL(X) { \
  22. sprintf(szErrorMsg, "%s alloc error 0x%x\n", #X, GetLastError()); \
  23. MessageBox(NULL, szErrorMsg, ERROR_CAPTION, MB_OK | MB_ICONERROR); \
  24. goto ErrorReturn; \
  25. }
  26. #define DW_INUSE 0
  27. #define DW_HASH_ALGID 1
  28. #define DW_END_CERT_INDEX 2
  29. //
  30. // Struct: ALGNODE
  31. // Purpose: A linked list of CSP algorithms
  32. //
  33. typedef struct _ALGNODE
  34. {
  35. struct _ALGNODE *pNext;
  36. PROV_ENUMALGS_EX EnumalgsEx;
  37. } ALGNODE, *PALGNODE;
  38. //
  39. // Struct: THREAD_DATA
  40. // Purpose: This is the data passed to the entry point
  41. // shared by each of the worker/test threads.
  42. //
  43. typedef struct _THREAD_DATA
  44. {
  45. DWORD rgdwThreadStatus[MAX_THREADS];
  46. DWORD dwThreadCount;
  47. DWORD dwProgramMins;
  48. PALGNODE pAlgList;
  49. CHAR rgszProvName[MAX_PATH];
  50. DWORD dwProvType;
  51. BOOL fEphemeralKeys;
  52. BOOL fUserProtectedKeys;
  53. HCRYPTPROV hProv;
  54. HCRYPTPROV hVerifyCtx;
  55. HCRYPTKEY hExchangeKey;
  56. HCRYPTKEY hSignatureKey;
  57. HANDLE hEndTestEvent;
  58. CRITICAL_SECTION CSThreadData;
  59. DWORD dwThreadID; // Not thread safe
  60. DWORD dwTestsToRun;
  61. } THREAD_DATA, *PTHREAD_DATA;
  62. // ************
  63. // Stress Tests
  64. // ************
  65. #define RUN_THREAD_SIGNATURE_TEST 0x00000001
  66. #define RUN_STRESS_TEST_ALL_ENCRYPTION_ALGS 0x00000002
  67. #define RUN_THREAD_HASHING_TEST 0x00000004
  68. #define RUN_THREAD_ACQUIRE_CONTEXT_TEST 0x00000008
  69. #define RUN_ALL_TESTS 0xffffffff
  70. //
  71. // Function: StressGetDefaultThreadCount
  72. // Purpose: Return the default number of worker/test threads to be
  73. // created by a stress test. This will be equal to the number
  74. // of processors on the host system, unless there's only one, in
  75. // which case the value returned will be STRESS_DEFAULT_THREAD_COUNT.
  76. //
  77. DWORD StressGetDefaultThreadCount(void);
  78. // *****************
  79. // Memory management
  80. // *****************
  81. //
  82. // Function: MyAlloc
  83. // Purpose: Wrapper for calling thread-safe HeapAlloc
  84. // with default params.
  85. //
  86. LPVOID MyAlloc(SIZE_T);
  87. //
  88. // Function: MyFree
  89. // Purpose: Wrapper for calling thread-safe HeapFree
  90. // with default params.
  91. //
  92. BOOL MyFree(LPVOID);
  93. //
  94. // Function: PrintBytes
  95. //
  96. void PrintBytes(LPSTR pszHdr, BYTE *pb, DWORD cbSize);
  97. // ***************
  98. // Encryption Test
  99. // ***************
  100. //
  101. // Struct: ENCRYPTION_TEST_DATA
  102. // Purpose: Parameters for the StressEncryptionTest function.
  103. //
  104. typedef struct _ENCRYPTION_TEST_DATA
  105. {
  106. ALG_ID aiEncryptionKey;
  107. ALG_ID aiHash;
  108. ALG_ID aiHashKey;
  109. } ENCRYPTION_TEST_DATA, *PENCRYPTION_TEST_DATA;
  110. // ****************
  111. // Regression Tests
  112. // ****************
  113. typedef DWORD (*PREGRESSION_TEST)(PTHREAD_DATA);
  114. typedef struct _REGRESS_TEST_TABLE_ENTRY
  115. {
  116. PREGRESSION_TEST pfTest;
  117. DWORD dwExclude;
  118. LPSTR pszDescription;
  119. } REGRESS_TEST_TABLE_ENTRY, *PREGRESS_TEST_TABLE_ENTRY;
  120. DWORD KeyArchiveRegression(PTHREAD_DATA pThreadData);
  121. DWORD PlaintextBlobRegression(PTHREAD_DATA pThreadData);
  122. DWORD LoadAesCspRegression(PTHREAD_DATA pThreadData);
  123. DWORD DesImportRegression(PTHREAD_DATA pThreadData);
  124. DWORD KnownBlockCipherKeyRegression(PTHREAD_DATA pThreadData);
  125. DWORD PinCacheRegression(PTHREAD_DATA pThreadData);
  126. DWORD DesGetKeyParamRegression(PTHREAD_DATA pThreadData);
  127. DWORD MacEncryptRegression(IN PTHREAD_DATA pThreadData);
  128. DWORD HmacRegression(PTHREAD_DATA pThreadData);
  129. DWORD UnalignedImportExportRegression(PTHREAD_DATA pThreadData);
  130. static const REGRESS_TEST_TABLE_ENTRY g_rgRegressTests [] = {
  131. { KeyArchiveRegression, 0, "KeyArchiveRegression for CRYPT_ARCHIVABLE flag" },
  132. { PlaintextBlobRegression, 0, "PlaintextBlobRegression for PLAINTEXTKEYBLOB blob type" },
  133. { LoadAesCspRegression, 0, "LoadAesCspRegression for DllInitialize" },
  134. { DesImportRegression, 0, "DesImportRegression for parity and non-parity key sizes" },
  135. { KnownBlockCipherKeyRegression, 0, "KnownBlockCipherKeyRegression for CSP compatibility"},
  136. { PinCacheRegression, 0, "PinCacheRegression for smart-card pin caching lib"},
  137. { DesGetKeyParamRegression, 0, "DesGetKeyParamRegression for des KP_KEYLEN and KP_EFFECTIVE_KEYLEN" },
  138. { MacEncryptRegression, 0, "MacEncryptRegression for simultaneous encrypt/decrypt and MAC" },
  139. { HmacRegression, 0, "HmacRegression for CRYPT_IPSEC_HMAC_KEY processing" },
  140. { UnalignedImportExportRegression, 0, "UnalignedImportExportRegression for key blob alignment" }
  141. };
  142. static const unsigned g_cRegressTests =
  143. sizeof(g_rgRegressTests) / sizeof(REGRESS_TEST_TABLE_ENTRY);
  144. #endif