fix cv25519 encryption key generation

This commit is contained in:
segfault-bilibili
2023-03-18 18:18:48 +08:00
committed by Vincent Breitmoser
parent 3288adf5b2
commit 5f0646b7e9
4 changed files with 20 additions and 5 deletions

View File

@@ -269,9 +269,14 @@ public class PgpKeyOperation {
return null;
}
progress(R.string.progress_generating_ecdh, 30);
ECGenParameterSpec ecParamSpec = getEccParameterSpec(add.getCurve());
keyGen = KeyPairGenerator.getInstance("ECDH", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(ecParamSpec, new SecureRandom());
if (add.getCurve() == Curve.CV25519) {
keyGen = KeyPairGenerator.getInstance("X25519");
keyGen.initialize(255);
} else {
ECGenParameterSpec ecParamSpec = getEccParameterSpec(add.getCurve());
keyGen = KeyPairGenerator.getInstance("ECDH", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(ecParamSpec, new SecureRandom());
}
algorithm = PGPPublicKey.ECDH;
break;

View File

@@ -324,7 +324,7 @@ public abstract class SaveKeyringParcel implements Parcelable {
// All curves defined in the standard
// http://www.bouncycastle.org/wiki/pages/viewpage.action?pageId=362269
public enum Curve {
NIST_P256, NIST_P384, NIST_P521,
NIST_P256, NIST_P384, NIST_P521, CV25519
// these are supported by gpg, but they are not in rfc6637 and not supported by BouncyCastle yet
// (adding support would be trivial though -> JcaPGPKeyConverter.java:190)

View File

@@ -262,6 +262,10 @@ public class AddSubkeyDialogFragment extends DialogFragment {
curve = Curve.NIST_P521;
break;
}
case EDDSA: {
curve = Curve.CV25519;
break;
}
}
// set algorithm
@@ -283,7 +287,11 @@ public class AddSubkeyDialogFragment extends DialogFragment {
break;
}
case EDDSA: {
algorithm = Algorithm.EDDSA;
if(mUsageEncrypt.isChecked()) {
algorithm = Algorithm.ECDH;
} else {
algorithm = Algorithm.EDDSA;
}
}
}

View File

@@ -188,6 +188,8 @@ public class KeyFormattingUtils {
return "NIST P-384";
case NIST_P521:
return "NIST P-521";
case CV25519:
return "Curve25519";
/* see SaveKeyringParcel
case BRAINPOOL_P256: