Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/lib/rng/rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,17 @@ class BOTAN_PUBLIC_API(2, 0) RandomNumberGenerator {
/**
* Fill a given byte container with @p bytes random bytes
*
* @todo deprecate this overload (in favor of randomize())
* Deprecated
* Use randomize(std::span<uint8_t>) overload instead. No resizing or
* allocation operations are performed here. This overload exists for
* historical reasons and will be removed in Botan4.
*
* @param v the container to be filled with @p bytes random bytes
* @throws Exception if RNG fails
*
* TODO(Botan4) remove this function
*/
void random_vec(std::span<uint8_t> v) { this->randomize(v); }
BOTAN_DEPRECATED("Use randomize() instead") void random_vec(std::span<uint8_t> v) { this->randomize(v); }

/**
* Resize a given byte container to @p bytes and fill it with random bytes
Expand All @@ -214,7 +219,7 @@ class BOTAN_PUBLIC_API(2, 0) RandomNumberGenerator {
template <concepts::resizable_byte_buffer T>
void random_vec(T& v, size_t bytes) {
v.resize(bytes);
random_vec(v);
randomize(v);
}

/**
Expand All @@ -239,7 +244,7 @@ class BOTAN_PUBLIC_API(2, 0) RandomNumberGenerator {
template <size_t bytes>
std::array<uint8_t, bytes> random_array() {
std::array<uint8_t, bytes> result{};
random_vec(result);
randomize(result);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Fixed_Output_Position_RNG final : public Fixed_Output_RNG {
Fixed_Output_RNG::fill_bytes_with_input(output, input);
} else {
// return random
m_rng.random_vec(output);
m_rng.randomize(output);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_strong_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Strong_Type_Tests final : public Test {
auto tb = rng.random_vec<Test_Buffer>(4);
auto tsb = rng.random_vec<Test_Secure_Buffer>(4);
Test_Fixed_Array tfa;
rng.random_vec(tfa);
rng.randomize(tfa);

result.test_bin_eq("generated expected output", tb.get(), "deadbeef");
result.test_bin_eq("generated expected secure output", tsb.get(), "baadcafe");
Expand Down
Loading