Giter VIP home page Giter VIP logo

cryptorand's Introduction

Cryptographically Secure Pseudo-Random Number Generator

discord twitter

This uses the operating system's random number generation. If you're looking for a CSPRNG from scratch you'll need to look elsewhere.

Supported generation methods are Win32's BCryptGenRandom() with CryptGenRandom() as a fallback. On platforms that support /dev/urandom, that will be used. OpenBSD will use arc4random().

There is no need to link to anything with this library. You can use CRYPTORAND_IMPLEMENTATION to define the implementation section, or you can use cryptorand.c if you prefer a traditional header/source pair.

There's only three functions, all of which should be self explanatory and easy to figure out:

cryptorand_result cryptorand_init(cryptorand* pRNG);
void cryptorand_uninit(cryptorand* pRNG);
cryptorand_result cryptorand_generate(cryptorand* pRNG, void* pBufferOut, size_t byteCount);

Call cryptorand_init() to initialize the random number generator. On Windows, this is where libraries are linked at runtime so avoid calling this in high performance scenarios. It's best to just create one instance and then read from it multiple times.

To generate random bytes you need only call cryptorand_generate(). You just specify a pointer to a buffer that will receive the random data and the number of bytes you want. If this fails, the content of the buffer will be cleared to zero.

Uninitialize the random number generator with cryptorand_uninit().

Thread safety depends on the backend.

cryptorand's People

Contributors

mackron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.