aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/cipher.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-04-09 16:29:18 +0000
committerMike Buland <eichlan@xagasoft.com>2012-04-09 16:29:18 +0000
commit228b885b41652a015a91770dfd993456d76ad102 (patch)
tree9a4b0756133fa1b7553f9aacf9ad50e7f26179d8 /src/experimental/cipher.cpp
parentb93f18e1dd303fb648bc350416f7f5ace536fd1f (diff)
downloadlibbu++-228b885b41652a015a91770dfd993456d76ad102.tar.gz
libbu++-228b885b41652a015a91770dfd993456d76ad102.tar.bz2
libbu++-228b885b41652a015a91770dfd993456d76ad102.tar.xz
libbu++-228b885b41652a015a91770dfd993456d76ad102.zip
Blowfish works in it's new split form, which will make it much easier to add
other types of ciphers down the road, should we choose to.
Diffstat (limited to '')
-rw-r--r--src/experimental/cipher.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/experimental/cipher.cpp b/src/experimental/cipher.cpp
new file mode 100644
index 0000000..3430c08
--- /dev/null
+++ b/src/experimental/cipher.cpp
@@ -0,0 +1,65 @@
1#include "bu/cipher.h"
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