提交 0844032a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use rotateLeft() and rotateRight() in Fog

上级 4d32c294
...@@ -36,16 +36,10 @@ public class Fog implements BlockCipher { ...@@ -36,16 +36,10 @@ public class Fog implements BlockCipher {
int x2 = Bits.readInt(in, off + 8); int x2 = Bits.readInt(in, off + 8);
int x3 = Bits.readInt(in, off + 12); int x3 = Bits.readInt(in, off + 12);
int k = key; int k = key;
int s = x1 & 31; x0 = Integer.rotateLeft(x0 ^ k, x1);
x0 ^= k; x2 = Integer.rotateLeft(x2 ^ k, x1);
x0 = (x0 << s) | (x0 >>> (32 - s)); x1 = Integer.rotateLeft(x1 ^ k, x0);
x2 ^= k; x3 = Integer.rotateLeft(x3 ^ k, x0);
x2 = (x2 << s) | (x2 >>> (32 - s));
s = x0 & 31;
x1 ^= k;
x1 = (x1 << s) | (x1 >>> (32 - s));
x3 ^= k;
x3 = (x3 << s) | (x3 >>> (32 - s));
Bits.writeInt(out, off, x0); Bits.writeInt(out, off, x0);
Bits.writeInt(out, off + 4, x1); Bits.writeInt(out, off + 4, x1);
Bits.writeInt(out, off + 8, x2); Bits.writeInt(out, off + 8, x2);
...@@ -58,16 +52,10 @@ public class Fog implements BlockCipher { ...@@ -58,16 +52,10 @@ public class Fog implements BlockCipher {
int x2 = Bits.readInt(in, off + 8); int x2 = Bits.readInt(in, off + 8);
int x3 = Bits.readInt(in, off + 12); int x3 = Bits.readInt(in, off + 12);
int k = key; int k = key;
int s = 32 - (x0 & 31); x1 = Integer.rotateRight(x1, x0) ^ k;
x1 = (x1 << s) | (x1 >>> (32 - s)); x3 = Integer.rotateRight(x3, x0) ^ k;
x1 ^= k; x0 = Integer.rotateRight(x0, x1) ^ k;
x3 = (x3 << s) | (x3 >>> (32 - s)); x2 = Integer.rotateRight(x2, x1) ^ k;
x3 ^= k;
s = 32 - (x1 & 31);
x0 = (x0 << s) | (x0 >>> (32 - s));
x0 ^= k;
x2 = (x2 << s) | (x2 >>> (32 - s));
x2 ^= k;
Bits.writeInt(out, off, x0); Bits.writeInt(out, off, x0);
Bits.writeInt(out, off + 4, x1); Bits.writeInt(out, off + 4, x1);
Bits.writeInt(out, off + 8, x2); Bits.writeInt(out, off + 8, x2);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论