Skip to content

Commit 47539e2

Browse files
committed
added public key verification to private parameters where public key is provided.
1 parent 77419cc commit 47539e2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ public MLDSAPrivateKeyParameters(MLDSAParameters params, byte[] encoding, MLDSAP
7474
delta = eng.getDilithiumK() * MLDSAEngine.DilithiumPolyT0PackedBytes;
7575
this.t0 = Arrays.copyOfRange(encoding, index, index + delta);
7676
index += delta;
77+
this.t1 = eng.deriveT1(rho, k, tr, s1, s2, t0);
7778

7879
if (pubKey != null)
7980
{
80-
this.t1 = pubKey.getT1();
81-
}
82-
else
83-
{
84-
this.t1 = eng.deriveT1(rho, k, tr, s1, s2, t0);
81+
if (!Arrays.constantTimeAreEqual(this.t1, pubKey.getT1()))
82+
{
83+
throw new IllegalArgumentException("passed in public key does not match private values");
84+
}
8585
}
86+
8687
this.seed = null;
8788
}
8889
}

0 commit comments

Comments
 (0)