StreamTransformationFilter

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

A StreamTransformationFilter allows a symmetric cipher to participate in pipelining. The filter handles details such as buffering and padding the final block of a block cipher. The StreamTransformationFilter can be used for both block ciphers and stream ciphers, and can be used for both encryption and decryption.

If you are using an authenticated mode of operation, then you should use AuthenticatedEncryptionFilter and AuthenticatedEncryptionFilter instead.

Sources, filters and sinks are discussed at Pipelining. The pipeline article explains the design and shows you how to use them.

Constructor

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

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.

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;
enc.SetKeyWithIV( 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

Downloads

No downloads.