From 5b58356390777bed5fa230fc15fb06ff124eaa9c Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Wed, 14 Aug 2024 12:15:55 +0200 Subject: [PATCH] core: replace manual endianness swap with htobe64() call This fixes generation of TOTP and tests on FreeBSD. --- CHANGELOG.md | 1 + src/core/core-crypto.c | 19 +++++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8b71d1f4..46d40cd74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ - core: fix crash when deleting a bar that has no items ([#2138](https://github.com/weechat/weechat/issues/2138)) - relay/api: fix crash when sending data to a remote buffer when the remote has been deleted ([#2157](https://github.com/weechat/weechat/issues/2157)) - irc, xfer: fix display of input prompt in IRC private buffers and DCC chat buffers ([#2128](https://github.com/weechat/weechat/issues/2128)) +- core: fix generation of TOTP on FreeBSD ([#2171](https://github.com/weechat/weechat/issues/2171)) - core: apply buffer properties (options weechat.buffer.*) when a buffer name is changed - irc: fix property "short_name" of channel buffer when the joined channel has a different case than the `/join` command - irc: close /list buffer when the server buffer is closed ([#2121](https://github.com/weechat/weechat/issues/2121)) diff --git a/src/core/core-crypto.c b/src/core/core-crypto.c index 4d0e6e9f2..175982fdb 100644 --- a/src/core/core-crypto.c +++ b/src/core/core-crypto.c @@ -38,6 +38,10 @@ #include "core-string.h" #include "../plugins/plugin.h" +#ifdef htonll +#define htobe64 htonll +#endif + char *weecrypto_hash_algo_string[] = { "crc32", "md5", @@ -520,20 +524,7 @@ 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) - | ((moving_factor << 8) & 0x000000FF00000000) - | ((moving_factor >> 8) & 0x00000000FF000000) - | ((moving_factor >> 24) & 0x0000000000FF0000) - | ((moving_factor >> 40) & 0x000000000000FF00) - | (moving_factor << 56); -#endif - + moving_factor_swapped = htobe64 (moving_factor); rc = weecrypto_hmac (secret, length_secret, &moving_factor_swapped, sizeof (moving_factor_swapped), GCRY_MD_SHA1,