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.

330 lines
7.5 KiB

  1. #ifndef __FIPSAPI_H__
  2. #define __FIPSAPI_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <windef.h>
  7. #include <des.h>
  8. #include <tripldes.h>
  9. #include <sha.h>
  10. #include <modes.h>
  11. #include <md5.h>
  12. #if DEBUG
  13. #define FipsDebug(LEVEL, STRING) \
  14. { \
  15. DbgPrint STRING; \
  16. }
  17. #else
  18. #define FipsDebug(LEVEL, STRING)
  19. #endif
  20. #define FIPS_DEVICE_NAME L"\\Device\\Fips"
  21. #define FIPS_CTL_CODE(code) CTL_CODE(FILE_DEVICE_FIPS, \
  22. (code), \
  23. METHOD_BUFFERED, \
  24. FILE_ANY_ACCESS)
  25. #define IOCTL_FIPS_GET_FUNCTION_TABLE FIPS_CTL_CODE( 1)
  26. #define FIPS_CBC_DES 0x1
  27. #define FIPS_CBC_3DES 0x2
  28. //
  29. // Defines for IPSEC HMAC use
  30. //
  31. #define MAX_LEN_PAD 65
  32. #define MAX_KEYLEN_SHA 64
  33. #define MAX_KEYLEN_MD5 64
  34. //
  35. // Fill in the DESTable struct with the decrypt and encrypt
  36. // key expansions.
  37. //
  38. // Assumes that the second parameter points to DES_BLOCKLEN
  39. // bytes of key.
  40. //
  41. //
  42. VOID FipsDesKey(DESTable *DesTable, UCHAR *pbKey);
  43. //
  44. // Encrypt or decrypt with the key in DESTable
  45. //
  46. //
  47. VOID FipsDes(UCHAR *pbOut, UCHAR *pbIn, void *pKey, int iOp);
  48. //
  49. // Fill in the DES3Table structs with the decrypt and encrypt
  50. // key expansions.
  51. //
  52. // Assumes that the second parameter points to 2 * DES_BLOCKLEN
  53. // bytes of key.
  54. //
  55. //
  56. VOID Fips3Des3Key(PDES3TABLE pDES3Table, UCHAR *pbKey);
  57. //
  58. // Encrypt or decrypt with the key in pKey
  59. //
  60. VOID Fips3Des(UCHAR *pbIn, UCHAR *pbOut, void *pKey, int op);
  61. //
  62. // Initialize the SHA context.
  63. //
  64. VOID FipsSHAInit(A_SHA_CTX *pShaCtx);
  65. //
  66. // Hash data into the hash context.
  67. //
  68. VOID FipsSHAUpdate(A_SHA_CTX *pShaCtx, UCHAR *pb, unsigned int cb);
  69. //
  70. // Finish the SHA hash and copy the final hash value into the pbHash out param.
  71. //
  72. VOID FipsSHAFinal(A_SHA_CTX *pShaCtx, UCHAR *pbHash);
  73. //
  74. // FipsCBC (cipher block chaining) performs a XOR of the feedback register
  75. // with the plain text before calling the block cipher
  76. //
  77. // NOTE - Currently this function assumes that the block length is
  78. // DES_BLOCKLEN (8 bytes).
  79. //
  80. // Return: Failure if FALSE is returned, TRUE if it succeeded.
  81. //
  82. BOOL FipsCBC(
  83. ULONG EncryptionAlg,
  84. BYTE *pbOutput,
  85. BYTE *pbInput,
  86. void *pKeyTable,
  87. int Operation,
  88. BYTE *pbFeedback
  89. );
  90. //
  91. // FipsBlockCBC (cipher block chaining) performs a XOR of the feedback register
  92. // with the plain text before calling the block cipher
  93. //
  94. // NOTE - The Length must be multiple of DES_BLOCKLEN (8)
  95. // All the input buffer must be aligned on LONGLONG for performane reason.
  96. //
  97. // Return: Failure if FALSE is returned, TRUE if it succeeded.
  98. //
  99. BOOL FipsBlockCBC(
  100. ULONG EncryptionAlg,
  101. BYTE *pbOutput,
  102. BYTE *pbInput,
  103. ULONG Length,
  104. void *pKeyTable,
  105. int Operation,
  106. BYTE *pbFeedback
  107. );
  108. //
  109. // Function : FIPSGenRandom
  110. //
  111. // Description : FIPS 186 RNG, the seed is generated by calling NewGenRandom.
  112. //
  113. BOOL FIPSGenRandom(
  114. IN OUT UCHAR *pb,
  115. IN ULONG cb
  116. );
  117. //
  118. // Function: FipsHmacSHAInit
  119. //
  120. // Description: Initialize a SHA-HMAC context
  121. //
  122. VOID FipsHmacSHAInit(
  123. OUT A_SHA_CTX *pShaCtx,
  124. IN UCHAR *pKey,
  125. IN unsigned int cbKey
  126. );
  127. //
  128. // Function: FipsHmacSHAUpdate
  129. //
  130. // Description: Add more data to a SHA-HMAC context
  131. //
  132. VOID FipsHmacSHAUpdate(
  133. IN OUT A_SHA_CTX *pShaCtx,
  134. IN UCHAR *pb,
  135. IN unsigned int cb
  136. );
  137. //
  138. // Function: FipsHmacSHAFinal
  139. //
  140. // Description: Return result of SHA-HMAC
  141. //
  142. VOID FipsHmacSHAFinal(
  143. IN A_SHA_CTX *pShaCtx,
  144. IN UCHAR *pKey,
  145. IN unsigned int cbKey,
  146. OUT UCHAR *pHash
  147. );
  148. //
  149. // Function: HmacMD5Init
  150. //
  151. // Description: Initialize a MD5-HMAC context
  152. //
  153. VOID HmacMD5Init(
  154. OUT MD5_CTX *pMD5Ctx,
  155. IN UCHAR *pKey,
  156. IN unsigned int cbKey
  157. );
  158. //
  159. // Function: HmacMD5Update
  160. //
  161. // Description: Add more data to a MD5-HMAC context
  162. //
  163. VOID HmacMD5Update(
  164. IN OUT MD5_CTX *pMD5Ctx,
  165. IN UCHAR *pb,
  166. IN unsigned int cb
  167. );
  168. //
  169. // Function: HmacMD5Final
  170. //
  171. // Description: Return result of MD5-HMAC
  172. //
  173. VOID HmacMD5Final(
  174. IN MD5_CTX *pMD5Ctx,
  175. IN UCHAR *pKey,
  176. IN unsigned int cbKey,
  177. OUT UCHAR *pHash
  178. );
  179. //
  180. // Current FIPS function table
  181. // Includes HMAC entry points
  182. //
  183. typedef struct _FIPS_FUNCTION_TABLE {
  184. VOID (*FipsDesKey)(DESTable *DesTable, UCHAR *pbKey);
  185. VOID (*FipsDes)(UCHAR *pbOut, UCHAR *pbIn, void *pKey, int iOp);
  186. VOID (*Fips3Des3Key)(PDES3TABLE pDES3Table, UCHAR *pbKey);
  187. VOID (*Fips3Des)(UCHAR *pbIn, UCHAR *pbOut, void *pKey, int op);
  188. VOID (*FipsSHAInit)(A_SHA_CTX *pShaCtx);
  189. VOID (*FipsSHAUpdate)(A_SHA_CTX *pShaCtx, UCHAR *pb, unsigned int cb);
  190. VOID (*FipsSHAFinal)(A_SHA_CTX *pShaCtx, UCHAR *pbHash);
  191. BOOL (*FipsCBC)(
  192. ULONG EncryptionAlg,
  193. BYTE *pbOutput,
  194. BYTE *pbInput,
  195. void *pKeyTable,
  196. int Operation,
  197. BYTE *pbFeedback
  198. );
  199. BOOL (*FIPSGenRandom)(
  200. IN OUT UCHAR *pb,
  201. IN ULONG cb
  202. );
  203. BOOL (*FipsBlockCBC)(
  204. ULONG EncryptionAlg,
  205. BYTE *pbOutput,
  206. BYTE *pbInput,
  207. ULONG Length,
  208. void *pKeyTable,
  209. int Operation,
  210. BYTE *pbFeedback
  211. );
  212. VOID (*FipsHmacSHAInit)(
  213. OUT A_SHA_CTX *pShaCtx,
  214. IN UCHAR *pKey,
  215. IN unsigned int cbKey
  216. );
  217. VOID (*FipsHmacSHAUpdate)(
  218. IN OUT A_SHA_CTX *pShaCtx,
  219. IN UCHAR *pb,
  220. IN unsigned int cb
  221. );
  222. VOID (*FipsHmacSHAFinal)(
  223. IN A_SHA_CTX *pShaCtx,
  224. IN UCHAR *pKey,
  225. IN unsigned int cbKey,
  226. OUT UCHAR *pHash
  227. );
  228. VOID (*HmacMD5Init)(
  229. OUT MD5_CTX *pMD5Ctx,
  230. IN UCHAR *pKey,
  231. IN unsigned int cbKey
  232. );
  233. VOID (*HmacMD5Update)(
  234. IN OUT MD5_CTX *pMD5Ctx,
  235. IN UCHAR *pb,
  236. IN unsigned int cb
  237. );
  238. VOID (*HmacMD5Final)(
  239. IN MD5_CTX *pMD5Ctx,
  240. IN UCHAR *pKey,
  241. IN unsigned int cbKey,
  242. OUT UCHAR *pHash
  243. );
  244. } FIPS_FUNCTION_TABLE, *PFIPS_FUNCTION_TABLE;
  245. //
  246. // Old FIPS function table - please don't use
  247. //
  248. typedef struct _FIPS_FUNCTION_TABLE_1 {
  249. VOID (*FipsDesKey)(DESTable *DesTable, UCHAR *pbKey);
  250. VOID (*FipsDes)(UCHAR *pbOut, UCHAR *pbIn, void *pKey, int iOp);
  251. VOID (*Fips3Des3Key)(PDES3TABLE pDES3Table, UCHAR *pbKey);
  252. VOID (*Fips3Des)(UCHAR *pbIn, UCHAR *pbOut, void *pKey, int op);
  253. VOID (*FipsSHAInit)(A_SHA_CTX *pShaCtx);
  254. VOID (*FipsSHAUpdate)(A_SHA_CTX *pShaCtx, UCHAR *pb, unsigned int cb);
  255. VOID (*FipsSHAFinal)(A_SHA_CTX *pShaCtx, UCHAR *pbHash);
  256. BOOL (*FipsCBC)(
  257. ULONG EncryptionAlg,
  258. BYTE *pbOutput,
  259. BYTE *pbInput,
  260. void *pKeyTable,
  261. int Operation,
  262. BYTE *pbFeedback
  263. );
  264. BOOL (*FIPSGenRandom)(
  265. IN OUT UCHAR *pb,
  266. IN ULONG cb
  267. );
  268. BOOL (*FipsBlockCBC)(
  269. ULONG EncryptionAlg,
  270. BYTE *pbOutput,
  271. BYTE *pbInput,
  272. ULONG Length,
  273. void *pKeyTable,
  274. int Operation,
  275. BYTE *pbFeedback
  276. );
  277. } FIPS_FUNCTION_TABLE_1, *PFIPS_FUNCTION_TABLE_1;
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. #endif // __FIPSAPI_H__