Skip to content

Commit b0f8158

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents 969f2d7 + 2612e96 commit b0f8158

File tree

47 files changed

+1109
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1109
-128
lines changed

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/StreamUtil.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int read2OctetLength(InputStream in)
134134
}
135135

136136
static void write4OctetLength(OutputStream pOut, int len)
137-
throws IOException
137+
throws IOException
138138
{
139139
pOut.write(len >> 24);
140140
pOut.write(len >> 16);
@@ -151,7 +151,6 @@ static int read4OctetLength(InputStream in)
151151
static int flag_eof = 0;
152152
static int flag_isLongLength = 1;
153153
static int flag_partial = 2;
154-
155154
/**
156155
* Note: flags is an array of three boolean values:
157156
* flags[0] indicates l is negative, flag for eof
@@ -192,27 +191,27 @@ else if (l == 255)
192191
static void write8OctetLength(OutputStream pOut, long len)
193192
throws IOException
194193
{
195-
pOut.write((int)(len >> 56));
196-
pOut.write((int)(len >> 48));
197-
pOut.write((int)(len >> 40));
198-
pOut.write((int)(len >> 32));
199-
pOut.write((int)(len >> 24));
200-
pOut.write((int)(len >> 16));
201-
pOut.write((int)(len >> 8));
202-
pOut.write((int)len);
194+
pOut.write((int) (len >> 56));
195+
pOut.write((int) (len >> 48));
196+
pOut.write((int) (len >> 40));
197+
pOut.write((int) (len >> 32));
198+
pOut.write((int) (len >> 24));
199+
pOut.write((int) (len >> 16));
200+
pOut.write((int) (len >> 8));
201+
pOut.write((int) len);
203202
}
204203

205204
static long read8OctetLength(InputStream in)
206205
throws IOException
207206
{
208-
return ((long)in.read() << 56) |
209-
((long)in.read() << 48) |
210-
((long)in.read() << 40) |
211-
((long)in.read() << 32) |
212-
((long)in.read() << 24) |
213-
((long)in.read() << 16) |
214-
((long)in.read() << 8) |
215-
((long)in.read());
207+
return ((long) in.read() << 56) |
208+
((long) in.read() << 48) |
209+
((long) in.read() << 40) |
210+
((long) in.read() << 32) |
211+
((long) in.read() << 24) |
212+
((long) in.read() << 16) |
213+
((long) in.read() << 8) |
214+
((long) in.read());
216215
}
217216

218217
}

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)