diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-26 12:13:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-26 12:13:11 +0700 |
commit | 335839d58ab12a9398b3883454008b273005ad52 (patch) | |
tree | 5164633cf406e424c19cff27ffcc62ee65cec571 | |
parent | Const-time padding improvements (diff) | |
download | BouncyCastle.NET-ed25519-335839d58ab12a9398b3883454008b273005ad52.tar.xz |
Handle zero-distance rotates correctly
-rw-r--r-- | crypto/src/util/Integers.cs | 8 | ||||
-rw-r--r-- | crypto/src/util/Longs.cs | 8 |
2 files changed, 8 insertions, 8 deletions
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 } } |