Skip to content

Commit 2a957c4

Browse files
committed
Fix properly parsing of bit strength for X25519/X448/Ed25519/Ed448 keys
1 parent 93c1cb4 commit 2a957c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
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;
23+
import org.bouncycastle.bcpg.OctetArrayBCPGKey;
2124
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
2225
import org.bouncycastle.bcpg.PublicKeyPacket;
2326
import org.bouncycastle.bcpg.PublicSubkeyPacket;
@@ -27,6 +30,7 @@
2730
import org.bouncycastle.bcpg.UserAttributePacket;
2831
import org.bouncycastle.bcpg.UserDataPacket;
2932
import org.bouncycastle.bcpg.UserIDPacket;
33+
import org.bouncycastle.bcpg.X448PublicBCPGKey;
3034
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
3135
import org.bouncycastle.util.Arrays;
3236
import org.bouncycastle.util.Pack;
@@ -98,6 +102,14 @@ else if (key instanceof ECPublicBCPGKey)
98102
{
99103
this.keyStrength = 256;
100104
}
105+
else if (curveOID.equals(EdECObjectIdentifiers.id_X448))
106+
{
107+
this.keyStrength = X448PublicBCPGKey.LENGTH * 8;
108+
}
109+
else if (curveOID.equals(EdECObjectIdentifiers.id_Ed448))
110+
{
111+
this.keyStrength = Ed448PublicBCPGKey.LENGTH * 8;
112+
}
101113
else
102114
{
103115
X9ECParametersHolder ecParameters = ECNamedCurveTable.getByOIDLazy(curveOID);
@@ -112,6 +124,10 @@ else if (key instanceof ECPublicBCPGKey)
112124
}
113125
}
114126
}
127+
else if (key instanceof OctetArrayBCPGKey)
128+
{
129+
this.keyStrength = key.getEncoded().length * 8;
130+
}
115131
}
116132
}
117133

0 commit comments

Comments
 (0)