Skip to content

Commit 658cf6e

Browse files
committed
Add notes about accuracy of output size calculations of AEADBlockCipher and appropriate handling of plaintext output during decryption prior to authentication.
1 parent 79cfae3 commit 658cf6e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

core/src/main/java/org/bouncycastle/crypto/modes/AEADBlockCipher.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
/**
99
* A block cipher mode that includes authenticated encryption with a streaming mode and optional associated data.
10+
* <p/>
11+
* Implementations of this interface may operate in a packet mode (where all input data is buffered and
12+
* processed dugin the call to {@link #doFinal(byte[], int)}), or in a streaming mode (where output data is
13+
* incrementally produced with each call to {@link #processByte(byte, byte[], int)} or
14+
* {@link #processBytes(byte[], int, int, byte[], int)}.
15+
* <br/>This is important to consider during decryption: in a streaming mode, unauthenticated plaintext data
16+
* may be output prior to the call to {@link #doFinal(byte[], int)} that results in an authentication
17+
* failure. The higher level protocol utilising this cipher must ensure the plaintext data is handled
18+
* appropriately until the end of data is reached and the entire ciphertext is authenticated.
1019
* @see org.bouncycastle.crypto.params.AEADParameters
1120
*/
1221
public interface AEADBlockCipher
@@ -101,7 +110,11 @@ public int doFinal(byte[] out, int outOff)
101110
/**
102111
* return the size of the output buffer required for a processBytes
103112
* an input of len bytes.
104-
*
113+
* <p/>
114+
* The returned size may be dependent on the initialisation of this cipher
115+
* and may not be accurate once subsequent input data is processed - this method
116+
* should be invoked immediately prior to input data being processed.
117+
*
105118
* @param len the length of the input.
106119
* @return the space required to accommodate a call to processBytes
107120
* with len bytes of input.
@@ -111,7 +124,12 @@ public int doFinal(byte[] out, int outOff)
111124
/**
112125
* return the size of the output buffer required for a processBytes plus a
113126
* doFinal with an input of len bytes.
114-
*
127+
* <p/>
128+
* The returned size may be dependent on the initialisation of this cipher
129+
* and may not be accurate once subsequent input data is processed - this method
130+
* should be invoked immediately prior to a call to final processing of input data
131+
* and a call to {@link #doFinal(byte[], int)}.
132+
*
115133
* @param len the length of the input.
116134
* @return the space required to accommodate a call to processBytes and doFinal
117135
* with len bytes of input.

0 commit comments

Comments
 (0)