Skip to content

Commit f57f167

Browse files
committed
Reintroduce and deprecate old AEAD preferences methods.
1 parent d8b63ec commit f57f167

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ else if (l == 255)
165165
case PREFERRED_COMP_ALGS:
166166
case PREFERRED_HASH_ALGS:
167167
case PREFERRED_SYM_ALGS:
168+
case PREFERRED_ENCRYPTION_MODES:
168169
return new PreferredAlgorithms(type, isCritical, isLongLength, data);
169170
case PREFERRED_AEAD_ALGORITHMS:
170171
return new PreferredAEADCiphersuites(isCritical, isLongLength, data);

pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketTags.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public interface SignatureSubpacketTags
3030
int SIGNATURE_TARGET = 31; // signature target
3131
int EMBEDDED_SIGNATURE = 32; // embedded signature
3232
int ISSUER_FINGERPRINT = 33; // issuer key fingerprint
33-
// public static final int PREFERRED_AEAD_ALGORITHMS = 34; // RESERVED since crypto-refresh-05
34-
int INTENDED_RECIPIENT_FINGERPRINT = 35; // intended recipient fingerprint
33+
int PREFERRED_ENCRYPTION_MODES = 34; // draft-koch-openpgp-2015-rfc4880bis defines this packet for AEAD algorithms
34+
int INTENDED_RECIPIENT_FINGERPRINT = 35; // intended recipient fingerprint
3535
int ATTESTED_CERTIFICATIONS = 37; // attested certifications (RESERVED)
3636
int KEY_BLOCK = 38; // Key Block (RESERVED)
3737
int PREFERRED_AEAD_ALGORITHMS = 39; // preferred AEAD algorithms

pg/src/main/java/org/bouncycastle/openpgp/PGPSignatureSubpacketGenerator.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,27 @@ public void setPreferredCompressionAlgorithms(boolean isCritical, int[] algorith
184184

185185
/**
186186
* Specify the preferred AEAD algorithms of this key.
187+
* This method of defining encryption mode preferences was introduced and deprecated in
188+
* draft-koch-openpgp-2015-rfc4880bis for OpenPGP v5 keys.
187189
*
188-
* @param isCritical true if should be treated as critical, false otherwise.
190+
* @param isCritical true, if this packet should be treated as critical, false otherwise.
191+
* @param algorithms array of algorithms in descending preference
192+
* @deprecated use {@link #setPreferredAEADCiphersuites(boolean, PreferredAEADCiphersuites.Combination[])} instead
193+
*/
194+
@Deprecated
195+
public void setPreferredAEADAlgorithms(boolean isCritical, int[] algorithms)
196+
{
197+
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_ENCRYPTION_MODES, isCritical,
198+
algorithms));
199+
}
200+
201+
/**
202+
* Specify the preferred AEAD cipher suites of this key.
203+
*
204+
* @param isCritical true, if this packet should be treated as critical, false otherwise.
189205
* @param algorithms array of algorithms in descending preference
190206
*/
191-
public void setPreferredAEADAlgorithms(boolean isCritical, PreferredAEADCiphersuites.Combination[] algorithms)
207+
public void setPreferredAEADCiphersuites(boolean isCritical, PreferredAEADCiphersuites.Combination[] algorithms)
192208
{
193209
packets.add(new PreferredAEADCiphersuites(isCritical, algorithms));
194210
}

pg/src/main/java/org/bouncycastle/openpgp/PGPSignatureSubpacketVector.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,37 @@ public int[] getPreferredCompressionAlgorithms()
258258
return ((PreferredAlgorithms)p).getPreferences();
259259
}
260260

261-
public PreferredAEADCiphersuites getPreferredAEADAlgorithms()
261+
/**
262+
* Return an array containing the preferred AEAD encryption modes of the key.
263+
* AEAD Encryption modes are defined in {@link org.bouncycastle.bcpg.AEADAlgorithmTags}.
264+
* <br>
265+
* This packet type is defined in draft-koch-openpgp-2015-rfc4880bis.
266+
* Recipients should ignore this packet and assume the recipient to prefer OCB.
267+
*
268+
* @return encryption modes
269+
* @deprecated use {@link #getPreferredAEADCiphersuites()} instead.
270+
*/
271+
@Deprecated
272+
public int[] getPreferredAEADAlgorithms()
273+
{
274+
SignatureSubpacket p = this.getSubpacket(SignatureSubpacketTags.PREFERRED_ENCRYPTION_MODES);
275+
276+
if (p == null)
277+
{
278+
return null;
279+
}
280+
281+
PreferredAlgorithms packet = (PreferredAlgorithms) p;
282+
return packet.getPreferences();
283+
}
284+
285+
/**
286+
* Return an array containing preferred AEAD ciphersuites of the key.
287+
* AEAD cipher suites are pairs of a symmetric algorithm and an AEAD algorithm.
288+
*
289+
* @return AEAD cipher suites
290+
*/
291+
public PreferredAEADCiphersuites getPreferredAEADCiphersuites()
262292
{
263293
SignatureSubpacket p = this.getSubpacket(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
264294

0 commit comments

Comments
 (0)