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