Skip to content

Commit

Permalink
Fix properly parsing of bit strength for X25519/X448/Ed25519/Ed448 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Sep 10, 2024
1 parent bdebcde commit aa95529
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@

import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cryptlib.CryptlibObjectIdentifiers;
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
import org.bouncycastle.asn1.gnu.GNUObjectIdentifiers;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParametersHolder;
import org.bouncycastle.bcpg.BCPGKey;
import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.DSAPublicBCPGKey;
import org.bouncycastle.bcpg.ECPublicBCPGKey;
import org.bouncycastle.bcpg.Ed25519PublicBCPGKey;
import org.bouncycastle.bcpg.Ed448PublicBCPGKey;
import org.bouncycastle.bcpg.ElGamalPublicBCPGKey;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.bcpg.PublicSubkeyPacket;
import org.bouncycastle.bcpg.RSAPublicBCPGKey;
import org.bouncycastle.bcpg.SignatureSubpacketTags;
import org.bouncycastle.bcpg.TrustPacket;
import org.bouncycastle.bcpg.UnknownBCPGKey;
import org.bouncycastle.bcpg.UserAttributePacket;
import org.bouncycastle.bcpg.UserDataPacket;
import org.bouncycastle.bcpg.UserIDPacket;
import org.bouncycastle.bcpg.X25519PublicBCPGKey;
import org.bouncycastle.bcpg.X448PublicBCPGKey;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Pack;
Expand Down Expand Up @@ -98,6 +104,14 @@ else if (key instanceof ECPublicBCPGKey)
{
this.keyStrength = 256;
}
else if (curveOID.equals(EdECObjectIdentifiers.id_X448))
{
this.keyStrength = X448PublicBCPGKey.LENGTH * 8;
}
else if (curveOID.equals(EdECObjectIdentifiers.id_Ed448))
{
this.keyStrength = Ed448PublicBCPGKey.LENGTH * 8;
}
else
{
X9ECParametersHolder ecParameters = ECNamedCurveTable.getByOIDLazy(curveOID);
Expand All @@ -112,6 +126,26 @@ else if (key instanceof ECPublicBCPGKey)
}
}
}
else if (key instanceof X25519PublicBCPGKey)
{
this.keyStrength = X25519PublicBCPGKey.LENGTH * 8;
}
else if (key instanceof Ed25519PublicBCPGKey)
{
this.keyStrength = Ed25519PublicBCPGKey.LENGTH * 8;
}
else if (key instanceof X448PublicBCPGKey)
{
this.keyStrength = X448PublicBCPGKey.LENGTH * 8;
}
else if (key instanceof Ed448PublicBCPGKey)
{
this.keyStrength = Ed448PublicBCPGKey.LENGTH * 8;
}
else if (key instanceof UnknownBCPGKey)
{
this.keyStrength = key.getEncoded().length * 8;
}
}
}

Expand Down

0 comments on commit aa95529

Please sign in to comment.