Skip to content

Commit

Permalink
removed dependency on lightweight classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed May 16, 2020
1 parent 5b9a5bd commit 7124e1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
import org.bouncycastle.bcpg.RSAPublicBCPGKey;
import org.bouncycastle.bcpg.RSASecretBCPGKey;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
import org.bouncycastle.crypto.params.X25519PublicKeyParameters;
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
import org.bouncycastle.jcajce.util.ProviderJcaJceHelper;
Expand All @@ -83,6 +81,9 @@

public class JcaPGPKeyConverter
{
private static final int X25519_KEY_SIZE = 32;
private static final int ED25519_KEY_SIZE = 32;

// We default to these as they are specified as mandatory in RFC 6631.
private static final PGPKdfParameters DEFAULT_KDF_PARAMETERS = new PGPKdfParameters(HashAlgorithmTags.SHA256,
SymmetricKeyAlgorithmTags.AES_128);
Expand Down Expand Up @@ -480,7 +481,7 @@ else if (algorithm == PGPPublicKey.ECDSA)
else if (pubKey.getAlgorithm().regionMatches(true, 0, "ED2", 0, 3))
{
SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded());
byte[] pointEnc = new byte[1 + Ed25519PublicKeyParameters.KEY_SIZE];
byte[] pointEnc = new byte[1 + ED25519_KEY_SIZE];

pointEnc[0] = 0x40;
System.arraycopy(pubInfo.getPublicKeyData().getBytes(), 0, pointEnc, 1, pointEnc.length - 1);
Expand All @@ -490,7 +491,7 @@ else if (pubKey.getAlgorithm().regionMatches(true, 0, "ED2", 0, 3))
else if (pubKey.getAlgorithm().regionMatches(true, 0, "X2", 0, 2))
{
SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded());
byte[] pointEnc = new byte[1 + X25519PublicKeyParameters.KEY_SIZE];
byte[] pointEnc = new byte[1 + X25519_KEY_SIZE];

pointEnc[0] = 0x40;
System.arraycopy(pubInfo.getPublicKeyData().getBytes(), 0, pointEnc, 1, pointEnc.length - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.bouncycastle.bcpg.ECDHPublicBCPGKey;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.crypto.params.X25519PublicKeyParameters;
import org.bouncycastle.jcajce.spec.UserKeyingMaterialSpec;
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
Expand All @@ -43,6 +42,8 @@

public class JcePublicKeyDataDecryptorFactoryBuilder
{
private static final int X25519_KEY_SIZE = 32;

private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
private OperatorHelper contentHelper = new OperatorHelper(new DefaultJcaJceHelper());
private JcaPGPKeyConverter keyConverter = new JcaPGPKeyConverter();
Expand Down Expand Up @@ -180,7 +181,7 @@ private byte[] decryptSessionData(JcaPGPKeyConverter converter, PGPPrivateKey pr
KeyFactory keyFact = helper.createKeyFactory("XDH");

// skip the 0x40 header byte.
if (pEnc.length != (1 + X25519PublicKeyParameters.KEY_SIZE) || 0x40 != pEnc[0])
if (pEnc.length != (1 + X25519_KEY_SIZE) || 0x40 != pEnc[0])
{
throw new IllegalArgumentException("Invalid Curve25519 public key");
}
Expand Down

0 comments on commit 7124e1f

Please sign in to comment.