From 10c882d27cb970189c7987af93d8cdb83af44c54 Mon Sep 17 00:00:00 2001 From: Li Cao Date: Fri, 5 Dec 2025 11:16:16 +0800 Subject: [PATCH] [posix] remove sanitizer code in entropy (#12196) The sanitizer code won't be used on posix platform. --- src/posix/platform/entropy.cpp | 67 +--------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/src/posix/platform/entropy.cpp b/src/posix/platform/entropy.cpp index 2dc98e3d2..ce28573dd 100644 --- a/src/posix/platform/entropy.cpp +++ b/src/posix/platform/entropy.cpp @@ -42,58 +42,15 @@ #include "common/code_utils.hpp" -#ifndef __SANITIZE_ADDRESS__ -#define __SANITIZE_ADDRESS__ 0 -#endif - -#if __SANITIZE_ADDRESS__ != 0 - -static uint32_t sState = 1; - -#endif // __SANITIZE_ADDRESS__ - void platformRandomInit(void) { -#if __SANITIZE_ADDRESS__ != 0 - - // Multiplying gNodeId assures that no two nodes gets the same seed within an hour. - sState = (uint32_t)time(nullptr) + (3600 * gNodeId); - -#endif // __SANITIZE_ADDRESS__ + // Do nothing. } -#if __SANITIZE_ADDRESS__ != 0 - -uint32_t randomUint32Get(void) -{ - uint32_t mlcg, p, q; - uint64_t tmpstate; - - tmpstate = (uint64_t)33614 * (uint64_t)sState; - q = tmpstate & 0xffffffff; - q = q >> 1; - p = tmpstate >> 32; - mlcg = p + q; - - if (mlcg & 0x80000000) - { - mlcg &= 0x7fffffff; - mlcg++; - } - - sState = mlcg; - - return mlcg; -} - -#endif // __SANITIZE_ADDRESS__ - otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) { otError error = OT_ERROR_NONE; -#if __SANITIZE_ADDRESS__ == 0 - FILE *file = nullptr; size_t readLength; @@ -111,27 +68,5 @@ exit: { fclose(file); } - -#else // __SANITIZE_ADDRESS__ - - /* - * THE IMPLEMENTATION BELOW IS NOT COMPLIANT WITH THE THREAD SPECIFICATION. - * - * Address Sanitizer triggers test failures when reading random - * values from /dev/urandom. The pseudo-random number generator - * implementation below is only used to enable continuous - * integration checks with Address Sanitizer enabled. - */ - VerifyOrExit(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); - - for (uint16_t length = 0; length < aOutputLength; length++) - { - aOutput[length] = (uint8_t)randomUint32Get(); - } - -exit: - -#endif // __SANITIZE_ADDRESS__ - return error; }