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.

228 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1993, 1998 Microsoft Corporation
  3. Module Name:
  4. randlib.h
  5. Abstract:
  6. Exported procedures for core cryptographic random number generation.
  7. Author:
  8. Scott Field (sfield) 27-Oct-98
  9. Revision History:
  10. Oct 11 1996 jeffspel moved from ntagimp1.h
  11. Aug 27 1997 sfield Increase RAND_CTXT_LEN
  12. Aug 15 1998 sfield Kernel mode and general cleanup
  13. --*/
  14. #ifndef __RANDLIB_H__
  15. #define __RANDLIB_H__
  16. #ifndef RSA32API
  17. #define RSA32API __stdcall
  18. #endif
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef struct {
  23. unsigned long cbSize;
  24. unsigned long Flags;
  25. unsigned char *pbRandSeed;
  26. unsigned long cbRandSeed;
  27. } RNG_CONTEXT, *PRNG_CONTEXT, *LPRNG_CONTEXT;
  28. #define RNG_FLAG_REKEY_ONLY 1
  29. //
  30. // primary random number generation interface
  31. // Functions return TRUE for success, FALSE for failure.
  32. //
  33. unsigned int
  34. RSA32API
  35. NewGenRandomEx(
  36. IN RNG_CONTEXT *pRNGContext,
  37. IN OUT unsigned char *pbRandBuffer,
  38. IN unsigned long cbRandBuffer
  39. );
  40. unsigned int
  41. RSA32API
  42. NewGenRandom(
  43. IN OUT unsigned char **ppbRandSeed, // initial seed value (ignored if already set)
  44. IN unsigned long *pcbRandSeed,
  45. IN OUT unsigned char *pbBuffer,
  46. IN unsigned long dwLength
  47. );
  48. //
  49. // RNG seed set and query
  50. //
  51. unsigned int
  52. RSA32API
  53. InitRand(
  54. IN OUT unsigned char **ppbRandSeed, // new seed value to set (over-writes current)
  55. IN unsigned long *pcbRandSeed
  56. );
  57. unsigned int
  58. RSA32API
  59. DeInitRand(
  60. IN OUT unsigned char *pbRandSeed, // output of current seed
  61. IN unsigned long cbRandSeed
  62. );
  63. //
  64. // RNG initializers for DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH
  65. //
  66. unsigned int
  67. RSA32API
  68. InitializeRNG(
  69. VOID *pvReserved
  70. );
  71. void
  72. RSA32API
  73. ShutdownRNG(
  74. VOID *pvReserved
  75. );
  76. //
  77. // RC4 thread safe primitives, for the bold users who stream data from RC4
  78. // themselves.
  79. //
  80. //
  81. // rc4_safe_startup called to initialize internal structures.
  82. // typically called during DLL_PROCESS_ATTACH type initialiation code.
  83. //
  84. unsigned int
  85. RSA32API
  86. rc4_safe_startup(
  87. IN OUT void **ppContext
  88. );
  89. unsigned int
  90. RSA32API
  91. rc4_safe_startup_np(
  92. IN OUT void **ppContext
  93. );
  94. //
  95. // typically call rc4_safe_shutdown during DLL_PROCESS_DETACH, with the
  96. // value obtained during rc4_safe_startup
  97. //
  98. void
  99. RSA32API
  100. rc4_safe_shutdown(
  101. IN void *pContext
  102. );
  103. void
  104. RSA32API
  105. rc4_safe_shutdown_np(
  106. IN void *pContext
  107. );
  108. //
  109. // select a safe entry.
  110. // outputs: entry index
  111. // bytes used for specified index. 0xffffffff indicates caller
  112. // MUST call rc4_safe_key to initialize the key.
  113. // caller decides when to rekey based on non-zero output of pBytesUsed
  114. // example is RNG re-keying when pBytesUsed >= 16384
  115. //
  116. void
  117. RSA32API
  118. rc4_safe_select(
  119. IN void *pContext,
  120. OUT unsigned int *pEntry,
  121. OUT unsigned int *pBytesUsed
  122. );
  123. void
  124. RSA32API
  125. rc4_safe_select_np(
  126. IN void *pContext,
  127. OUT unsigned int *pEntry,
  128. OUT unsigned int *pBytesUsed
  129. );
  130. //
  131. // initialize the key specified by Entry index.
  132. // key material is size cb, pointer to key is pv.
  133. // this routine is the safe version of rc4_key()
  134. //
  135. void
  136. RSA32API
  137. rc4_safe_key(
  138. IN void *pContext,
  139. IN unsigned int Entry,
  140. IN unsigned int cb,
  141. IN const void *pv
  142. );
  143. void
  144. RSA32API
  145. rc4_safe_key_np(
  146. IN void *pContext,
  147. IN unsigned int Entry, // 0xffffffff for default
  148. IN unsigned int cb,
  149. IN const void *pv
  150. );
  151. //
  152. // encrypt using the key specified by Entry index.
  153. // buffer of size cb at location pv is encrypted.
  154. // this routine is the safe version of rc4()
  155. //
  156. void
  157. RSA32API
  158. rc4_safe(
  159. IN void *pContext,
  160. IN unsigned int Entry,
  161. IN unsigned int cb,
  162. IN void *pv
  163. );
  164. void
  165. RSA32API
  166. rc4_safe_np(
  167. IN void *pContext,
  168. IN unsigned int Entry,
  169. IN unsigned int cb,
  170. IN void *pv
  171. );
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif // __RANDLIB_H__