aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/ciphermodeofb.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/ciphermodeofb.h')
-rw-r--r--src/experimental/ciphermodeofb.h90
1 files changed, 45 insertions, 45 deletions
diff --git a/src/experimental/ciphermodeofb.h b/src/experimental/ciphermodeofb.h
index 8c2aa20..e1b5108 100644
--- a/src/experimental/ciphermodeofb.h
+++ b/src/experimental/ciphermodeofb.h
@@ -6,51 +6,51 @@
6 6
7namespace Bu 7namespace Bu
8{ 8{
9 template<int iBlockSize, typename CipherType> 9 template<int iBlockSize, typename CipherType>
10 class CipherModeOfb : public CipherType 10 class CipherModeOfb : public CipherType
11 { 11 {
12 public: 12 public:
13 CipherModeOfb(class Stream &rNext ) : 13 CipherModeOfb(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 ~CipherModeOfb() 20 virtual ~CipherModeOfb()
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 CipherType::encipher( aVector ); 32 CipherType::encipher( aVector );
33 uint8_t aTmp[iBlockSize]; 33 uint8_t aTmp[iBlockSize];
34 memcpy( aTmp, aVector, iBlockSize ); 34 memcpy( aTmp, aVector, iBlockSize );
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 uint8_t aTmp[iBlockSize]; 43 uint8_t aTmp[iBlockSize];
44 memcpy( aTmp, aVector, iBlockSize ); 44 memcpy( aTmp, aVector, iBlockSize );
45 for( int j = 0; j < iBlockSize; j++ ) 45 for( int j = 0; j < iBlockSize; j++ )
46 ((uint8_t *)pBuf)[j] ^= aVector[j]; 46 ((uint8_t *)pBuf)[j] ^= aVector[j];
47 memcpy( aVector, aTmp, iBlockSize ); 47 memcpy( aVector, aTmp, iBlockSize );
48 } 48 }
49 49
50 private: 50 private:
51 bool bStart; 51 bool bStart;
52 uint8_t aVector[iBlockSize]; 52 uint8_t aVector[iBlockSize];
53 }; 53 };
54}; 54};
55 55
56#endif 56#endif