CCF
Loading...
Searching...
No Matches
src
crypto
openssl
entropy.h
Go to the documentation of this file.
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
// Licensed under the Apache 2.0 License.
3
#pragma once
4
5
#include "
ccf/crypto/entropy.h
"
6
#include "
ccf/crypto/openssl/openssl_wrappers.h
"
7
8
#include <functional>
9
#include <memory>
10
#include <openssl/rand.h>
11
#include <vector>
12
13
namespace
ccf::crypto
14
{
15
class
Entropy_OpenSSL
:
public
Entropy
16
{
17
private
:
18
static
bool
gen(uint64_t& v);
19
20
public
:
21
Entropy_OpenSSL
() =
default
;
22
23
std::vector<uint8_t>
random
(
size_t
len)
override
24
{
25
std::vector<uint8_t> data(len);
26
27
if
(RAND_bytes(data.data(), data.size()) != 1)
28
throw
std::logic_error(
"Couldn't create random data"
);
29
30
return
data;
31
}
32
33
uint64_t
random64
()
override
34
{
35
uint64_t rnd;
36
37
if
(RAND_bytes((
unsigned
char
*)&rnd,
sizeof
(uint64_t)) != 1)
38
{
39
throw
std::logic_error(
"Couldn't create random data"
);
40
}
41
42
return
rnd;
43
}
44
45
void
random
(
unsigned
char
* data,
size_t
len)
override
46
{
47
if
(RAND_bytes(data, len) != 1)
48
{
49
throw
std::logic_error(
"Couldn't create random data"
);
50
}
51
}
52
};
53
}
ccf::crypto::Entropy_OpenSSL
Definition
entropy.h:16
ccf::crypto::Entropy_OpenSSL::Entropy_OpenSSL
Entropy_OpenSSL()=default
ccf::crypto::Entropy_OpenSSL::random64
uint64_t random64() override
Definition
entropy.h:33
ccf::crypto::Entropy_OpenSSL::random
void random(unsigned char *data, size_t len) override
Definition
entropy.h:45
ccf::crypto::Entropy_OpenSSL::random
std::vector< uint8_t > random(size_t len) override
Definition
entropy.h:23
ccf::crypto::Entropy
Definition
entropy.h:13
entropy.h
ccf::crypto
Definition
base64.h:10
openssl_wrappers.h
Generated by
1.9.8