Skip to content

Commit 0d93bbf

Browse files
committed
Reintroduce and deprecate old AEAD preferences methods.
1 parent 813419f commit 0d93bbf

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
@@ -149,6 +149,7 @@ else if (flags[StreamUtil.flag_partial])
149149
case PREFERRED_COMP_ALGS:
150150
case PREFERRED_HASH_ALGS:
151151
case PREFERRED_SYM_ALGS:
152+
case PREFERRED_ENCRYPTION_MODES:
152153
return new PreferredAlgorithms(type, isCritical, isLongLength, data);
153154
case PREFERRED_AEAD_ALGORITHMS:
154155
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
@@ -193,11 +193,27 @@ public void setPreferredCompressionAlgorithms(boolean isCritical, int[] algorith
193193

194194
/**
195195
* Specify the preferred AEAD algorithms of this key.
196+
* This method of defining encryption mode preferences was introduced and deprecated in
197+
* draft-koch-openpgp-2015-rfc4880bis for OpenPGP v5 keys.
196198
*
197-
* @param isCritical true if should be treated as critical, false otherwise.
199+
* @param isCritical true, if this packet should be treated as critical, false otherwise.
200+
* @param algorithms array of algorithms in descending preference
201+
* @deprecated use {@link #setPreferredAEADCiphersuites(boolean, PreferredAEADCiphersuites.Combination[])} instead
202+
*/
203+
@Deprecated
204+
public void setPreferredAEADAlgorithms(boolean isCritical, int[] algorithms)
205+
{
206+
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_ENCRYPTION_MODES, isCritical,
207+
algorithms));
208+
}
209+
210+
/**
211+
* Specify the preferred AEAD cipher suites of this key.
212+
*
213+
* @param isCritical true, if this packet should be treated as critical, false otherwise.
198214
* @param algorithms array of algorithms in descending preference
199215
*/
200-
public void setPreferredAEADAlgorithms(boolean isCritical, PreferredAEADCiphersuites.Combination[] algorithms)
216+
public void setPreferredAEADCiphersuites(boolean isCritical, PreferredAEADCiphersuites.Combination[] algorithms)
201217
{
202218
packets.add(new PreferredAEADCiphersuites(isCritical, algorithms));
203219
}

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

+31-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,37 @@ public int[] getPreferredCompressionAlgorithms()
286286
return ((PreferredAlgorithms)p).getPreferences();
287287
}
288288

289-
public PreferredAEADCiphersuites getPreferredAEADAlgorithms()
289+
/**
290+
* Return an array containing the preferred AEAD encryption modes of the key.
291+
* AEAD Encryption modes are defined in {@link org.bouncycastle.bcpg.AEADAlgorithmTags}.
292+
* <br>
293+
* This packet type is defined in draft-koch-openpgp-2015-rfc4880bis.
294+
* Recipients should ignore this packet and assume the recipient to prefer OCB.
295+
*
296+
* @return encryption modes
297+
* @deprecated use {@link #getPreferredAEADCiphersuites()} instead.
298+
*/
299+
@Deprecated
300+
public int[] getPreferredAEADAlgorithms()
301+
{
302+
SignatureSubpacket p = this.getSubpacket(SignatureSubpacketTags.PREFERRED_ENCRYPTION_MODES);
303+
304+
if (p == null)
305+
{
306+
return null;
307+
}
308+
309+
PreferredAlgorithms packet = (PreferredAlgorithms) p;
310+
return packet.getPreferences();
311+
}
312+
313+
/**
314+
* Return an array containing preferred AEAD ciphersuites of the key.
315+
* AEAD cipher suites are pairs of a symmetric algorithm and an AEAD algorithm.
316+
*
317+
* @return AEAD cipher suites
318+
*/
319+
public PreferredAEADCiphersuites getPreferredAEADCiphersuites()
290320
{
291321
SignatureSubpacket p = this.getSubpacket(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
292322

0 commit comments

Comments
 (0)