Skip to content

Commit 3c31f1f

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents 57ab020 + c4819e1 commit 3c31f1f

32 files changed

+571
-481
lines changed

CONTRIBUTORS.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@
568568
<li>Linuka Ratnayake &lt;https://github.com/linukaratnayake&gt; - initial patches for including KEM-type algorithms in TLS key shares.</li>
569569
<li>Rune Flobakk &lt;https://github.com/runeflobakk&gt; - initial gradle mods for BOM (Bill of Materials) creation.</li>
570570
<li>Jon Marius Venstad &lt;https://github.com/jonmv&gt; - Fixed a KangarooTwelve padding bug caused by premature absorption of queued data.</li>
571+
<li>Lomig Mégard &lt;https://github.com/lomigmegard&gt; - BLAKE2 defensive improvements and cleanup.</li>
571572
</ul>
572573
</body>
573574
</html>

core/src/main/j2me/java/math/BigInteger.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Vector;
66

77
import org.bouncycastle.util.Arrays;
8+
import org.bouncycastle.util.Integers;
89

910
public class BigInteger
1011
{
@@ -978,9 +979,10 @@ private static int compareNoLeadingZeroes(int xIndx, int[] x, int yIndx, int[] y
978979
int v1 = x[xIndx++];
979980
int v2 = y[yIndx++];
980981

981-
if (v1 != v2)
982+
int c = Integers.compareUnsigned(v1, v2);
983+
if (c != 0)
982984
{
983-
return (v1 ^ Integer.MIN_VALUE) < (v2 ^ Integer.MIN_VALUE) ? -1 : 1;
985+
return c;
984986
}
985987
}
986988

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public static int bitCount(int i)
2222
return i;
2323
}
2424

25+
public static int compare(int x, int y)
26+
{
27+
return x < y ? -1 : x == y ? 0 : 1;
28+
}
29+
30+
public static int compareUnsigned(int x, int y)
31+
{
32+
return compare(x + Integer.MIN_VALUE, y + Integer.MIN_VALUE);
33+
}
34+
2535
public static int highestOneBit(int i)
2636
{
2737
i |= (i >> 1);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public class Longs
1313
0x3E, 0x33, 0x05, 0x19, 0x24, 0x27, 0x20, 0x2E, 0x3C, 0x2C, 0x2A, 0x14, 0x16, 0x39, 0x10, 0x09,
1414
0x32, 0x18, 0x23, 0x1F, 0x3B, 0x13, 0x38, 0x0F, 0x31, 0x1E, 0x12, 0x0E, 0x1D, 0x0D, 0x0C, 0x0B };
1515

16+
public static int compare(long x, long y)
17+
{
18+
return x < y ? -1 : x == y ? 0 : 1;
19+
}
20+
21+
public static int compareUnsigned(long x, long y)
22+
{
23+
return compare(x + Long.MIN_VALUE, y + Long.MIN_VALUE);
24+
}
25+
1626
public static long highestOneBit(long i)
1727
{
1828
i |= (i >> 1);

core/src/main/java/org/bouncycastle/crypto/digests/AsconCXof128.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected long loadBytes(final byte[] bytes, int inOff)
5858

5959
protected long loadBytes(final byte[] bytes, int inOff, int n)
6060
{
61-
return Pack.littleEndianToLong(bytes, inOff, n);
61+
return n <= 0 ? 0L : Pack.littleEndianToLong_Low(bytes, inOff, n);
6262
}
6363

6464
protected void setBytes(long w, byte[] bytes, int inOff)
@@ -68,7 +68,10 @@ protected void setBytes(long w, byte[] bytes, int inOff)
6868

6969
protected void setBytes(long w, byte[] bytes, int inOff, int n)
7070
{
71-
Pack.longToLittleEndian(w, bytes, inOff, n);
71+
if (n > 0)
72+
{
73+
Pack.longToLittleEndian_Low(w, bytes, inOff, n);
74+
}
7275
}
7376

7477
@Override

core/src/main/java/org/bouncycastle/crypto/digests/AsconDigest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected long loadBytes(final byte[] bytes, int inOff)
5353

5454
protected long loadBytes(final byte[] bytes, int inOff, int n)
5555
{
56-
return Pack.bigEndianToLong(bytes, inOff, n);
56+
return n <= 0 ? 0L : Pack.bigEndianToLong_High(bytes, inOff, n);
5757
}
5858

5959
protected void setBytes(long w, byte[] bytes, int inOff)
@@ -63,7 +63,10 @@ protected void setBytes(long w, byte[] bytes, int inOff)
6363

6464
protected void setBytes(long w, byte[] bytes, int inOff, int n)
6565
{
66-
Pack.longToBigEndian(w, bytes, inOff, n);
66+
if (n > 0)
67+
{
68+
Pack.longToBigEndian_High(w, bytes, inOff, n);
69+
}
6770
}
6871

6972
@Override

core/src/main/java/org/bouncycastle/crypto/digests/AsconHash256.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected long loadBytes(final byte[] bytes, int inOff)
3434

3535
protected long loadBytes(final byte[] bytes, int inOff, int n)
3636
{
37-
return Pack.littleEndianToLong(bytes, inOff, n);
37+
return n <= 0 ? 0L : Pack.littleEndianToLong_Low(bytes, inOff, n);
3838
}
3939

4040
protected void setBytes(long w, byte[] bytes, int inOff)
@@ -44,7 +44,10 @@ protected void setBytes(long w, byte[] bytes, int inOff)
4444

4545
protected void setBytes(long w, byte[] bytes, int inOff, int n)
4646
{
47-
Pack.longToLittleEndian(w, bytes, inOff, n);
47+
if (n > 0)
48+
{
49+
Pack.longToLittleEndian_Low(w, bytes, inOff, n);
50+
}
4851
}
4952

5053
@Override

core/src/main/java/org/bouncycastle/crypto/digests/AsconXof.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected long loadBytes(final byte[] bytes, int inOff)
5454

5555
protected long loadBytes(final byte[] bytes, int inOff, int n)
5656
{
57-
return Pack.bigEndianToLong(bytes, inOff, n);
57+
return n <= 0 ? 0L : Pack.bigEndianToLong_High(bytes, inOff, n);
5858
}
5959

6060
protected void setBytes(long w, byte[] bytes, int inOff)
@@ -64,7 +64,10 @@ protected void setBytes(long w, byte[] bytes, int inOff)
6464

6565
protected void setBytes(long w, byte[] bytes, int inOff, int n)
6666
{
67-
Pack.longToBigEndian(w, bytes, inOff, n);
67+
if (n > 0)
68+
{
69+
Pack.longToBigEndian_High(w, bytes, inOff, n);
70+
}
6871
}
6972

7073
@Override

core/src/main/java/org/bouncycastle/crypto/digests/AsconXof128.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected long loadBytes(final byte[] bytes, int inOff)
3535

3636
protected long loadBytes(final byte[] bytes, int inOff, int n)
3737
{
38-
return Pack.littleEndianToLong(bytes, inOff, n);
38+
return n <= 0 ? 0L : Pack.littleEndianToLong_Low(bytes, inOff, n);
3939
}
4040

4141
protected void setBytes(long w, byte[] bytes, int inOff)
@@ -45,7 +45,10 @@ protected void setBytes(long w, byte[] bytes, int inOff)
4545

4646
protected void setBytes(long w, byte[] bytes, int inOff, int n)
4747
{
48-
Pack.longToLittleEndian(w, bytes, inOff, n);
48+
if (n > 0)
49+
{
50+
Pack.longToLittleEndian_Low(w, bytes, inOff, n);
51+
}
4952
}
5053

5154
@Override

0 commit comments

Comments
 (0)