diff options
-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())); |