aboutsummaryrefslogtreecommitdiff
path: root/src/experimental
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-04-09 16:35:15 +0000
committerMike Buland <eichlan@xagasoft.com>2012-04-09 16:35:15 +0000
commit1e9d8f7a92e43f61e4d9f478f6e8dd5ae206616e (patch)
tree65cb355aa0a99bf4b9ad94ef4525065880e3ecd1 /src/experimental
parent228b885b41652a015a91770dfd993456d76ad102 (diff)
downloadlibbu++-1e9d8f7a92e43f61e4d9f478f6e8dd5ae206616e.tar.gz
libbu++-1e9d8f7a92e43f61e4d9f478f6e8dd5ae206616e.tar.bz2
libbu++-1e9d8f7a92e43f61e4d9f478f6e8dd5ae206616e.tar.xz
libbu++-1e9d8f7a92e43f61e4d9f478f6e8dd5ae206616e.zip
Halfway through crypto-template conversion.
Diffstat (limited to 'src/experimental')
-rw-r--r--src/experimental/blowfish.cpp2
-rw-r--r--src/experimental/blowfish.h2
-rw-r--r--src/experimental/cipher.cpp62
-rw-r--r--src/experimental/cipher.h67
4 files changed, 63 insertions, 70 deletions
diff --git a/src/experimental/blowfish.cpp b/src/experimental/blowfish.cpp
index 797ec73..7f89f0f 100644
--- a/src/experimental/blowfish.cpp
+++ b/src/experimental/blowfish.cpp
@@ -9,7 +9,7 @@ using Bu::sio;
9 SB[3][x.byte.three]) 9 SB[3][x.byte.three])
10 10
11Bu::Blowfish::Blowfish( Bu::Stream &rNext ) : 11Bu::Blowfish::Blowfish( Bu::Stream &rNext ) :
12 Bu::Cipher( rNext ) 12 Bu::Cipher<8>( rNext )
13{ 13{
14} 14}
15 15
diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h
index 4dbd637..c043b12 100644
--- a/src/experimental/blowfish.h
+++ b/src/experimental/blowfish.h
@@ -12,7 +12,7 @@
12 12
13namespace Bu 13namespace Bu
14{ 14{
15 class Blowfish : public Bu::Cipher 15 class Blowfish : public Bu::Cipher<8>
16 { 16 {
17 public: 17 public:
18 Blowfish( Bu::Stream &rNext ); 18 Blowfish( Bu::Stream &rNext );
diff --git a/src/experimental/cipher.cpp b/src/experimental/cipher.cpp
index 3430c08..d6d01c7 100644
--- a/src/experimental/cipher.cpp
+++ b/src/experimental/cipher.cpp
@@ -1,65 +1,3 @@
1#include "bu/cipher.h" 1#include "bu/cipher.h"
2 2
3Bu::Cipher::Cipher( Bu::Stream &rNext ) :
4 Bu::Filter( rNext )
5{
6}
7
8Bu::Cipher::~Cipher()
9{
10}
11
12void Bu::Cipher::start()
13{
14}
15
16Bu::size Bu::Cipher::stop()
17{
18 return 0;
19}
20
21Bu::size Bu::Cipher::read( void *pBuf, Bu::size iBytes )
22{
23 uint32_t i;
24
25 if (iBytes%8)
26 {
27 return 0;
28 }
29
30 iBytes /= 8;
31
32 for (i=0;i<iBytes;i++)
33 {
34 void *pSeg = ((char *)pBuf)+(i*8);
35 int iRead = rNext.read( pSeg, 8 );
36 decipher( pSeg );
37 }
38
39 return iBytes*8;
40}
41
42Bu::size Bu::Cipher::write( const void *pBuf, Bu::size iBytes )
43{
44 uint32_t i;
45
46 if (iBytes%8)
47 {
48 return 0;
49 }
50
51 iBytes /= 8;
52
53 char buf[8];
54
55 for (i=0;i<iBytes;i++)
56 {
57 memcpy( buf, ((const char *)pBuf)+(i*8), 8 );
58 encipher( buf );
59 rNext.write( buf, 8 );
60 }
61
62 memset( &buf, 0, 8 );
63 return iBytes*8;
64}
65 3
diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h
index 2327aa6..613bc88 100644
--- a/src/experimental/cipher.h
+++ b/src/experimental/cipher.h
@@ -5,17 +5,72 @@
5 5
6namespace Bu 6namespace Bu
7{ 7{
8 template<int iBlockSize>
8 class Cipher : Bu::Filter 9 class Cipher : Bu::Filter
9 { 10 {
10 public: 11 public:
11 Cipher( Bu::Stream &rNext ); 12 Cipher( Bu::Stream &rNext ) :
12 virtual ~Cipher(); 13 Bu::Filter( rNext )
14 {
15 }
13 16
14 virtual void start(); 17 virtual ~Cipher()
15 virtual Bu::size stop(); 18 {
19 }
16 20
17 virtual Bu::size read( void *pBuf, Bu::size iBytes ); 21 virtual void start()
18 virtual Bu::size write( const void *pBuf, Bu::size iBytes ); 22 {
23 }
24
25 virtual Bu::size stop()
26 {
27 return 0;
28 }
29
30 virtual Bu::size read( void *pBuf, Bu::size iBytes )
31 {
32 uint32_t i;
33
34 if (iBytes%iBlockSize)
35 {
36 return 0;
37 }
38
39 iBytes /= iBlockSize;
40
41 for (i=0;i<iBytes;i++)
42 {
43 void *pSeg = ((char *)pBuf)+(i*iBlockSize);
44 int iRead = rNext.read( pSeg, iBlockSize );
45 decipher( pSeg );
46 }
47
48 return iBytes*iBlockSize;
49 }
50
51 virtual Bu::size write( const void *pBuf, Bu::size iBytes )
52 {
53 uint32_t i;
54
55 if (iBytes%iBlockSize)
56 {
57 return 0;
58 }
59
60 iBytes /= iBlockSize;
61
62 char buf[iBlockSize];
63
64 for (i=0;i<iBytes;i++)
65 {
66 memcpy( buf, ((const char *)pBuf)+(i*iBlockSize), 8 );
67 encipher( buf );
68 rNext.write( buf, iBlockSize );
69 }
70
71 memset( &buf, 0, iBlockSize );
72 return iBytes*iBlockSize;
73 }
19 74
20 using Bu::Stream::read; 75 using Bu::Stream::read;
21 using Bu::Stream::write; 76 using Bu::Stream::write;