Random: secure_uint{32,64}
GitOrigin-RevId: 5cc15552bc0d103cbe93935d3c75256845e3a39b
This commit is contained in:
parent
d4cb9d2d52
commit
b938ca635c
@ -81,6 +81,18 @@ int64 Random::secure_int64() {
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32 Random::secure_uint32() {
|
||||
uint32 res = 0;
|
||||
secure_bytes(reinterpret_cast<unsigned char *>(&res), sizeof(uint32));
|
||||
return res;
|
||||
}
|
||||
|
||||
uint64 Random::secure_uint64() {
|
||||
uint64 res = 0;
|
||||
secure_bytes(reinterpret_cast<unsigned char *>(&res), sizeof(uint64));
|
||||
return res;
|
||||
}
|
||||
|
||||
void Random::add_seed(Slice bytes, double entropy) {
|
||||
RAND_add(bytes.data(), static_cast<int>(bytes.size()), entropy);
|
||||
random_seed_generation++;
|
||||
|
@ -18,6 +18,8 @@ class Random {
|
||||
static void secure_bytes(unsigned char *ptr, size_t size);
|
||||
static int32 secure_int32();
|
||||
static int64 secure_int64();
|
||||
static uint32 secure_uint32();
|
||||
static uint64 secure_uint64();
|
||||
|
||||
// works only for current thread
|
||||
static void add_seed(Slice bytes, double entropy = 0);
|
||||
|
Loading…
Reference in New Issue
Block a user