Skip to content

Commit 04f2f98

Browse files
author
royb
committed
Merge remote-tracking branch 'origin/main'
2 parents 920de25 + acf48ff commit 04f2f98

20 files changed

+571
-61
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
}

pg/src/main/java/org/bouncycastle/bcpg/PublicKeyPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public class PublicKeyPacket
136136
throw new UnsupportedPacketVersionException("Unsupported Public Key Packet version encountered: " + version);
137137
}
138138

139-
time = StreamUtil.read4OctetLength(in);
139+
time = StreamUtil.read4OctetLength(in) & 0xFFFFFFFFL;
140140

141141
if (version == 2 || version == VERSION_3)
142142
{

pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,15 @@ private void parseSignature(BCPGInputStream in)
254254
signature[0] = v;
255255
break;
256256
case DSA:
257+
case ELGAMAL_ENCRYPT: // yep, this really does happen sometimes.
258+
case ELGAMAL_GENERAL:
257259
MPInteger r = new MPInteger(in);
258260
MPInteger s = new MPInteger(in);
259261

260262
signature = new MPInteger[2];
261263
signature[0] = r;
262264
signature[1] = s;
263265
break;
264-
case ELGAMAL_ENCRYPT: // yep, this really does happen sometimes.
265-
case ELGAMAL_GENERAL:
266-
MPInteger p = new MPInteger(in);
267-
MPInteger g = new MPInteger(in);
268-
MPInteger y = new MPInteger(in);
269-
270-
signature = new MPInteger[3];
271-
signature[0] = p;
272-
signature[1] = g;
273-
signature[2] = y;
274-
break;
275266
case Ed448:
276267
signatureEncoding = new byte[org.bouncycastle.math.ec.rfc8032.Ed448.SIGNATURE_SIZE];
277268
in.readFully(signatureEncoding);

pg/src/main/java/org/bouncycastle/bcpg/StreamUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void writeTime(BCPGOutputStream pOut, long time)
117117
static long readTime(BCPGInputStream in)
118118
throws IOException
119119
{
120-
return (long)read4OctetLength(in) * 1000L;
120+
return ((long)read4OctetLength(in) & 0xFFFFFFFFL) * 1000L;
121121
}
122122

123123
static void write2OctetLength(OutputStream pOut, int len)

pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010

1111
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
1212
import org.bouncycastle.asn1.cryptlib.CryptlibObjectIdentifiers;
13+
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
1314
import org.bouncycastle.asn1.gnu.GNUObjectIdentifiers;
1415
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
1516
import org.bouncycastle.asn1.x9.X9ECParametersHolder;
1617
import org.bouncycastle.bcpg.BCPGKey;
1718
import org.bouncycastle.bcpg.BCPGOutputStream;
1819
import org.bouncycastle.bcpg.DSAPublicBCPGKey;
1920
import org.bouncycastle.bcpg.ECPublicBCPGKey;
21+
import org.bouncycastle.bcpg.Ed448PublicBCPGKey;
2022
import org.bouncycastle.bcpg.ElGamalPublicBCPGKey;
2123
import org.bouncycastle.bcpg.KeyIdentifier;
24+
import org.bouncycastle.bcpg.OctetArrayBCPGKey;
2225
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
2326
import org.bouncycastle.bcpg.PublicKeyPacket;
2427
import org.bouncycastle.bcpg.PublicSubkeyPacket;
@@ -28,6 +31,7 @@
2831
import org.bouncycastle.bcpg.UserAttributePacket;
2932
import org.bouncycastle.bcpg.UserDataPacket;
3033
import org.bouncycastle.bcpg.UserIDPacket;
34+
import org.bouncycastle.bcpg.X448PublicBCPGKey;
3135
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
3236
import org.bouncycastle.util.Arrays;
3337

@@ -47,7 +51,7 @@ public class PGPPublicKey
4751
List<List<PGPSignature>> idSigs = new ArrayList<List<PGPSignature>>();
4852

4953
List<PGPSignature> subSigs = null;
50-
54+
5155
private KeyIdentifier keyIdentifier;
5256
private int keyStrength;
5357

@@ -90,6 +94,14 @@ else if (key instanceof ECPublicBCPGKey)
9094
{
9195
this.keyStrength = 256;
9296
}
97+
else if (curveOID.equals(EdECObjectIdentifiers.id_X448))
98+
{
99+
this.keyStrength = X448PublicBCPGKey.LENGTH * 8;
100+
}
101+
else if (curveOID.equals(EdECObjectIdentifiers.id_Ed448))
102+
{
103+
this.keyStrength = Ed448PublicBCPGKey.LENGTH * 8;
104+
}
93105
else
94106
{
95107
X9ECParametersHolder ecParameters = ECNamedCurveTable.getByOIDLazy(curveOID);
@@ -104,6 +116,10 @@ else if (key instanceof ECPublicBCPGKey)
104116
}
105117
}
106118
}
119+
else if (key instanceof OctetArrayBCPGKey)
120+
{
121+
this.keyStrength = key.getEncoded().length * 8;
122+
}
107123
}
108124
}
109125

@@ -150,7 +166,7 @@ public PGPPublicKey(PublicKeyPacket publicKeyPacket, KeyFingerPrintCalculator fi
150166
this.publicPk = key.publicPk;
151167
this.trustPk = trust;
152168
this.subSigs = subSigs;
153-
169+
154170
this.keyStrength = key.keyStrength;
155171
this.keyIdentifier = key.keyIdentifier;
156172
}
@@ -1216,7 +1232,8 @@ private static void joinPgpSignatureList(List<PGPSignature> source,
12161232
for (int i = 0; isNotNull && i < rlt.size(); i++)
12171233
{
12181234
PGPSignature existingSubSig = (PGPSignature)rlt.get(i);
1219-
if (PGPSignature.isSignatureEncodingEqual(existingSubSig, copySubSig))
1235+
if (existingSubSig.getVersion() == copySubSig.getVersion() &&
1236+
PGPSignature.isSignatureEncodingEqual(existingSubSig, copySubSig))
12201237
{
12211238
found = true;
12221239
// join existing sig with copy to apply modifications in unhashed subpackets

0 commit comments

Comments
 (0)