diff options
author | Jack Lloyd <[email protected]> | 2018-08-10 10:53:05 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-08-10 10:53:05 -0400 |
commit | 2eee96640f4629aa9c6c517b1703e7dcd8a4dbd5 (patch) | |
tree | 82c62e857dea098b27124dfe8d37e6d79c8ae795 /src | |
parent | d664c9669a0f3d5f09e3bf89b222abb7483d426e (diff) |
Add a "user-threadsafe" option to botan_rng_init
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ffi/ffi_rng.cpp | 10 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi_rng.cpp b/src/lib/ffi/ffi_rng.cpp index 8d97a39d8..b3c5cd967 100644 --- a/src/lib/ffi/ffi_rng.cpp +++ b/src/lib/ffi/ffi_rng.cpp @@ -25,11 +25,21 @@ int botan_rng_init(botan_rng_t* rng_out, const char* rng_type) std::unique_ptr<Botan::RandomNumberGenerator> rng; if(rng_type_s == "system") + { rng.reset(new Botan::System_RNG); + } else if(rng_type_s == "user") + { rng.reset(new Botan::AutoSeeded_RNG); + } + else if(rng_type_s == "user-threadsafe") + { + rng.reset(new Botan::Serialized_RNG(new Botan::AutoSeeded_RNG)); + } else + { return BOTAN_FFI_ERROR_BAD_PARAMETER; + } *rng_out = new botan_rng_struct(rng.release()); return BOTAN_FFI_SUCCESS; diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index ec8db1739..a479c6a48 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -52,6 +52,13 @@ class FFI_Unit_Tests final : public Test TEST_FFI_OK(botan_rng_destroy, (rng)); } + if(TEST_FFI_OK(botan_rng_init, (&rng, "user-threadsafe"))) + { + TEST_FFI_OK(botan_rng_get, (rng, outbuf.data(), outbuf.size())); + TEST_FFI_OK(botan_rng_reseed, (rng, 256)); + TEST_FFI_OK(botan_rng_destroy, (rng)); + } + if(TEST_FFI_OK(botan_rng_init, (&rng, "user"))) { TEST_FFI_OK(botan_rng_get, (rng, outbuf.data(), outbuf.size())); |