From d49fc3aeac4daa65416751f94943b6611ad247d3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 10 Apr 2012 08:32:23 +0000 Subject: Rearranged the Cipher system, and added four modes of operation. It's pretty slick, really, and we actually support four of the most common modes. Blowfish is still a template, but it doesn't really need to be anymore... --- src/experimental/ciphermodeofb.h | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/experimental/ciphermodeofb.h (limited to 'src/experimental/ciphermodeofb.h') diff --git a/src/experimental/ciphermodeofb.h b/src/experimental/ciphermodeofb.h new file mode 100644 index 0000000..8c2aa20 --- /dev/null +++ b/src/experimental/ciphermodeofb.h @@ -0,0 +1,56 @@ +#ifndef BU_MODE_OFB_H +#define BU_MODE_OFB_H + +#include "bu/filter.h" +#include "bu/string.h" + +namespace Bu +{ + template + class CipherModeOfb : public CipherType + { + public: + CipherModeOfb(class Stream &rNext ) : + CipherType( rNext ), + bStart( true ) + { + memset( aVector, 0, iBlockSize ); + } + + virtual ~CipherModeOfb() + { + } + + void setIv( const Bu::String &sIv ) + { + memcpy( aVector, sIv.getStr(), iBlockSize ); + } + + protected: + void decipher( void *pBuf ) + { + CipherType::encipher( aVector ); + uint8_t aTmp[iBlockSize]; + memcpy( aTmp, aVector, iBlockSize ); + for( int j = 0; j < iBlockSize; j++ ) + ((uint8_t *)pBuf)[j] ^= aVector[j]; + memcpy( aVector, aTmp, iBlockSize ); + } + + void encipher( void *pBuf ) + { + CipherType::encipher( aVector ); + uint8_t aTmp[iBlockSize]; + memcpy( aTmp, aVector, iBlockSize ); + for( int j = 0; j < iBlockSize; j++ ) + ((uint8_t *)pBuf)[j] ^= aVector[j]; + memcpy( aVector, aTmp, iBlockSize ); + } + + private: + bool bStart; + uint8_t aVector[iBlockSize]; + }; +}; + +#endif -- cgit v1.2.3