c - Is CryptGenRandom() thread-safe? -


is cryptgenrandom() thread-safe single global program-wide hcryptprov instance?

msdn appears lack info on this: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx

creating separate hcryptprov per thread , destroying again complicate matters (and risk more security-relevant bugs on side), useful know. sharing 1 global hcryptprov lot easier sure.

so here know thread-safety of cryptgenrandom(), particularly single hcryptprov instance?

creating separate hcryptprov per thread doesn't make sense. pointer memory block heap in current implementations, saved pointers csp entry points used call actual provider implementation (cpgenrandom in our case). references not contain state of csp, unlike example hcryptkey containing actual key state. if create separate hcryptprov every thread - changes nothing.

there may global variables / data used csp internally during call; unknown these implementation details. of course can serialize calls cryptgenrandom in code. cannot control other dll in our process call cryptgenrandom concurrently. serializing calls cryptgenrandom impossible.

as result think cpgenrandom must design thread-safe. , tests known microsoft csp true. internal synchronization used in function, when need access global data , if multiple threads call cpgenrandom concurrently; every thread receives unique random data.

so conclusion - cryptgenrandom thread-safe, @ least microsoft csp


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -