Skip to content

Commit 5113002

Browse files
committed
Handle zero-distance rotates correctly
1 parent 7826300 commit 5113002

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

core/src/main/j2me/org/bouncycastle/util/Integers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public static int reverseBytes(int i)
6565

6666
public static int rotateLeft(int i, int distance)
6767
{
68-
return (i << distance) ^ (i >>> -distance);
68+
return (i << distance) | (i >>> -distance);
6969
}
7070

7171
public static int rotateRight(int i, int distance)
7272
{
73-
return (i >>> distance) ^ (i << -distance);
73+
return (i >>> distance) | (i << -distance);
7474
}
7575

7676
public static Integer valueOf(int value)

core/src/main/j2me/org/bouncycastle/util/Longs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public static long reverseBytes(long i)
6565

6666
public static long rotateLeft(long i, int distance)
6767
{
68-
return (i << distance) ^ (i >>> -distance);
68+
return (i << distance) | (i >>> -distance);
6969
}
7070

7171
public static long rotateRight(long i, int distance)
7272
{
73-
return (i >>> distance) ^ (i << -distance);
73+
return (i >>> distance) | (i << -distance);
7474
}
7575

7676
public static Long valueOf(long value)

core/src/main/jdk1.4/org/bouncycastle/util/Integers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public static int reverseBytes(int i)
6565

6666
public static int rotateLeft(int i, int distance)
6767
{
68-
return (i << distance) ^ (i >>> -distance);
68+
return (i << distance) | (i >>> -distance);
6969
}
7070

7171
public static int rotateRight(int i, int distance)
7272
{
73-
return (i >>> distance) ^ (i << -distance);
73+
return (i >>> distance) | (i << -distance);
7474
}
7575

7676
public static Integer valueOf(int value)

core/src/main/jdk1.4/org/bouncycastle/util/Longs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public static long reverseBytes(long i)
6565

6666
public static long rotateLeft(long i, int distance)
6767
{
68-
return (i << distance) ^ (i >>> -distance);
68+
return (i << distance) | (i >>> -distance);
6969
}
7070

7171
public static long rotateRight(long i, int distance)
7272
{
73-
return (i >>> distance) ^ (i << -distance);
73+
return (i >>> distance) | (i << -distance);
7474
}
7575

7676
public static Long valueOf(long value)

0 commit comments

Comments
 (0)