Windows SDK Support Team Blog

#define _WIN32_WINNT

How to make your custom RNG (random number generator) implementation the default RNG provider for the system using CNG API's

How to make your custom RNG (random number generator) implementation the default RNG provider for the system using CNG API's

Rate This
  • Comments 1

 

If you have implemented your random number generator make sure that you register it using BCryptRegisterProvider function. Add the algorithm name to the list of symmetric cipher algorithm class using BCryptAddContextFunction.

 

Example:

 

BCryptAddContextFunction(

                        CRYPT_LOCAL,              // Scope: local machine only

                        NULL,                     // Application context: default

                        BCRYPT_RNG_INTERFACE,     // Algorithm class

                        BCRYPT_RNG_ALGORITHM,     // Algorithm name

                        CRYPT_PRIORITY_TOP

                       );

 

 

To use the CNG API's to make your custom RNG provider the default system RNG provider call:

 

BCryptOpenAlgorithmProvider(&hRandomAlg, BCRYPT_RNG_ALGORITHM, NULL, 0); 

 

This would select your own RNG implementation.

For post Vista OS’s, you don’t need the algorithm name for RNG algorithm when calling BCryptGenRandom.  By setting your implementation to the top, the BCryptGenRandom function will automatically handle opening and closing RNG algorithm handles for you if you call BCryptGenRandom with a NULL algorithm handle and set the BCRYPT_USE_SYSTEM_PREFERRED_RNG flag.

Reference:

http://msdn.microsoft.com/en-us/library/aa375458(VS.85).aspx

-Shamik

  • you are asome

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 3 and 2 and type the answer here:
  • Post
Search Blogs