From 03e8c5ad314252cde58c53688c70b9f836a1d5b4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 28 Nov 2012 17:39:09 +0000 Subject: More comments; moved the encryption system to unstable. --- src/experimental/blowfish.cpp | 13 - src/experimental/blowfish.h | 476 ------------------------------------- src/experimental/cipher.cpp | 10 - src/experimental/cipher.h | 127 ---------- src/experimental/ciphermodecbc.cpp | 2 - src/experimental/ciphermodecbc.h | 54 ----- src/experimental/ciphermodecfb.cpp | 2 - src/experimental/ciphermodecfb.h | 53 ----- src/experimental/ciphermodeecb.cpp | 1 - src/experimental/ciphermodeecb.h | 32 --- src/experimental/ciphermodeofb.cpp | 2 - src/experimental/ciphermodeofb.h | 56 ----- 12 files changed, 828 deletions(-) delete mode 100644 src/experimental/blowfish.cpp delete mode 100644 src/experimental/blowfish.h delete mode 100644 src/experimental/cipher.cpp delete mode 100644 src/experimental/cipher.h delete mode 100644 src/experimental/ciphermodecbc.cpp delete mode 100644 src/experimental/ciphermodecbc.h delete mode 100644 src/experimental/ciphermodecfb.cpp delete mode 100644 src/experimental/ciphermodecfb.h delete mode 100644 src/experimental/ciphermodeecb.cpp delete mode 100644 src/experimental/ciphermodeecb.h delete mode 100644 src/experimental/ciphermodeofb.cpp delete mode 100644 src/experimental/ciphermodeofb.h (limited to 'src/experimental') diff --git a/src/experimental/blowfish.cpp b/src/experimental/blowfish.cpp deleted file mode 100644 index 3da32a9..0000000 --- a/src/experimental/blowfish.cpp +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/blowfish.h" - -template class Bu::CipherModeEcb<8, Bu::Blowfish<1> >; -template class Bu::CipherModeCfb<8, Bu::Blowfish<1> >; -template class Bu::CipherModeCbc<8, Bu::Blowfish<1> >; -template class Bu::CipherModeOfb<8, Bu::Blowfish<1> >; diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h deleted file mode 100644 index b287bd4..0000000 --- a/src/experimental/blowfish.h +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_BLOWFISH_H -#define BU_BLOWFISH_H - -#include "bu/config.h" -#include "bu/cipher.h" - -#include "bu/ciphermodeecb.h" -#include "bu/ciphermodecfb.h" -#include "bu/ciphermodecbc.h" -#include "bu/ciphermodeofb.h" - -#define NUM_SUBKEYS 18 -#define NUM_S_BOXES 4 -#define NUM_ENTRIES 256 - -#define MAX_STRING 256 -#define MAX_PASSWD 56 // 448bits -#define F(x) \ - (((SB[0][x.byte.zero] + SB[1][x.byte.one]) ^ SB[2][x.byte.two]) + \ - SB[3][x.byte.three]) -#define revBytes( x ) x = (((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24)) - -namespace Bu -{ - template - class Blowfish : public Bu::Cipher<8> - { - public: - Blowfish( Bu::Stream &rNext ) : - Bu::Cipher<8>( rNext ) - { - } - - virtual ~Blowfish() - { - stop(); - reset(); - } - - void setPassword( const Bu::String &sPass ) - { - reset(); - - uint32_t i,j,len=sPass.getSize(); - Word Work,null0,null1; - - if (len > 0) - { - j = 0; - for (i=0;iword0, &w2 = dwWork->word1; - - w1.word = be32toh( w1.word ); - w2.word = be32toh( w2.word ); - - keyEncipher( w1, w2 ); - - revBytes( w1.word ); - revBytes( w2.word ); - } - - virtual void decipher( void *pData ) - { - DWord *dwWork = (DWord *)pData; - Word &w1 = dwWork->word0, &w2 = dwWork->word1; - - revBytes( w1.word ); - revBytes( w2.word ); - - w1.word ^= PA[17]; - w2.word ^= F(w1)^PA[16]; w1.word ^= F(w2)^PA[15]; - w2.word ^= F(w1)^PA[14]; w1.word ^= F(w2)^PA[13]; - w2.word ^= F(w1)^PA[12]; w1.word ^= F(w2)^PA[11]; - w2.word ^= F(w1)^PA[10]; w1.word ^= F(w2)^PA[9]; - w2.word ^= F(w1)^PA[8]; w1.word ^= F(w2)^PA[7]; - w2.word ^= F(w1)^PA[6]; w1.word ^= F(w2)^PA[5]; - w2.word ^= F(w1)^PA[4]; w1.word ^= F(w2)^PA[3]; - w2.word ^= F(w1)^PA[2]; w1.word ^= F(w2)^PA[1]; - w2.word ^= PA[0]; - - Bu::swap( w1, w2 ); - - w1.word = htobe32( w1.word ); - w2.word = htobe32( w2.word ); - } - - inline void keyEncipher( Word &w1, Word &w2 ) - { - w1.word ^= PA[0]; - w2.word ^= F(w1)^PA[1]; w1.word ^= F(w2)^PA[2]; - w2.word ^= F(w1)^PA[3]; w1.word ^= F(w2)^PA[4]; - w2.word ^= F(w1)^PA[5]; w1.word ^= F(w2)^PA[6]; - w2.word ^= F(w1)^PA[7]; w1.word ^= F(w2)^PA[8]; - w2.word ^= F(w1)^PA[9]; w1.word ^= F(w2)^PA[10]; - w2.word ^= F(w1)^PA[11]; w1.word ^= F(w2)^PA[12]; - w2.word ^= F(w1)^PA[13]; w1.word ^= F(w2)^PA[14]; - w2.word ^= F(w1)^PA[15]; w1.word ^= F(w2)^PA[16]; - w2.word ^= PA[17]; - - Bu::swap( w1, w2 ); - } - }; - - typedef CipherModeEcb<8, Blowfish<1> > BlowfishEcb; - typedef CipherModeCfb<8, Blowfish<1> > BlowfishCfb; - typedef CipherModeCbc<8, Blowfish<1> > BlowfishCbc; - typedef CipherModeOfb<8, Blowfish<1> > BlowfishOfb; -}; - -#endif diff --git a/src/experimental/cipher.cpp b/src/experimental/cipher.cpp deleted file mode 100644 index e1ed0e5..0000000 --- a/src/experimental/cipher.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/cipher.h" - - diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h deleted file mode 100644 index 6e58613..0000000 --- a/src/experimental/cipher.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_CIPHER_H -#define BU_CIPHER_H - -#include "bu/filter.h" -#include "bu/util.h" - -namespace Bu -{ - template - class Cipher : public Bu::Filter - { - public: - Cipher( Bu::Stream &rNext ) : - Bu::Filter( rNext ), - iReadBufFill( 0 ), - iReadBufPos( 0 ), - iWriteBufFill( 0 ) - { - } - - virtual ~Cipher() - { - } - - virtual void start() - { - } - - virtual Bu::size stop() - { - flush(); - return 0; - } - - virtual Bu::size read( void *pBuf, Bu::size iBytes ) - { - Bu::size iRead = 0; - while( iRead < iBytes ) - { - if( iReadBufFill < iBlockSize ) - { - int iR = rNext.read( - aReadBuf+iReadBufFill, - iBlockSize-iReadBufFill - ); - if( iR == 0 ) - return iRead; - - iReadBufFill += iR; - - if( iReadBufFill == iBlockSize ) - decipher( aReadBuf ); - } - - if( iReadBufFill == iBlockSize ) - { - int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); - memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); - iRead += iCpy; - iReadBufPos += iCpy; - if( iReadBufPos == iBlockSize ) - { - iReadBufPos = iReadBufFill = 0; - } - } - } - - return iRead; - } - - virtual Bu::size write( const void *pBuf, Bu::size iBytes ) - { - Bu::size iPos = 0; - - while( iPos < iBytes ) - { - int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill); - memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); - iPos += iLeft; - iWriteBufFill += iLeft; - if( iWriteBufFill == iBlockSize ) - { - encipher( aWriteBuf ); - rNext.write( aWriteBuf, iBlockSize ); - iWriteBufFill = 0; - } - } - - return iPos; - } - - virtual void flush() - { - if( iWriteBufFill > 0 && iWriteBufFill < iBlockSize ) - { - memset( aWriteBuf+iWriteBufFill, 0, iBlockSize-iWriteBufFill ); - encipher( aWriteBuf ); - rNext.write( aWriteBuf, iBlockSize ); - iWriteBufFill = 0; - } - rNext.flush(); - } - - using Bu::Stream::read; - using Bu::Stream::write; - - protected: - virtual void encipher( void *pData )=0; - virtual void decipher( void *pData )=0; - - private: - char aReadBuf[iBlockSize]; - char aWriteBuf[iBlockSize]; - int iReadBufFill; - int iReadBufPos; - int iWriteBufFill; - }; -}; - -#endif diff --git a/src/experimental/ciphermodecbc.cpp b/src/experimental/ciphermodecbc.cpp deleted file mode 100644 index 169c1d3..0000000 --- a/src/experimental/ciphermodecbc.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "ciphermodecbc.h" - diff --git a/src/experimental/ciphermodecbc.h b/src/experimental/ciphermodecbc.h deleted file mode 100644 index b06a972..0000000 --- a/src/experimental/ciphermodecbc.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef BU_MODE_CBC_H -#define BU_MODE_CBC_H - -#include "bu/filter.h" -#include "bu/string.h" - -namespace Bu -{ - template - class CipherModeCbc : public CipherType - { - public: - CipherModeCbc(class Stream &rNext ) : - CipherType( rNext ), - bStart( true ) - { - memset( aVector, 0, iBlockSize ); - } - - virtual ~CipherModeCbc() - { - } - - void setIv( const Bu::String &sIv ) - { - memcpy( aVector, sIv.getStr(), iBlockSize ); - } - - protected: - void decipher( void *pBuf ) - { - uint8_t aTmp[iBlockSize]; - memcpy( aTmp, pBuf, iBlockSize ); - CipherType::decipher( pBuf ); - for( int j = 0; j < iBlockSize; j++ ) - ((uint8_t *)pBuf)[j] ^= aVector[j]; - memcpy( aVector, aTmp, iBlockSize ); - } - - void encipher( void *pBuf ) - { - for( int j = 0; j < iBlockSize; j++ ) - ((uint8_t *)pBuf)[j] ^= aVector[j]; - CipherType::encipher( pBuf ); - memcpy( aVector, pBuf, iBlockSize ); - } - - private: - bool bStart; - uint8_t aVector[iBlockSize]; - }; -}; - -#endif diff --git a/src/experimental/ciphermodecfb.cpp b/src/experimental/ciphermodecfb.cpp deleted file mode 100644 index 271d371..0000000 --- a/src/experimental/ciphermodecfb.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "ciphermodecfb.h" - diff --git a/src/experimental/ciphermodecfb.h b/src/experimental/ciphermodecfb.h deleted file mode 100644 index 34c682f..0000000 --- a/src/experimental/ciphermodecfb.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef BU_MODE_CFB_H -#define BU_MODE_CFB_H - -#include "bu/filter.h" -#include "bu/string.h" - -namespace Bu -{ - template - class CipherModeCfb : public CipherType - { - public: - CipherModeCfb(class Stream &rNext ) : - CipherType( rNext ), - bStart( true ) - { - memset( aVector, 0, iBlockSize ); - } - - virtual ~CipherModeCfb() - { - } - - void setIv( const Bu::String &sIv ) - { - memcpy( aVector, sIv.getStr(), iBlockSize ); - } - - protected: - void decipher( void *pBuf ) - { - uint8_t aTmp[iBlockSize]; - memcpy( aTmp, pBuf, iBlockSize ); - CipherType::encipher( aVector ); - for( int j = 0; j < iBlockSize; j++ ) - ((uint8_t *)pBuf)[j] ^= aVector[j]; - memcpy( aVector, aTmp, iBlockSize ); - } - - void encipher( void *pBuf ) - { - CipherType::encipher( aVector ); - for( int j = 0; j < iBlockSize; j++ ) - aVector[j] = ((uint8_t *)pBuf)[j] ^= aVector[j]; - } - - private: - bool bStart; - uint8_t aVector[iBlockSize]; - }; -}; - -#endif diff --git a/src/experimental/ciphermodeecb.cpp b/src/experimental/ciphermodeecb.cpp deleted file mode 100644 index 8856304..0000000 --- a/src/experimental/ciphermodeecb.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "ciphermodeecb.h" diff --git a/src/experimental/ciphermodeecb.h b/src/experimental/ciphermodeecb.h deleted file mode 100644 index cac2beb..0000000 --- a/src/experimental/ciphermodeecb.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef BU_MODE_ECB_H -#define BU_MODE_ECB_H - -namespace Bu -{ - template - class CipherModeEcb : public CipherType - { - public: - CipherModeEcb( class Stream &rNext ) : - CipherType( rNext ) - { - } - - virtual ~CipherModeEcb() - { - } - - protected: - virtual void decipher( void *pBuf ) - { - CipherType::decipher( pBuf ); - } - - virtual void encipher( void *pBuf ) - { - CipherType::encipher( pBuf ); - } - }; -}; - -#endif diff --git a/src/experimental/ciphermodeofb.cpp b/src/experimental/ciphermodeofb.cpp deleted file mode 100644 index bebbce2..0000000 --- a/src/experimental/ciphermodeofb.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "ciphermodeofb.h" - diff --git a/src/experimental/ciphermodeofb.h b/src/experimental/ciphermodeofb.h deleted file mode 100644 index e1b5108..0000000 --- a/src/experimental/ciphermodeofb.h +++ /dev/null @@ -1,56 +0,0 @@ -#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