container: root: macro: add bitcoin plugin support

- Adds support to existing macros for bitcoin's RNG via `dfi`'s `Random`
  * Currently only supports one of bitcoin's RNG's (`FastRandomContext`)
This commit is contained in:
2025-11-14 12:38:43 -08:00
parent 2268ae8083
commit 0bf4c359b1
3 changed files with 48 additions and 0 deletions

View File

@@ -105,6 +105,21 @@ using Random = ::dfi::crypto::libsodium::Random;
auto g_Random = std::make_unique<Random>();
} // namespace crypto::libsodium
#ifdef __DFI_PLUGIN_BITCOIN__
//! \namespace dfi::macro::common::crypto::bitcoin
//! \since docker-finance 1.1.0
namespace crypto::bitcoin
{
//! \brief ROOT's bitcoin Random class
//! \ingroup cpp_macro
using Random = ::dfi::crypto::bitcoin::Random;
//! \brief ROOT's bitcoin Random instance
//! \ingroup cpp_macro
auto g_Random = std::make_unique<Random>();
} // namespace crypto::bitcoin
#endif
} // namespace common
} // namespace macro
} // namespace dfi

View File

@@ -47,6 +47,9 @@ namespace common = ::dfi::macro::common;
namespace libsodium = common::crypto::libsodium;
namespace cryptopp = common::crypto::cryptopp;
namespace botan = common::crypto::botan;
#ifdef __DFI_PLUGIN_BITCOIN__
namespace bitcoin = common::crypto::bitcoin;
#endif
//! \brief CSPRNG macro
class Random final
@@ -110,6 +113,24 @@ class Random final
return rng;
}
#ifdef __DFI_PLUGIN_BITCOIN__
//! \brief bitcon RNG
//! \return t_rng Random map to print (label, num)
static t_rng bitcoin_generate()
{
t_rng rng;
rng["int16_t (unsupported)"] = 0;
rng["int32_t (unsupported)"] = 0;
rng["uint16_t (unsupported)"] = 0;
rng["uint32_t"] = bitcoin::g_Random->generate<uint32_t>();
rng["uint64_t"] = bitcoin::g_Random->generate<uint64_t>();
return rng;
}
#endif
public:
//! \brief Print t_rng of CSPRNG numbers in CSV format
static void generate()
@@ -122,6 +143,9 @@ class Random final
};
std::cout << "\nimpl,type,num\n";
#ifdef __DFI_PLUGIN_BITCOIN__
print("bitcoin::Random", Random::bitcoin_generate());
#endif
print("botan::Random", Random::botan_generate());
print("cryptopp::Random", Random::cryptopp_generate());
print("libsodium::Random", Random::libsodium_generate());

View File

@@ -351,6 +351,15 @@ class Random final
const std::string timestamp{common::make_timestamp()};
#ifdef __DFI_PLUGIN_BITCOIN__
data.title = "Bitcoin_FastRandomContext_32_RNG_" + timestamp;
random(data, []() -> uint32_t {
return common::crypto::bitcoin::g_Random->generate();
});
// TODO(afiore): uint64_t (requires canvas-related refactor)
#endif
data.title = "Botan_RNG_" + timestamp;
random(data, []() -> uint32_t {
return common::crypto::botan::g_Random->generate();