aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/ciphermodecfb.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/experimental/ciphermodecfb.h84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/experimental/ciphermodecfb.h b/src/experimental/ciphermodecfb.h
index dab6c2e..34c682f 100644
--- a/src/experimental/ciphermodecfb.h
+++ b/src/experimental/ciphermodecfb.h
@@ -6,48 +6,48 @@
6 6
7namespace Bu 7namespace Bu
8{ 8{
9 template<int iBlockSize, typename CipherType> 9 template<int iBlockSize, typename CipherType>
10 class CipherModeCfb : public CipherType 10 class CipherModeCfb : public CipherType
11 { 11 {
12 public: 12 public:
13 CipherModeCfb(class Stream &rNext ) : 13 CipherModeCfb(class Stream &rNext ) :
14 CipherType( rNext ), 14 CipherType( rNext ),
15 bStart( true ) 15 bStart( true )
16 { 16 {
17 memset( aVector, 0, iBlockSize ); 17 memset( aVector, 0, iBlockSize );
18 } 18 }
19 19
20 virtual ~CipherModeCfb() 20 virtual ~CipherModeCfb()
21 { 21 {
22 } 22 }
23 23
24 void setIv( const Bu::String &sIv ) 24 void setIv( const Bu::String &sIv )
25 { 25 {
26 memcpy( aVector, sIv.getStr(), iBlockSize ); 26 memcpy( aVector, sIv.getStr(), iBlockSize );
27 } 27 }
28 28
29 protected: 29 protected:
30 void decipher( void *pBuf ) 30 void decipher( void *pBuf )
31 { 31 {
32 uint8_t aTmp[iBlockSize]; 32 uint8_t aTmp[iBlockSize];
33 memcpy( aTmp, pBuf, iBlockSize ); 33 memcpy( aTmp, pBuf, iBlockSize );
34 CipherType::encipher( aVector ); 34 CipherType::encipher( aVector );
35 for( int j = 0; j < iBlockSize; j++ ) 35 for( int j = 0; j < iBlockSize; j++ )
36 ((uint8_t *)pBuf)[j] ^= aVector[j]; 36 ((uint8_t *)pBuf)[j] ^= aVector[j];
37 memcpy( aVector, aTmp, iBlockSize ); 37 memcpy( aVector, aTmp, iBlockSize );
38 } 38 }
39 39
40 void encipher( void *pBuf ) 40 void encipher( void *pBuf )
41 { 41 {
42 CipherType::encipher( aVector ); 42 CipherType::encipher( aVector );
43 for( int j = 0; j < iBlockSize; j++ ) 43 for( int j = 0; j < iBlockSize; j++ )
44 aVector[j] = ((uint8_t *)pBuf)[j] ^= aVector[j]; 44 aVector[j] = ((uint8_t *)pBuf)[j] ^= aVector[j];
45 } 45 }
46 46
47 private: 47 private:
48 bool bStart; 48 bool bStart;
49 uint8_t aVector[iBlockSize]; 49 uint8_t aVector[iBlockSize];
50 }; 50 };
51}; 51};
52 52
53#endif 53#endif