MCPcopy Create free account
hub / github.com/FastLED/FastLED / generateNonce

Method generateNonce

src/platforms/esp/32/ota/ota_impl.cpp.hpp:916–936  ·  view source on GitHub ↗

@brief Generate authentication nonce for OTA @param nonce Output buffer for nonce (64 characters for SHA256)

Source from the content-addressed store, hash-verified

914 /// @brief Generate authentication nonce for OTA
915 /// @param nonce Output buffer for nonce (64 characters for SHA256)
916 static void generateNonce(char* nonce, size_t len) {
917 // Generate nonce from timestamp and random data
918 unsigned char hash[32];
919 mbedtls_sha256_context ctx;
920 mbedtls_sha256_init(&ctx);
921 mbedtls_sha256_starts(&ctx, 0); // 0 = SHA256 (not SHA224)
922
923 u32 seed = esp_random();
924 mbedtls_sha256_update(&ctx, (unsigned char*)&seed, sizeof(seed));
925
926 i64 time_us = esp_timer_get_time();
927 mbedtls_sha256_update(&ctx, (unsigned char*)&time_us, sizeof(time_us));
928
929 mbedtls_sha256_finish(&ctx, hash);
930 mbedtls_sha256_free(&ctx);
931
932 // Convert to hex string
933 for (size_t i = 0; i < 32 && i * 2 + 1 < len; i++) {
934 fl::snprintf(nonce + i * 2, 3, "%02x", hash[i]);
935 }
936 }
937
938 /// @brief Verify OTA authentication response
939 /// @param password Password to verify against

Callers

nothing calls this directly

Calls 1

snprintfFunction · 0.85

Tested by

no test coverage detected