aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/cipher.h
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/cipher.h
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/cipher.h')
-rw-r--r--src/experimental/cipher.h67
1 files changed, 61 insertions, 6 deletions
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;