Skip to content

Commit 428bda1

Browse files
committed
Add PGPKeyPairGenerator factory methods for OpenPGP brainpool keys
1 parent 88c6a3a commit 428bda1

2 files changed

Lines changed: 333 additions & 0 deletions

File tree

pg/src/main/java/org/bouncycastle/openpgp/operator/PGPKeyPairGenerator.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
44
import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
5+
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
56
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
67
import org.bouncycastle.openpgp.PGPException;
78
import org.bouncycastle.openpgp.PGPKeyPair;
@@ -183,6 +184,7 @@ public abstract PGPKeyPair generateLegacyX25519KeyPair()
183184

184185
/**
185186
* Generate an ECDH elliptic curve encryption key over the NIST p-256 curve.
187+
* <pre>NIST P-256</pre> is equivalent to <pre>prime256v1</pre> and <pre>secp256r1</pre>.
186188
*
187189
* @return NIST p-256 ECDSA encryption key pair
188190
* @throws PGPException if the key pair cannot be generated
@@ -198,6 +200,7 @@ public PGPKeyPair generateNistP256ECDHKeyPair()
198200

199201
/**
200202
* Generate an ECDH elliptic curve encryption key over the NIST p-384 curve.
203+
* <pre>NIST P-384</pre> is equivalent to <pre>secp384r1</pre>.
201204
*
202205
* @return NIST p-384 ECDSA encryption key pair
203206
* @throws PGPException if the key pair cannot be generated
@@ -213,6 +216,7 @@ public PGPKeyPair generateNistP384ECDHKeyPair()
213216

214217
/**
215218
* Generate an ECDH elliptic curve encryption key over the NIST p-521 curve.
219+
* <pre>NIST P-521</pre> is equivalent to <pre>secp521r1</pre>.
216220
*
217221
* @return NIST p-521 ECDSA encryption key pair
218222
* @throws PGPException if the key pair cannot be generated
@@ -226,8 +230,54 @@ public PGPKeyPair generateNistP521ECDHKeyPair()
226230
return generateECDHKeyPair(SECObjectIdentifiers.secp521r1);
227231
}
228232

233+
/**
234+
* Generate an ECDH elliptic curve encryption key over the brainpoolP256r1 curve.
235+
*
236+
* @return BrainpoolP256r1 ECDH encryption key pair
237+
* @throws PGPException if the key pair cannot be generated
238+
*
239+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
240+
* RFC9580 - ECC Curves for OpenPGP</a>
241+
*/
242+
public PGPKeyPair generateBrainpoolP256r1ECDHKeyPair()
243+
throws PGPException
244+
{
245+
return generateECDHKeyPair(TeleTrusTObjectIdentifiers.brainpoolP256r1);
246+
}
247+
248+
/**
249+
* Generate an ECDH elliptic curve encryption key over the brainpoolP384r1 curve.
250+
*
251+
* @return BrainpoolP384r1 ECDH encryption key pair
252+
* @throws PGPException if the key pair cannot be generated
253+
*
254+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
255+
* RFC9580 - ECC Curves for OpenPGP</a>
256+
*/
257+
public PGPKeyPair generateBrainpoolP384r1ECDHKeyPair()
258+
throws PGPException
259+
{
260+
return generateECDHKeyPair(TeleTrusTObjectIdentifiers.brainpoolP384r1);
261+
}
262+
263+
/**
264+
* Generate an ECDH elliptic curve encryption key over the brainpoolP512r1 curve.
265+
*
266+
* @return BrainpoolP512r1 ECDH encryption key pair
267+
* @throws PGPException if the key pair cannot be generated
268+
*
269+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
270+
* RFC9580 - ECC Curves for OpenPGP</a>
271+
*/
272+
public PGPKeyPair generateBrainpoolP512r1ECDHKeyPair()
273+
throws PGPException
274+
{
275+
return generateECDHKeyPair(TeleTrusTObjectIdentifiers.brainpoolP512r1);
276+
}
277+
229278
/**
230279
* Generate an ECDSA elliptic curve signing key over the NIST p-256 curve.
280+
* <pre>NIST P-256</pre> is equivalent to <pre>prime256v1</pre> and <pre>secp256r1</pre>.
231281
*
232282
* @return NIST p-256 ECDSA signing key pair
233283
* @throws PGPException if the key pair cannot be generated
@@ -243,6 +293,7 @@ public PGPKeyPair generateNistP256ECDSAKeyPair()
243293

244294
/**
245295
* Generate an ECDSA elliptic curve signing key over the NIST p-384 curve.
296+
* <pre>NIST P-384</pre> is equivalent to <pre>secp384r1</pre>.
246297
*
247298
* @return NIST p-384 ECDSA signing key pair
248299
* @throws PGPException if the key pair cannot be generated
@@ -258,6 +309,7 @@ public PGPKeyPair generateNistP384ECDSAKeyPair()
258309

259310
/**
260311
* Generate an ECDSA elliptic curve signing key over the NIST p-521 curve.
312+
* <pre>NIST P-521</pre> is equivalent to <pre>secp521r1</pre>.
261313
*
262314
* @return NIST p-521 ECDSA signing key pair
263315
* @throws PGPException if the key pair cannot be generated
@@ -271,6 +323,51 @@ public PGPKeyPair generateNistP521ECDSAKeyPair()
271323
return generateECDSAKeyPair(SECObjectIdentifiers.secp521r1);
272324
}
273325

326+
/**
327+
* Generate an ECDSA elliptic curve signing key over the brainpoolP256r1 curve.
328+
*
329+
* @return BrainpoolP256r1 ECDSA signing key pair
330+
* @throws PGPException if the key pair cannot be generated
331+
*
332+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
333+
* RFC9580 - ECC Curves for OpenPGP</a>
334+
*/
335+
public PGPKeyPair generateBrainpoolP256r1ECDSAKeyPair()
336+
throws PGPException
337+
{
338+
return generateECDSAKeyPair(TeleTrusTObjectIdentifiers.brainpoolP256r1);
339+
}
340+
341+
/**
342+
* Generate an ECDSA elliptic curve signing key over the brainpoolP384r1 curve.
343+
*
344+
* @return BrainpoolP384r1 ECDSA signing key pair
345+
* @throws PGPException if the key pair cannot be generated
346+
*
347+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
348+
* RFC9580 - ECC Curves for OpenPGP</a>
349+
*/
350+
public PGPKeyPair generateBrainpoolP384r1ECDSAKeyPair()
351+
throws PGPException
352+
{
353+
return generateECDSAKeyPair(TeleTrusTObjectIdentifiers.brainpoolP384r1);
354+
}
355+
356+
/**
357+
* Generate an ECDSA elliptic curve signing key over the brainpoolP512r1 curve.
358+
*
359+
* @return BrainpoolP512r1 ECDSA signing key pair
360+
* @throws PGPException if the key pair cannot be generated
361+
*
362+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-ecc-curves-for-openpgp">
363+
* RFC9580 - ECC Curves for OpenPGP</a>
364+
*/
365+
public PGPKeyPair generateBrainpoolP512r1ECDSAKeyPair()
366+
throws PGPException
367+
{
368+
return generateECDSAKeyPair(TeleTrusTObjectIdentifiers.brainpoolP512r1);
369+
}
370+
274371
/**
275372
* Generate an elliptic curve Diffie-Hellman encryption key pair over the curve identified by the given OID.
276373
*

0 commit comments

Comments
 (0)