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
{
29
throw
std::logic_error(
"Couldn't create random data"
);
30
}
31
32
return
data;
33
}
34
35
uint64_t
random64
()
override
36
{
37
uint64_t rnd = 0;
38
39
if
(
40
RAND_bytes(
reinterpret_cast<
unsigned
char
*
>
(&rnd),
sizeof
(uint64_t)) !=
41
1)
42
{
43
throw
std::logic_error(
"Couldn't create random data"
);
44
}
45
46
return
rnd;
47
}
48
49
void
random
(
unsigned
char
* data,
size_t
len)
override
50
{
51
if
(RAND_bytes(data, len) != 1)
52
{
53
throw
std::logic_error(
"Couldn't create random data"
);
54
}
55
}
56
};
57
}
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:35
ccf::crypto::Entropy_OpenSSL::random
void random(unsigned char *data, size_t len) override
Definition
entropy.h:49
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