Skip to content

Commit 444055e

Browse files
committed
relates to github #2186: moved ML-DSA, SLH-DSA to use SignatureSpi.
adjusted composite to deal with the same. Java 4 compatibility fixes.
1 parent 471bec3 commit 444055e

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,37 @@ public static boolean constantTimeAreEqual(
177177
return nonEqual == 0;
178178
}
179179

180+
public static boolean constantTimeAreEqual(int len, long[] a, int aOff, long[] b, int bOff)
181+
{
182+
if (null == a)
183+
{
184+
throw new NullPointerException("'a' cannot be null");
185+
}
186+
if (null == b)
187+
{
188+
throw new NullPointerException("'b' cannot be null");
189+
}
190+
if (len < 0)
191+
{
192+
throw new IllegalArgumentException("'len' cannot be negative");
193+
}
194+
if (aOff > (a.length - len))
195+
{
196+
throw new IndexOutOfBoundsException("'aOff' value invalid for specified length");
197+
}
198+
if (bOff > (b.length - len))
199+
{
200+
throw new IndexOutOfBoundsException("'bOff' value invalid for specified length");
201+
}
202+
203+
long d = 0;
204+
for (int i = 0; i < len; ++i)
205+
{
206+
d |= (a[aOff + i] ^ b[bOff + i]);
207+
}
208+
return 0L == d;
209+
}
210+
180211
public static int compareUnsigned(byte[] a, byte[] b)
181212
{
182213
if (a == b)

core/src/test/java/org/bouncycastle/pqc/crypto/test/MLDSATest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void testConsistency()
7979
{
8080
AsymmetricCipherKeyPair kp = kpg.generateKeyPair();
8181

82-
Signer signer = parameters.isPreHash() ? new HashMLDSASigner() : new MLDSASigner();
82+
Signer signer = parameters.isPreHash() ? (Signer)new HashMLDSASigner() : (Signer)new MLDSASigner();
8383

8484
for (int j = 0; j < 2; ++j)
8585
{

prov/src/main/java/org/bouncycastle/jcajce/CompositeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CompositeUtil
3535

3636
static ASN1ObjectIdentifier getOid(String name)
3737
{
38-
ASN1ObjectIdentifier oid = algorithmOids.get(Strings.toUpperCase(name));
38+
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)algorithmOids.get(Strings.toUpperCase(name));
3939
if (oid == null)
4040
{
4141
throw new IllegalArgumentException("name " + name + " not recognized");

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositesignatures/SignatureSpi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,15 @@ protected boolean engineVerify(byte[] signature)
439439
throws SignatureException
440440
{
441441
int mldsaSigLen = 0;
442-
if (componentSignatures[0] instanceof org.bouncycastle.jcajce.provider.asymmetric.mldsa.SignatureSpi.MLDSA44)
442+
if (algs[0].indexOf("44") > 0)
443443
{
444444
mldsaSigLen = 2420;
445445
}
446-
else if (componentSignatures[0] instanceof org.bouncycastle.jcajce.provider.asymmetric.mldsa.SignatureSpi.MLDSA65)
446+
else if (algs[0].indexOf("65") > 0)
447447
{
448448
mldsaSigLen = 3309;
449449
}
450-
else if (componentSignatures[0] instanceof org.bouncycastle.jcajce.provider.asymmetric.mldsa.SignatureSpi.MLDSA87)
450+
else if (algs[0].indexOf("87") > 0)
451451
{
452452
mldsaSigLen = 4627;
453453
}

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/BaseDeterministicOrRandomSignature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import java.security.ProviderException;
88
import java.security.PublicKey;
99
import java.security.SecureRandom;
10-
import java.security.Signature;
1110
import java.security.SignatureException;
11+
import java.security.SignatureSpi;
1212
import java.security.spec.AlgorithmParameterSpec;
1313

1414
import org.bouncycastle.crypto.CipherParameters;
@@ -22,7 +22,7 @@
2222
import org.bouncycastle.util.Exceptions;
2323

2424
public abstract class BaseDeterministicOrRandomSignature
25-
extends Signature
25+
extends SignatureSpi
2626
{
2727
private final JcaJceHelper helper = new BCJcaJceHelper();
2828
private final AlgorithmParameterSpec originalSpec;
@@ -35,7 +35,6 @@ public abstract class BaseDeterministicOrRandomSignature
3535

3636
protected BaseDeterministicOrRandomSignature(String name)
3737
{
38-
super(name);
3938
this.originalSpec = ContextParameterSpec.EMPTY_CONTEXT_SPEC;
4039
}
4140

0 commit comments

Comments
 (0)