Skip to content

Commit abc92b2

Browse files
committed
Updated documentation
1 parent e92eb31 commit abc92b2

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

cryptlib.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,11 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
875875
//! \param inString the input byte buffer
876876
//! \param inLength the size of the input byte buffer, in bytes
877877
//! \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.
882883
//! \sa IsLastBlockSpecial
883884
virtual size_t ProcessLastBlock(byte *outString, size_t outLength, const byte *inString, size_t inLength);
884885

@@ -891,15 +892,34 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
891892
//! \brief Determines if the last block receives special processing
892893
//! \returns true if the last block reveives special processing, false otherwise.
893894
//! \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().
899909
//! \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>
902921
//! \sa ProcessLastBlock
922+
//! \since Crypto++ 6.0
903923
virtual bool IsLastBlockSpecial() const {return false;}
904924

905925
//! \brief Encrypt or decrypt a string of bytes

0 commit comments

Comments
 (0)