add EdDSA support
This commit is contained in:
@@ -209,6 +209,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
mPrivateKey = mSecretKey.extractPrivateKey(keyDecryptor);
|
||||
mPrivateKeyState = PRIVATE_KEY_STATE_UNLOCKED;
|
||||
} catch (PGPException e) {
|
||||
Log.e(Constants.TAG, "Error extracting private key!", e);
|
||||
return false;
|
||||
}
|
||||
if (mPrivateKey == null) {
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.bouncycastle.bcpg.S2K;
|
||||
import org.bouncycastle.bcpg.sig.Features;
|
||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||
import org.bouncycastle.bcpg.sig.RevocationReasonTags;
|
||||
import org.bouncycastle.jcajce.provider.asymmetric.eddsa.spec.EdDSAGenParameterSpec;
|
||||
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyFlags;
|
||||
@@ -174,7 +175,7 @@ public class PgpKeyOperation {
|
||||
log.add(LogType.MSG_CR_ERROR_NO_CURVE, indent);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
} else if (add.getAlgorithm() != Algorithm.EDDSA) {
|
||||
if (add.getKeySize() == null) {
|
||||
log.add(LogType.MSG_CR_ERROR_NO_KEYSIZE, indent);
|
||||
return null;
|
||||
@@ -241,6 +242,21 @@ public class PgpKeyOperation {
|
||||
break;
|
||||
}
|
||||
|
||||
case EDDSA: {
|
||||
if ((add.getFlags() & (PGPKeyFlags.CAN_ENCRYPT_COMMS | PGPKeyFlags.CAN_ENCRYPT_STORAGE)) > 0) {
|
||||
log.add(LogType.MSG_CR_ERROR_FLAGS_ECDSA, indent);
|
||||
return null;
|
||||
}
|
||||
progress(R.string.progress_generating_eddsa, 30);
|
||||
EdDSAGenParameterSpec edParamSpec =
|
||||
new EdDSAGenParameterSpec("ed25519");
|
||||
keyGen = KeyPairGenerator.getInstance("EdDSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||
keyGen.initialize(edParamSpec, new SecureRandom());
|
||||
|
||||
algorithm = PGPPublicKey.EDDSA;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECDH: {
|
||||
// make sure there are no sign or certify flags set
|
||||
if ((add.getFlags() & (PGPKeyFlags.CAN_SIGN | PGPKeyFlags.CAN_CERTIFY)) > 0) {
|
||||
|
||||
@@ -174,6 +174,9 @@ public class PgpSecurityConstants {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
case PublicKeyAlgorithmTags.EDDSA: {
|
||||
return null;
|
||||
}
|
||||
// ELGAMAL_GENERAL: deprecated in RFC 4880, use ELGAMAL_ENCRYPT
|
||||
// DIFFIE_HELLMAN: unsure
|
||||
// TODO specialize all cases!
|
||||
|
||||
@@ -250,6 +250,7 @@ public class UncachedKeyRing {
|
||||
PublicKeyAlgorithmTags.ECDSA, // 19
|
||||
PublicKeyAlgorithmTags.ELGAMAL_GENERAL, // 20
|
||||
// PublicKeyAlgorithmTags.DIFFIE_HELLMAN, // 21
|
||||
PublicKeyAlgorithmTags.EDDSA, // 22
|
||||
};
|
||||
|
||||
/** "Canonicalizes" a public key, removing inconsistencies in the process.
|
||||
|
||||
@@ -223,7 +223,8 @@ public class UncachedPublicKey {
|
||||
|
||||
public boolean isEC() {
|
||||
return getAlgorithm() == PGPPublicKey.ECDH
|
||||
|| getAlgorithm() == PGPPublicKey.ECDSA;
|
||||
|| getAlgorithm() == PGPPublicKey.ECDSA
|
||||
|| getAlgorithm() == PGPPublicKey.EDDSA;
|
||||
}
|
||||
|
||||
public byte[] getFingerprint() {
|
||||
|
||||
Reference in New Issue
Block a user