Skip to content

Commit

Permalink
deprecated EC in favor of ECDH
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Oct 8, 2015
1 parent 556a28c commit 0ddd7b2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 87 deletions.
Expand Up @@ -10,6 +10,9 @@ public interface PublicKeyAlgorithmTags
public static final int RSA_SIGN = 3; // RSA Sign-Only
public static final int ELGAMAL_ENCRYPT = 16; // Elgamal (Encrypt-Only), see [ELGAMAL]
public static final int DSA = 17; // DSA (Digital Signature Standard)
/**
* @deprecated use ECDH
*/
public static final int EC = 18; // Reserved for Elliptic Curve
public static final int ECDH = 18; // Reserved for Elliptic Curve (actual algorithm name)
public static final int ECDSA = 19; // Reserved for ECDSA
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class PublicKeyPacket
case ELGAMAL_GENERAL:
key = new ElGamalPublicBCPGKey(in);
break;
case EC:
case ECDH:
key = new ECDHPublicBCPGKey(in);
break;
case ECDSA:
Expand Down
76 changes: 1 addition & 75 deletions pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
Expand Up @@ -6,9 +6,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.security.Signature;
import java.util.Date;

import org.bouncycastle.asn1.ASN1InputStream;
Expand All @@ -17,7 +15,6 @@
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.MPInteger;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.util.encoders.Base64;

Expand All @@ -38,7 +35,7 @@ public class PGPUtil
*/
public static String getDefaultProvider()
{
// TODO: This is unused?
// TODO: no longer used.
return defProvider;
}

Expand Down Expand Up @@ -83,77 +80,6 @@ static MPInteger[] dsaSigToMpi(
return values;
}

/**
* Translates a PGP {@link HashAlgorithmTags hash algorithm tag} to a JCA {@link MessageDigest}
* algorithm name
*
* @param hashAlgorithm the hash algorithm identifier.
* @return the corresponding JCA algorithm name.
* @throws PGPException if the hash algorithm is unknown.
*/
static String getDigestName(
int hashAlgorithm)
throws PGPException
{
switch (hashAlgorithm)
{
case HashAlgorithmTags.SHA1:
return "SHA1";
case HashAlgorithmTags.MD2:
return "MD2";
case HashAlgorithmTags.MD5:
return "MD5";
case HashAlgorithmTags.RIPEMD160:
return "RIPEMD160";
case HashAlgorithmTags.SHA256:
return "SHA256";
case HashAlgorithmTags.SHA384:
return "SHA384";
case HashAlgorithmTags.SHA512:
return "SHA512";
case HashAlgorithmTags.SHA224:
return "SHA224";
default:
throw new PGPException("unknown hash algorithm tag in getDigestName: " + hashAlgorithm);
}
}

/**
* Translates a PGP {@link PublicKeyAlgorithmTags public key algorithm tag} and a
* {@link HashAlgorithmTags hash algorithm tag} to a JCA {@link Signature} algorithm name.
*
* @param keyAlgorithm they public key algorithm identifier.
* @param hashAlgorithm the hash algorithm identifier.
* @return the corresponding JCA algorithm name.
* @throws PGPException if the public key or hash algorithm is unknown.
*/
static String getSignatureName(
int keyAlgorithm,
int hashAlgorithm)
throws PGPException
{
String encAlg;

switch (keyAlgorithm)
{
case PublicKeyAlgorithmTags.RSA_GENERAL:
case PublicKeyAlgorithmTags.RSA_SIGN:
encAlg = "RSA";
break;
case PublicKeyAlgorithmTags.DSA:
encAlg = "DSA";
break;
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: // in some malformed cases.
case PublicKeyAlgorithmTags.ELGAMAL_GENERAL:
encAlg = "ElGamal";
break;
default:
throw new PGPException("unknown algorithm tag in signature:" + keyAlgorithm);
}

return getDigestName(hashAlgorithm) + "with" + encAlg;
}

/**
* Generates a random key for a {@link SymmetricKeyAlgorithmTags symmetric encryption algorithm}
* .
Expand Down
Expand Up @@ -35,8 +35,8 @@ public static String getAlgorithm(
return "ELGAMAL_ENCRYPT";
case PublicKeyAlgorithmTags.DSA:
return "DSA";
case PublicKeyAlgorithmTags.EC:
return "EC";
case PublicKeyAlgorithmTags.ECDH:
return "ECDH";
case PublicKeyAlgorithmTags.ECDSA:
return "ECDSA";
case PublicKeyAlgorithmTags.ELGAMAL_GENERAL:
Expand Down
Expand Up @@ -2,7 +2,6 @@

import java.util.Date;

import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.bcpg.BCPGKey;
import org.bouncycastle.bcpg.DSAPublicBCPGKey;
Expand All @@ -19,7 +18,6 @@
import org.bouncycastle.bcpg.RSAPublicBCPGKey;
import org.bouncycastle.bcpg.RSASecretBCPGKey;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.DSAParameters;
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
Expand Down Expand Up @@ -78,7 +76,7 @@ else if (pubKey instanceof ECPublicKeyParameters)
{
ECPublicKeyParameters eK = (ECPublicKeyParameters)pubKey;

if (algorithm == PGPPublicKey.EC)
if (algorithm == PGPPublicKey.ECDH)
{ // TODO: KDF parameters setting
bcpgKey = new ECDHPublicBCPGKey(((ECNamedDomainParameters)eK.getParameters()).getName(), eK.getQ(), HashAlgorithmTags.SHA256, SymmetricKeyAlgorithmTags.AES_128);
}
Expand Down
Expand Up @@ -118,7 +118,7 @@ public PublicKey getPublicKey(PGPPublicKey publicKey)
fact = helper.createKeyFactory("ElGamal");

return fact.generatePublic(elSpec);
case PublicKeyAlgorithmTags.EC:
case PublicKeyAlgorithmTags.ECDH:
ECDHPublicBCPGKey ecdhK = (ECDHPublicBCPGKey)publicPk.getKey();
X9ECParameters ecdhParams = PGPUtil.getX9Parameters(ecdhK.getCurveOID());
ECPoint ecdhPoint = PGPUtil.decodePoint(ecdhK.getEncodedPoint(), ecdhParams.getCurve());
Expand Down Expand Up @@ -201,7 +201,7 @@ else if (pubKey instanceof ECPublicKey)
ASN1OctetString key = new DEROctetString(keyInfo.getPublicKeyData().getBytes());
X9ECPoint derQ = new X9ECPoint(params.getCurve(), key);

if (algorithm == PGPPublicKey.EC)
if (algorithm == PGPPublicKey.ECDH)
{
PGPKdfParameters kdfParams = (PGPKdfParameters)algorithmParameters;
if (kdfParams == null)
Expand Down Expand Up @@ -359,7 +359,7 @@ public PGPPrivateKey getPGPPrivateKey(PGPPublicKey pub, PrivateKey privKey)

privPk = new ElGamalSecretBCPGKey(esK.getX());
break;
case PGPPublicKey.EC:
case PGPPublicKey.ECDH:
case PGPPublicKey.ECDSA:
ECPrivateKey ecK = (ECPrivateKey)privKey;

Expand Down
Expand Up @@ -112,7 +112,7 @@ public PublicKey getPublicKey(PGPPublicKey publicKey)
fact = helper.createKeyFactory("ElGamal");

return fact.generatePublic(elSpec);
case PublicKeyAlgorithmTags.EC:
case PublicKeyAlgorithmTags.ECDH:
ECDHPublicBCPGKey ecdhK = (ECDHPublicBCPGKey)publicPk.getKey();
X9ECParameters ecdhParams = PGPUtil.getX9Parameters(ecdhK.getCurveOID());
ECPoint ecdhPoint = PGPUtil.decodePoint(ecdhK.getEncodedPoint(), ecdhParams.getCurve());
Expand Down Expand Up @@ -195,7 +195,7 @@ else if (pubKey instanceof ECPublicKey)
ASN1OctetString key = new DEROctetString(keyInfo.getPublicKeyData().getBytes());
X9ECPoint derQ = new X9ECPoint(params.getCurve(), key);

if (algorithm == PGPPublicKey.EC)
if (algorithm == PGPPublicKey.ECDH)
{
PGPKdfParameters kdfParams = (PGPKdfParameters)algorithmParameters;
if (kdfParams == null)
Expand Down Expand Up @@ -353,7 +353,7 @@ public PGPPrivateKey getPGPPrivateKey(PGPPublicKey pub, PrivateKey privKey)

privPk = new ElGamalSecretBCPGKey(esK.getX());
break;
case PGPPublicKey.EC:
case PGPPublicKey.ECDH:
case PGPPublicKey.ECDSA:
ECPrivateKey ecK = (ECPrivateKey)privKey;

Expand Down

0 comments on commit 0ddd7b2

Please sign in to comment.