Skip to content

Commit 525bf6f

Browse files
committed
merge bitcoin#29815: always use our fallback timingsafe_bcmp rather than libc's
1 parent 42aa57a commit 525bf6f

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,6 @@ AC_CHECK_DECLS([setsid])
10591059

10601060
AC_CHECK_DECLS([pipe2])
10611061

1062-
AC_CHECK_FUNCS([timingsafe_bcmp])
1063-
10641062
dnl Check for mallopt(M_ARENA_MAX) (to set glibc arenas)
10651063
AC_MSG_CHECKING([for mallopt M_ARENA_MAX])
10661064
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],

src/crypto/chacha20poly1305.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ void AEADChaCha20Poly1305::SetKey(Span<const std::byte> key) noexcept
2626

2727
namespace {
2828

29-
#ifndef HAVE_TIMINGSAFE_BCMP
30-
#define HAVE_TIMINGSAFE_BCMP
31-
32-
int timingsafe_bcmp(const unsigned char* b1, const unsigned char* b2, size_t n) noexcept
29+
int timingsafe_bcmp_internal(const unsigned char* b1, const unsigned char* b2, size_t n) noexcept
3330
{
3431
const unsigned char *p1 = b1, *p2 = b2;
3532
int ret = 0;
@@ -38,8 +35,6 @@ int timingsafe_bcmp(const unsigned char* b1, const unsigned char* b2, size_t n)
3835
return (ret != 0);
3936
}
4037

41-
#endif
42-
4338
/** Compute poly1305 tag. chacha20 must be set to the right nonce, block 0. Will be at block 1 after. */
4439
void ComputeTag(ChaCha20& chacha20, Span<const std::byte> aad, Span<const std::byte> cipher, Span<std::byte> tag) noexcept
4540
{
@@ -93,7 +88,7 @@ bool AEADChaCha20Poly1305::Decrypt(Span<const std::byte> cipher, Span<const std:
9388
m_chacha20.Seek(nonce, 0);
9489
std::byte expected_tag[EXPANSION];
9590
ComputeTag(m_chacha20, aad, cipher.first(cipher.size() - EXPANSION), expected_tag);
96-
if (timingsafe_bcmp(UCharCast(expected_tag), UCharCast(cipher.last(EXPANSION).data()), EXPANSION)) return false;
91+
if (timingsafe_bcmp_internal(UCharCast(expected_tag), UCharCast(cipher.last(EXPANSION).data()), EXPANSION)) return false;
9792

9893
// Decrypt (starting at block 1).
9994
m_chacha20.Crypt(cipher.first(plain1.size()), plain1);

0 commit comments

Comments
 (0)