Skip to content

Commit 61c67ab

Browse files
committed
Add ed25519x25519Key(), ed448x448Key() factory methods
1 parent 5db2d69 commit 61c67ab

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPV6KeyGenerator.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,46 @@ public PGPSecretKeyRing classicKey(String userId, char[] passphrase)
159159
.addEncryptionSubkey()
160160
.build(passphrase);
161161
}
162+
162163
/**
163-
* Generate a sign-only OpenPGP key.
164-
* The key consists of a single, user-id-less Ed25519 key, which is capable of signing and certifying.
165-
* It carries a single direct-key signature with signing-related preferences.
164+
* Generate an OpenPGP key consisting of an Ed25519 certify-only primary key,
165+
* a dedicated Ed25519 sign-only subkey and dedicated X25519 encryption-only subkey.
166+
* The key will carry the provided user-id and be protected using the provided passphrase.
166167
*
167-
* @return sign-only (+certify) OpenPGP key
168+
* @param userId user id
169+
* @param passphrase nullable passphrase
170+
* @return OpenPGP key
168171
* @throws PGPException if the key cannot be generated
169172
*/
170-
public PGPSecretKeyRing signOnlyKey()
173+
public PGPSecretKeyRing ed25519x25519Key(String userId, char[] passphrase)
171174
throws PGPException
172175
{
173-
return signOnlyKey(null);
176+
return withPrimaryKey(PGPKeyPairGenerator::generateEd25519KeyPair)
177+
.addSigningSubkey(PGPKeyPairGenerator::generateEd25519KeyPair)
178+
.addEncryptionSubkey(PGPKeyPairGenerator::generateX25519KeyPair)
179+
.addUserId(userId)
180+
.build(passphrase);
181+
}
182+
183+
184+
/**
185+
* Generate an OpenPGP key consisting of an Ed448 certify-only primary key,
186+
* a dedicated Ed448 sign-only subkey and dedicated X448 encryption-only subkey.
187+
* The key will carry the provided user-id and be protected using the provided passphrase.
188+
*
189+
* @param userId user id
190+
* @param passphrase nullable passphrase
191+
* @return OpenPGP key
192+
* @throws PGPException if the key cannot be generated
193+
*/
194+
public PGPSecretKeyRing ed448x448Key(String userId, char[] passphrase)
195+
throws PGPException
196+
{
197+
return withPrimaryKey(PGPKeyPairGenerator::generateEd448KeyPair)
198+
.addSigningSubkey(PGPKeyPairGenerator::generateEd448KeyPair)
199+
.addEncryptionSubkey(PGPKeyPairGenerator::generateX448KeyPair)
200+
.addUserId(userId)
201+
.build(passphrase);
174202
}
175203

176204
/**
@@ -257,7 +285,14 @@ public PGPSecretKeyRing signOnlyKey(
257285
public WithPrimaryKey withPrimaryKey()
258286
throws PGPException
259287
{
260-
return withPrimaryKey(null);
288+
return withPrimaryKey((SignatureSubpacketsFunction) null);
289+
}
290+
291+
public WithPrimaryKey withPrimaryKey(
292+
KeyPairGeneratorCallback keyGenCallback)
293+
throws PGPException
294+
{
295+
return withPrimaryKey(keyGenCallback, null);
261296
}
262297

263298
/**

0 commit comments

Comments
 (0)