Skip to content

Commit d6af532

Browse files
committed
moved pubKey test for ML-DSA to apply to both encodings.
added pubKey check to ML-KEM where pubKey is provided.
1 parent ce4aeba commit d6af532

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

core/src/main/java/org/bouncycastle/pqc/crypto/mldsa/MLDSAPrivateKeyParameters.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ public MLDSAPrivateKeyParameters(MLDSAParameters params, byte[] encoding, MLDSAP
8282
this.t0 = Arrays.copyOfRange(encoding, index, index + delta);
8383
index += delta;
8484
this.t1 = eng.deriveT1(rho, k, tr, s1, s2, t0);
85+
this.seed = null;
86+
}
8587

86-
if (pubKey != null)
88+
if (pubKey != null)
89+
{
90+
if (!Arrays.constantTimeAreEqual(this.t1, pubKey.getT1()))
8791
{
88-
if (!Arrays.constantTimeAreEqual(this.t1, pubKey.getT1()))
89-
{
90-
throw new IllegalArgumentException("passed in public key does not match private values");
91-
}
92+
throw new IllegalArgumentException("passed in public key does not match private values");
9293
}
93-
94-
this.seed = null;
9594
}
95+
9696
this.prefFormat = (seed != null) ? BOTH : EXPANDED_KEY;
9797
}
9898

core/src/main/java/org/bouncycastle/pqc/crypto/mlkem/MLKEMPrivateKeyParameters.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public MLKEMPrivateKeyParameters(MLKEMParameters params, byte[] s, byte[] hpk, b
3737
}
3838

3939
public MLKEMPrivateKeyParameters(MLKEMParameters params, byte[] encoding)
40+
{
41+
this(params, encoding, null);
42+
}
43+
44+
public MLKEMPrivateKeyParameters(MLKEMParameters params, byte[] encoding, MLKEMPublicKeyParameters pubKey)
4045
{
4146
super(true, params);
4247

@@ -68,6 +73,14 @@ public MLKEMPrivateKeyParameters(MLKEMParameters params, byte[] encoding)
6873
this.seed = null;
6974
}
7075

76+
if (pubKey != null)
77+
{
78+
if (!Arrays.constantTimeAreEqual(this.t, pubKey.t) || !Arrays.constantTimeAreEqual(this.rho, pubKey.rho))
79+
{
80+
throw new IllegalArgumentException("passed in public key does not match private values");
81+
}
82+
}
83+
7184
this.prefFormat = BOTH;
7285
}
7386

0 commit comments

Comments
 (0)