@@ -875,10 +875,11 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
875
875
// ! \param inString the input byte buffer
876
876
// ! \param inLength the size of the input byte buffer, in bytes
877
877
// ! \returns the number of bytes used in outString
878
- // ! ProcessLastBlock is used when the last block of data is special and the
879
- // ! cipher text may expand larger than input data length. The current implementation provides
880
- // ! an output buffer with a size <tt>inLength+2*MandatoryBlockSize()</tt>. This member function
881
- // ! is used by CBC-CTS and OCB modes.
878
+ // ! \details ProcessLastBlock is used when the last block of data is special and requires handling
879
+ // ! by the cipher. The current implementation provides an output buffer with a size
880
+ // ! <tt>inLength+2*MandatoryBlockSize()</tt>. The return value allows the cipher to expand cipher text
881
+ // ! during encryption or shrink plain text during decryption.
882
+ // ! \details This member function is used by CBC-CTS and OCB modes.
882
883
// ! \sa IsLastBlockSpecial
883
884
virtual size_t ProcessLastBlock (byte *outString, size_t outLength, const byte *inString, size_t inLength);
884
885
@@ -891,15 +892,34 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
891
892
// ! \brief Determines if the last block receives special processing
892
893
// ! \returns true if the last block reveives special processing, false otherwise.
893
894
// ! \details Some authenticated encryption modes have needs that are not expressed well
894
- // ! with MandatoryBlockSize() and MinLastBlockSize(). When IsLastBlockSpecial() returns
895
- // ! true three things happen. First, standard block cipher padding is not applied.
896
- // ! Second, the ProcessLastBlock() is used that provides inString and outString lengths.
897
- // ! Third, outString is larger than inString by <tt>2*MandatoryBlockSize()</tt>. That is,
898
- // ! there's a reserve available when processing the last block.
895
+ // ! with MandatoryBlockSize() and MinLastBlockSize(). For example, AES/OCB uses
896
+ // ! 16-byte blocks (MandatoryBlockSize = 16) and the last block requires special processing
897
+ // ! (MinLastBlockSize = 0). However, 0 is a valid last block size for OCB and the special
898
+ // ! processing is custom padding, and not standard PKCS padding. In response an
899
+ // ! unambiguous IsLastBlockSpecial() was added.
900
+ // ! \details When IsLastBlockSpecial() returns false nothing special happens. All the former
901
+ // ! rules and behaviors apply. This is the default behavior of IsLastBlockSpecial().
902
+ // ! \details When IsLastBlockSpecial() returns true four things happen. First, MinLastBlockSize = 0
903
+ // ! means 0 is a valid block size that should be processed. Second, standard block cipher padding is
904
+ // ! \a not \a applied. Third, the caller supplies an outString is larger than inString by
905
+ // ! <tt>2*MandatoryBlockSize()</tt>. That is, there's a reserve available when processing the last block.
906
+ // ! Fourth, the cipher is responsible for finalization like custom padding. The cipher will tell
907
+ // ! the library how many bytes were processed or used by returning the appropriate value from
908
+ // ! ProcessLastBlock().
899
909
// ! \details The return value of ProcessLastBlock() indicates how many bytes were written
900
- // ! to outString. A filter driving data will send <tt>outString</tt> and <tt>outLength</tt>
901
- // ! to an <tt>AttachedTransformation()</tt> for additional processing.
910
+ // ! to outString. A filter pipelining data will send <tt>outString</tt> and up to <tt>outLength</tt>
911
+ // ! to an <tt>AttachedTransformation()</tt> for additional processing. Below is an example of the code
912
+ // ! used in <tt>StreamTransformationFilter::LastPut</tt>.
913
+ // ! <pre> if (m_cipher.IsLastBlockSpecial())
914
+ // ! {
915
+ // ! size_t reserve = 2*m_cipher.MandatoryBlockSize();
916
+ // ! space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, length, length+reserve);
917
+ // ! length = m_cipher.ProcessLastBlock(space, length+reserve, inString, length);
918
+ // ! AttachedTransformation()->Put(space, length);
919
+ // ! return;
920
+ // ! }</pre>
902
921
// ! \sa ProcessLastBlock
922
+ // ! \since Crypto++ 6.0
903
923
virtual bool IsLastBlockSpecial () const {return false ;}
904
924
905
925
// ! \brief Encrypt or decrypt a string of bytes
0 commit comments