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.

188 lines
7.0 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. BOOL fSkipPinAttackTest;
  62. } THREAD_DATA, *PTHREAD_DATA;
  63. // ************
  64. // Stress Tests
  65. // ************
  66. #define RUN_THREAD_SIGNATURE_TEST 0x00000001
  67. #define RUN_STRESS_TEST_ALL_ENCRYPTION_ALGS 0x00000002
  68. #define RUN_THREAD_HASHING_TEST 0x00000004
  69. #define RUN_THREAD_ACQUIRE_CONTEXT_TEST 0x00000008
  70. #define RUN_ALL_TESTS 0xffffffff
  71. //
  72. // Function: StressGetDefaultThreadCount
  73. // Purpose: Return the default number of worker/test threads to be
  74. // created by a stress test. This will be equal to the number
  75. // of processors on the host system, unless there's only one, in
  76. // which case the value returned will be STRESS_DEFAULT_THREAD_COUNT.
  77. //
  78. DWORD StressGetDefaultThreadCount(void);
  79. // *****************
  80. // Memory management
  81. // *****************
  82. //
  83. // Function: MyAlloc
  84. // Purpose: Wrapper for calling thread-safe HeapAlloc
  85. // with default params.
  86. //
  87. LPVOID MyAlloc(SIZE_T);
  88. //
  89. // Function: MyFree
  90. // Purpose: Wrapper for calling thread-safe HeapFree
  91. // with default params.
  92. //
  93. BOOL MyFree(LPVOID);
  94. //
  95. // Function: PrintBytes
  96. //
  97. void PrintBytes(LPSTR pszHdr, BYTE *pb, DWORD cbSize);
  98. // ***************
  99. // Encryption Test
  100. // ***************
  101. //
  102. // Struct: ENCRYPTION_TEST_DATA
  103. // Purpose: Parameters for the StressEncryptionTest function.
  104. //
  105. typedef struct _ENCRYPTION_TEST_DATA
  106. {
  107. ALG_ID aiEncryptionKey;
  108. ALG_ID aiHash;
  109. ALG_ID aiHashKey;
  110. } ENCRYPTION_TEST_DATA, *PENCRYPTION_TEST_DATA;
  111. // ****************
  112. // Regression Tests
  113. // ****************
  114. typedef DWORD (*PREGRESSION_TEST)(PTHREAD_DATA);
  115. typedef struct _REGRESS_TEST_TABLE_ENTRY
  116. {
  117. PREGRESSION_TEST pfTest;
  118. DWORD dwExclude;
  119. LPSTR pszDescription;
  120. } REGRESS_TEST_TABLE_ENTRY, *PREGRESS_TEST_TABLE_ENTRY;
  121. DWORD KeyArchiveRegression(PTHREAD_DATA pThreadData);
  122. DWORD PlaintextBlobRegression(PTHREAD_DATA pThreadData);
  123. DWORD LoadAesCspRegression(PTHREAD_DATA pThreadData);
  124. DWORD DesImportRegression(PTHREAD_DATA pThreadData);
  125. DWORD KnownBlockCipherKeyRegression(PTHREAD_DATA pThreadData);
  126. DWORD PinCacheRegression(PTHREAD_DATA pThreadData);
  127. DWORD DesGetKeyParamRegression(PTHREAD_DATA pThreadData);
  128. DWORD MacEncryptRegression(IN PTHREAD_DATA pThreadData);
  129. DWORD HmacRegression(PTHREAD_DATA pThreadData);
  130. DWORD UnalignedImportExportRegression(PTHREAD_DATA pThreadData);
  131. DWORD CFBCipherModeRegression(PTHREAD_DATA pThreadData);
  132. DWORD AESMonteCarloCBCRegression(PTHREAD_DATA pThreadData);
  133. DWORD AesDeriveKeyRegression(PTHREAD_DATA pThreadData);
  134. DWORD NewShaModesHmacRegression(PTHREAD_DATA pThreadData);
  135. DWORD NewShaModesBasicRegression(PTHREAD_DATA pThreadData);
  136. DWORD NewShaModesSigningRegression(PTHREAD_DATA pThreadData);
  137. DWORD NewShaModesHashSessionKeyRegression(PTHREAD_DATA pThreadData);
  138. DWORD NewShaModesDeriveKeyRegression(PTHREAD_DATA pThreadData);
  139. static const REGRESS_TEST_TABLE_ENTRY g_rgRegressTests [] = {
  140. { KeyArchiveRegression, 0, "KeyArchiveRegression for CRYPT_ARCHIVABLE flag" },
  141. { PlaintextBlobRegression, 0, "PlaintextBlobRegression for PLAINTEXTKEYBLOB blob type" },
  142. { LoadAesCspRegression, 0, "LoadAesCspRegression for DllInitialize" },
  143. { DesImportRegression, 0, "DesImportRegression for parity and non-parity key sizes" },
  144. { KnownBlockCipherKeyRegression, 0, "KnownBlockCipherKeyRegression for CSP compatibility"},
  145. { PinCacheRegression, 0, "PinCacheRegression for smart-card pin caching lib"},
  146. { DesGetKeyParamRegression, 0, "DesGetKeyParamRegression for des KP_KEYLEN and KP_EFFECTIVE_KEYLEN" },
  147. { MacEncryptRegression, 0, "MacEncryptRegression for simultaneous encrypt/decrypt and MAC" },
  148. { HmacRegression, 0, "HmacRegression for CRYPT_IPSEC_HMAC_KEY processing" },
  149. { UnalignedImportExportRegression, 0, "UnalignedImportExportRegression for key blob alignment" },
  150. { CFBCipherModeRegression, 0, "CFBCipherModeRegression for cipher feedback mode" },
  151. // { AESMonteCarloCBCRegression, 0, "AESMonteCarloCBCRegression for AES CBC mode cipher" },
  152. { AesDeriveKeyRegression, 0, "AesDeriveKeyRegression for AES CryptDeriveKey" },
  153. { NewShaModesBasicRegression, 0, "NewShaModesBasicRegression for new SHA mode vectors" },
  154. { NewShaModesHmacRegression, 0, "NewShaModesHmacRegression for new SHA HMAC vectors" },
  155. { NewShaModesSigningRegression, 0, "NewShaModesSigningRegression for new SHA mode RSA signing" },
  156. { NewShaModesHashSessionKeyRegression,
  157. 0, "NewShaModesHashSessionKeyRegression for new SHA modes with CryptHashSessionKey" },
  158. { NewShaModesDeriveKeyRegression, 0, "NewShaModesDeriveKeyRegression for AES keys derived from new SHA mode hashes" }
  159. };
  160. static const unsigned g_cRegressTests =
  161. sizeof(g_rgRegressTests) / sizeof(REGRESS_TEST_TABLE_ENTRY);
  162. #endif