summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto_internal.h
diff options
context:
space:
mode:
authorjsing <>2025-01-19 07:51:41 +0000
committerjsing <>2025-01-19 07:51:41 +0000
commita2f6e4db5ee489ac3600ec5518e9914d017f85de (patch)
treeec020deb0d1f679179eab8c5f4643191d4e623cc /src/lib/libcrypto/crypto_internal.h
parent34423391bcc52ecedccc906e3945ef585e383920 (diff)
downloadopenbsd-a2f6e4db5ee489ac3600ec5518e9914d017f85de.tar.gz
openbsd-a2f6e4db5ee489ac3600ec5518e9914d017f85de.tar.bz2
openbsd-a2f6e4db5ee489ac3600ec5518e9914d017f85de.zip
Improve bit counter handling in MD5.
Like most hashes, MD5 needs to keep count of the number of bits in the message being processed. However, rather than using a 64 bit counter this is implemented using two 32 bit values (which is exposed in the public API). Even with this hurdle, we can still use 64 bit math and let the compiler figure out how to best handle the situation (hopefully avoiding compiler warnings on 16 bit platforms in the process!). On amd64 this code now requires two instructions, instead of the previous five. While here remove a comment that is excessively visible and no longer completely accurate (and if you're going to redefine types like MD5_WORD you kinda need to know what you're doing). ok tb@ (who's going to miss the dear diary style comments)
Diffstat (limited to 'src/lib/libcrypto/crypto_internal.h')
-rw-r--r--src/lib/libcrypto/crypto_internal.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h
index c5de5b7b51..09ae7fa466 100644
--- a/src/lib/libcrypto/crypto_internal.h
+++ b/src/lib/libcrypto/crypto_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_internal.h,v 1.14 2024/11/08 14:05:43 jsing Exp $ */ 1/* $OpenBSD: crypto_internal.h,v 1.15 2025/01/19 07:51:41 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -256,6 +256,16 @@ crypto_store_htole32(uint8_t *dst, uint32_t v)
256} 256}
257#endif 257#endif
258 258
259#ifndef HAVE_CRYPTO_ADD_U32DW_U64
260static inline void
261crypto_add_u32dw_u64(uint32_t *h, uint32_t *l, uint64_t v)
262{
263 v += ((uint64_t)*h << 32) | *l;
264 *h = v >> 32;
265 *l = v;
266}
267#endif
268
259#ifndef HAVE_CRYPTO_ROL_U32 269#ifndef HAVE_CRYPTO_ROL_U32
260static inline uint32_t 270static inline uint32_t
261crypto_rol_u32(uint32_t v, size_t shift) 271crypto_rol_u32(uint32_t v, size_t shift)