Skip to content

Commit 9f35d87

Browse files
committed
updated randombytes NIST API
1 parent 52ad091 commit 9f35d87

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

examples/rand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main() {
2020
entropy_seed[0] = 100;
2121
entropy_seed[20] = 200;
2222
entropy_seed[47] = 150;
23-
oqs::rand::randombytes_nist_kat_init(entropy_seed);
23+
oqs::rand::randombytes_nist_kat_init_256bit(entropy_seed);
2424
std::cout << std::setw(18) << std::left;
2525
std::cout << "NIST-KAT: " << oqs::rand::randombytes(32) << '\n';
2626

include/rand/rand.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace rand {
3636
* \param bytes_to_read The number of random bytes to generate
3737
* \return Vector of random bytes
3838
*/
39-
bytes randombytes(std::size_t bytes_to_read) {
39+
inline bytes randombytes(std::size_t bytes_to_read) {
4040
bytes result(bytes_to_read);
4141
C::OQS_randombytes(result.data(), bytes_to_read);
4242
return result;
@@ -51,7 +51,7 @@ bytes randombytes(std::size_t bytes_to_read) {
5151
* \param [in] bytes_to_read The number of random bytes to generate
5252
* \param [out] random_array Output vector of random bytes
5353
*/
54-
void randombytes(bytes& random_array, std::size_t bytes_to_read) {
54+
inline void randombytes(bytes& random_array, std::size_t bytes_to_read) {
5555
if (bytes_to_read > random_array.size())
5656
throw(std::out_of_range(
5757
"bytes_to_read exceeds the size of random_array"));
@@ -65,19 +65,21 @@ void randombytes(bytes& random_array, std::size_t bytes_to_read) {
6565
* "OpenSSL", or the corresponding macros OQS_RAND_alg_system,
6666
* OQS_RAND_alg_nist_kat, and OQS_RAND_alg_openssl, respectively.
6767
*/
68-
void randombytes_switch_algorithm(const std::string& alg_name) {
68+
inline void randombytes_switch_algorithm(const std::string& alg_name) {
6969
if (C::OQS_randombytes_switch_algorithm(alg_name.c_str()) != C::OQS_SUCCESS)
7070
throw std::runtime_error("Can not switch algorithm");
7171
}
7272

7373
/**
74-
* \brief Initializes the NIST DRBG with the \a entropy_input seed
74+
* \brief Initializes the NIST DRBG with the \a entropy_input seed. The security
75+
* parameter is 256 bits.
7576
* \param entropy_input Entropy input seed, must be exactly 48 bytes long
7677
* \param personalization_string Optional personalization string, which, if
7778
* non-empty, must be at least 48 bytes long
7879
*/
79-
void randombytes_nist_kat_init(const bytes& entropy_input,
80-
const bytes& personalization_string = {}) {
80+
inline void
81+
randombytes_nist_kat_init_256bit(const bytes& entropy_input,
82+
const bytes& personalization_string = {}) {
8183
std::size_t len_str = personalization_string.size();
8284

8385
if (entropy_input.size() != 48)
@@ -87,20 +89,20 @@ void randombytes_nist_kat_init(const bytes& entropy_input,
8789
if (len_str < 48)
8890
throw std::out_of_range("The personalization string must be either "
8991
"empty or at least 48 bytes long");
90-
C::OQS_randombytes_nist_kat_init(entropy_input.data(),
91-
personalization_string.data(), 256);
92+
C::OQS_randombytes_nist_kat_init_256bit(entropy_input.data(),
93+
personalization_string.data());
9294
return;
9395
}
94-
C::OQS_randombytes_nist_kat_init(entropy_input.data(), nullptr, 256);
96+
C::OQS_randombytes_nist_kat_init_256bit(entropy_input.data(), nullptr);
9597
}
9698

9799
/**
98100
* \brief Switches oqs::rand::randombytes() to use the given function
99101
* \note This allows additional custom RNGs besides the provided ones.
100102
* \param algorithm_ptr Pointer to RNG function
101103
*/
102-
void randombytes_custom_algorithm(void (*algorithm_ptr)(uint8_t*,
103-
std::size_t)) {
104+
inline void randombytes_custom_algorithm(void (*algorithm_ptr)(uint8_t*,
105+
std::size_t)) {
104106
C::OQS_randombytes_custom_algorithm(algorithm_ptr);
105107
}
106108
} // namespace rand

0 commit comments

Comments
 (0)