Refined code for mbedtls_ms_time() #549

Open
opened 2025-10-26 08:31:58 -05:00 by irwir · 0 comments
irwir commented 2025-10-26 08:31:58 -05:00 (Migrated from github.com)

github.com/Mbed-TLS/TF-PSA-Crypto@8fa3370f74/drivers/builtin/src/platform_util.c (L251-L260)

According to FILETIME description from Microsoft, the code should be:

mbedtls_ms_time_t mbedtls_ms_time(void)
{
    FILETIME ct;
    ULARGE_INTEGER li;
 
    GetSystemTimeAsFileTime(&ct);
    li.LowPart = ct.dwLowDateTime;
    li.HighPart = ct.dwHighDateTime;
    return (mbedtls_ms_time_t)(li.QuadPart / 10000);
}

Looks tidier without type casts and additional calculations, gives better code without optimizer.

https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/8fa3370f747c5eae3c5004f47241cf45203c6a83/drivers/builtin/src/platform_util.c#L251-L260 According to `FILETIME` description from Microsoft, the code should be: ``` mbedtls_ms_time_t mbedtls_ms_time(void) { FILETIME ct; ULARGE_INTEGER li; GetSystemTimeAsFileTime(&ct); li.LowPart = ct.dwLowDateTime; li.HighPart = ct.dwHighDateTime; return (mbedtls_ms_time_t)(li.QuadPart / 10000); } ``` Looks tidier without type casts and additional calculations, gives better code without optimizer.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#549
No description provided.