MCPcopy Create free account
hub / github.com/SFML/SFML / MbedTlsSharedState

Method MbedTlsSharedState

src/SFML/Network/TcpSocket.cpp:347–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345struct MbedTlsSharedState
346{
347 MbedTlsSharedState()
348 {
349#if (MBEDTLS_VERSION_MAJOR < 4)
350 // Initialize crypto library in Mbed TLS 3.x.x and earlier
351 mbedtls_entropy_init(&entropyContext);
352 mbedtls_ctr_drbg_init(&ctrDrbgContext);
353
354 // We use a personalization string as a cheap way to minimally seed the RNG in case entropy is low
355 static const auto personalizationString = "sfml-network-" + std::string(sf::version().string) +
356 "-mbedtls-" MBEDTLS_VERSION_STRING_FULL;
357
358 if (auto result = mbedtls_ctr_drbg_seed(&ctrDrbgContext,
359 mbedtls_entropy_func,
360 &entropyContext,
361 reinterpret_cast<const unsigned char*>(personalizationString.data()),
362 personalizationString.size());
363 result != 0)
364 {
365 sf::err() << "Failed to seed DRBG: " << tlsErrorString(result) << std::endl;
366 assert(false && "Failed to seed DRBG");
367 throw std::runtime_error("Failed to seed DRBG");
368 }
369#else
370 // Initialize crypto library in Mbed TLS 4.x.x and later
371 if (auto result = psa_crypto_init(); result != PSA_SUCCESS)
372 {
373 sf::err() << "Failed to initialize crypto library" << std::endl;
374 assert(false && "Failed to initialize crypto library");
375 throw std::runtime_error("Failed to initialize crypto library");
376 }
377#endif
378 }
379
380#if (MBEDTLS_VERSION_MAJOR < 4)
381 ~MbedTlsSharedState()

Callers

nothing calls this directly

Calls 1

tlsErrorStringFunction · 0.85

Tested by

no test coverage detected