Skip to content
Snippets Groups Projects
rand.hh 1.13 KiB
#ifndef __VEREIGN_CRYPTO_RAND_HH
#define __VEREIGN_CRYPTO_RAND_HH

#include <vereign/bytes/buffer.hh>

namespace vereign::crypto {

/**
 * Appends a random bytes to a buffer.
 *
 * After the operation is finished, the passed `buf` will be with incremented size of the newly
 * added random bytes.
 *
 * Example:
 * @code
 * bytes::Bytes buf;
 * crypto::Rand(buf, 16);
 *
 * assert(buf.Size() == 16);
 * @endcode
 *
 * @param buf The buffer that will be filled with random bytes.
 * @param size The number of the random bytes.
 *
 * @throws crypto::Error on failure.
 */
void Rand(bytes::Buffer& buf, std::size_t size);

/**
 * Generate random bytes.
 *
 * Example:
 * @code
 * auto buf = crypto::Rand(16);
 *
 * assert(buf.Size() == 16);
 * @endcode
 *
 * @param size The number of the random bytes.
 * @returns buffer with the generated random bytes.
 *
 * @throws crypto::Error on failure.
 */
auto Rand(std::size_t size) -> bytes::Buffer;

/**
 * Generates random uint64_t.
 *
 * @returns random unsigned 64 bit integer.
 *
 * @throws crypto::Error on failure.
 */
auto RandUint64() -> uint64_t;

} // vereign::crypto

#endif // __VEREIGN_CRYPTO_RAND_HH