33import java .io .ByteArrayOutputStream ;
44import java .util .Arrays ;
55
6- import org .bouncycastle .crypto .CipherParameters ;
76import org .bouncycastle .crypto .DataLengthException ;
87import org .bouncycastle .crypto .InvalidCipherTextException ;
98import org .bouncycastle .crypto .OutputLengthException ;
@@ -318,7 +317,7 @@ public int processBytes(byte[] input, int inOff, int len, byte[] output, int out
318317
319318 if (inputOff + len - (forEncryption ? 0 : MAC_SIZE ) >= BLOCK_SIZE )
320319 {
321- int mlen = inputOff + len - (forEncryption ? 0 : MAC_SIZE );
320+ int mlen = inputOff + messageLen + len - (forEncryption ? 0 : MAC_SIZE );
322321 int adlen = processAADBytes ();
323322 int nblocks_c = 1 + mlen / BLOCK_SIZE ;
324323 int nblocks_m = ((mlen % BLOCK_SIZE ) != 0 ? nblocks_c : nblocks_c - 1 );
@@ -328,16 +327,17 @@ public int processBytes(byte[] input, int inOff, int len, byte[] output, int out
328327 System .arraycopy (inputMessage , 0 , tempInput , 0 , inputOff );
329328 System .arraycopy (input , inOff , tempInput , inputOff , Math .min (len , tempInput .length - inputOff ));
330329 int rv = processBytes (tempInput , output , outOff , nb_it , nblocks_m , nblocks_c , mlen , nblocks_ad , false );
331- if (rv >= inputOff )
330+ int copyLen = rv - inputOff ;
331+ if (copyLen >= 0 )
332332 {
333- int copyLen = rv - inputOff ;
334333 inputOff = inputOff + len - rv ;
335334 System .arraycopy (input , inOff + copyLen , inputMessage , 0 , inputOff );
336335 }
337336 else
338337 {
339- System .arraycopy (input , inOff + rv , inputMessage , inputOff , len - rv );
340- inputOff += len - rv ;
338+ System .arraycopy (inputMessage , inputOff + copyLen , inputMessage , 0 , -copyLen );
339+ System .arraycopy (input , inOff , inputMessage , -copyLen , len );
340+ inputOff = len - copyLen ;
341341 }
342342 messageLen += rv ;
343343 return rv ;
0 commit comments