From 64403cefc15cb81281c1b68b2dddac57850f7c24 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sun, 24 Sep 2023 21:36:11 +0200 Subject: [PATCH] core: fix TOTP moving factor on big-endian systems --- ChangeLog.adoc | 7 +++++++ src/core/wee-crypto.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index d4fd96da6..56d6e2529 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -10,6 +10,13 @@ This document lists all the changes for each version. + For a list of important changes that require manual actions, please look at release notes. +[[v4.0.6]] +== Version 4.0.6 (under dev) + +Bug fixes:: + + * core: fix generation of TOTP on Big Endian systems (issue #2021) + [[v4.0.5]] == Version 4.0.5 (2023-09-24) diff --git a/src/core/wee-crypto.c b/src/core/wee-crypto.c index 3b86f5def..904ea4e20 100644 --- a/src/core/wee-crypto.c +++ b/src/core/wee-crypto.c @@ -421,6 +421,10 @@ weecrypto_totp_generate_internal (const char *secret, int length_secret, int rc, offset, length; unsigned long bin_code; +#if __BYTE_ORDER == __BIG_ENDIAN + /* Big endian does not need to swap bytes here! */ + moving_factor_swapped = moving_factor; +#else moving_factor_swapped = (moving_factor >> 56) | ((moving_factor << 40) & 0x00FF000000000000) | ((moving_factor << 24) & 0x0000FF0000000000) @@ -429,6 +433,7 @@ weecrypto_totp_generate_internal (const char *secret, int length_secret, | ((moving_factor >> 24) & 0x0000000000FF0000) | ((moving_factor >> 40) & 0x000000000000FF00) | (moving_factor << 56); +#endif rc = weecrypto_hmac (secret, length_secret, &moving_factor_swapped, sizeof (moving_factor_swapped),