How to make your custom RNG (random number generator) implementation the default RNG provider for the system using CNG API's
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:
https://msdn.microsoft.com/en-us/library/aa375458(VS.85).aspx
-Shamik
Comments
- Anonymous
August 19, 2010
you are asome