StreamTransformationFilter

From Crypto++ Wiki
Jump to: navigation, search
StreamTransformationFilter
Documentation
#include <cryptopp/filters.h>

A StreamTransformationFilter allows a symmetric cipher to participate in pipelining. The filter also handles details such as padding.

Constructor

StreamTransformationFilter (StreamTransformation &c,
                            BufferedTransformation *attachment=NULL,
                            BlockPaddingScheme padding=DEFAULT_PADDING,
                            bool allowAuthenticatedSymmetricCipher=false)

c is a cipher that inherits from StreamTransformation. Descendents can be found at StreamTransformation Class Reference. For block ciphers, its going to be a mode object like CBC_Mode<T>::Encryption or OFB_Mode<T>::Decryption by way of CipherModeBase. For stream ciphers, its going to be a stream cipher like Salsa20::Encryption or Panama::Decryption.

attachment is a BufferedTransformation, such as another filter or sink. If attachment is NULL, then the StreamTransformationFilter object will internally accumulate the output byte stream.

padding is a padding scheme enumeration. The values of BlockPaddingScheme are NO_PADDING, ZEROS_PADDING, PKCS_PADDING, ONE_AND_ZEROS_PADDING and DEFAULT_PADDING. DEFAULT_PADDING is PKCS_PADDING for block ciphers.

allowAuthenticatedSymmetricCipher should always be false. If you need an authenticated encryption filter, then you should use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter.

Sample

In the example below, CBC_Mode< AES >::Encryption is the StreamTransformation object.

SecByteBlock key[ AES::DEFAULT_KEYLENGTH ];
SecByteBlock iv[ AES::BLOCKSIZE ];
...

// Encryptor
CBC_Mode< AES >::Encryption enc( key, key.size(), iv, iv.size() );

// Encryption
CryptoPP::StringSource ss( plainText, true,
   new CryptoPP::StreamTransformationFilter( enc,
      new CryptoPP::StringSink( cipherText )
   ) // StreamTransformationFilter
); // StringSource

To specify a padding scheme, use the overloaded constructor.

...

// Encryption
CryptoPP::StringSource ss( plainText, true,
   new CryptoPP::StreamTransformationFilter( enc,
      new CryptoPP::StringSink( cipherText ),
      BlockPaddingScheme::NO_PADDING
   ) // StreamTransformationFilter
); // StringSource