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.

147 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name:
  4. tssec.c
  5. Abstract:
  6. Contains code that generates random keys.
  7. Author:
  8. Madan Appiah (madana) 1-Jan-1998
  9. Modified by Nadim Abdo 31-Aug-2001 to use system RNG
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. #include <seccom.h>
  15. #include <stdlib.h>
  16. #include <rng.h>
  17. #ifndef OS_WINCE
  18. #include <randlib.h>
  19. #endif
  20. VOID
  21. TSRNG_Initialize(
  22. )
  23. {
  24. #ifndef OS_WINCE
  25. InitializeRNG(NULL);
  26. #else
  27. TSInitializeRNG();
  28. #endif
  29. }
  30. VOID
  31. TSRNG_Shutdown(
  32. )
  33. {
  34. #ifndef OS_WINCE
  35. ShutdownRNG(NULL);
  36. #endif
  37. }
  38. //
  39. // function definitions
  40. //
  41. BOOL
  42. TSRNG_GenerateRandomBits(
  43. LPBYTE pbRandomBits,
  44. DWORD cbLen
  45. )
  46. /*++
  47. Routine Description:
  48. This function returns random bits
  49. Arguments:
  50. pbRandomBits - pointer to a buffer where a random key is returned.
  51. cbLen - length of the random key required.
  52. Return Value:
  53. TRUE - if a random key is generated successfully.
  54. FALSE - otherwise.
  55. --*/
  56. {
  57. #ifndef OS_WINCE
  58. BOOL fRet;
  59. fRet = NewGenRandom(NULL, NULL, pbRandomBits, cbLen);
  60. return fRet;
  61. #else
  62. GenerateRandomBits(pbRandomBits, cbLen);
  63. return( TRUE );
  64. #endif
  65. }
  66. // Legacy RNG's
  67. VOID
  68. InitRandomGenerator(
  69. VOID
  70. )
  71. {
  72. //
  73. // initialize the random generator first.
  74. //
  75. TSInitializeRNG();
  76. }
  77. //
  78. // function definitions
  79. //
  80. BOOL
  81. GenerateRandomKey(
  82. LPBYTE pbRandomKey,
  83. DWORD dwRandomKeyLen
  84. )
  85. /*++
  86. Routine Description:
  87. This function makes and return the microsoft terminal server certificate
  88. blob of data.
  89. Arguments:
  90. pbRandomKey - pointer to a buffer where a random key is returned.
  91. dwRandomKeyLen - length of the random key required.
  92. Return Value:
  93. TRUE - if a random key is generated successfully.
  94. FALSE - otherwise.
  95. --*/
  96. {
  97. //
  98. // generate random bits now.
  99. //
  100. legacyGenerateRandomBits( pbRandomKey, dwRandomKeyLen );
  101. return( TRUE );
  102. }