From 335839d58ab12a9398b3883454008b273005ad52 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 26 Aug 2022 12:13:11 +0700 Subject: Handle zero-distance rotates correctly --- crypto/src/util/Integers.cs | 8 ++++---- crypto/src/util/Longs.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crypto') diff --git a/crypto/src/util/Integers.cs b/crypto/src/util/Integers.cs index b0c899500..75ba566e3 100644 --- a/crypto/src/util/Integers.cs +++ b/crypto/src/util/Integers.cs @@ -111,7 +111,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return (int)BitOperations.RotateLeft((uint)i, distance); #else - return (i << distance) ^ (int)((uint)i >> -distance); + return (i << distance) | (int)((uint)i >> -distance); #endif } @@ -121,7 +121,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return BitOperations.RotateLeft(i, distance); #else - return (i << distance) ^ (i >> -distance); + return (i << distance) | (i >> -distance); #endif } @@ -130,7 +130,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return (int)BitOperations.RotateRight((uint)i, distance); #else - return (int)((uint)i >> distance) ^ (i << -distance); + return (int)((uint)i >> distance) | (i << -distance); #endif } @@ -140,7 +140,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return BitOperations.RotateRight(i, distance); #else - return (i >> distance) ^ (i << -distance); + return (i >> distance) | (i << -distance); #endif } } diff --git a/crypto/src/util/Longs.cs b/crypto/src/util/Longs.cs index 0bb35de25..9e34dab99 100644 --- a/crypto/src/util/Longs.cs +++ b/crypto/src/util/Longs.cs @@ -112,7 +112,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return (long)BitOperations.RotateLeft((ulong)i, distance); #else - return (i << distance) ^ (long)((ulong)i >> -distance); + return (i << distance) | (long)((ulong)i >> -distance); #endif } @@ -122,7 +122,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return BitOperations.RotateLeft(i, distance); #else - return (i << distance) ^ (i >> -distance); + return (i << distance) | (i >> -distance); #endif } @@ -131,7 +131,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return (long)BitOperations.RotateRight((ulong)i, distance); #else - return (long)((ulong)i >> distance) ^ (i << -distance); + return (long)((ulong)i >> distance) | (i << -distance); #endif } @@ -141,7 +141,7 @@ namespace Org.BouncyCastle.Utilities #if NETCOREAPP3_0_OR_GREATER return BitOperations.RotateRight(i, distance); #else - return (i >> distance) ^ (i << -distance); + return (i >> distance) | (i << -distance); #endif } } -- cgit 1.4.1