From 0214b67982bfbba8184057f8423bd69b50c6dd3f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 3 May 2012 07:23:37 +0000 Subject: The cipher base class does nice buffering now based on the blocksize. This means that you can write odd numbers of bytes or read odd numbers of bytes from/to the ciphers and it'll just buffer until it gets a full block. Next up is adding padding support. Right now it doesn't flush the buffers with padding if you don't fill the last block. For that matter, it doesn't do any padding at all. --- src/experimental/cipher.h | 87 ++++++++++++++++++++++++++++++----------------- src/tests/blowfish.cpp | 26 ++++++++++++++ 2 files changed, 81 insertions(+), 32 deletions(-) diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h index 9e6f87d..6e1fa69 100644 --- a/src/experimental/cipher.h +++ b/src/experimental/cipher.h @@ -2,6 +2,7 @@ #define BU_CIPHER_H #include "bu/filter.h" +#include "bu/util.h" namespace Bu { @@ -10,7 +11,10 @@ namespace Bu { public: Cipher( Bu::Stream &rNext ) : - Bu::Filter( rNext ) + Bu::Filter( rNext ), + iReadBufFill( 0 ), + iReadBufPos( 0 ), + iWriteBufFill( 0 ) { } @@ -29,47 +33,59 @@ namespace Bu virtual Bu::size read( void *pBuf, Bu::size iBytes ) { - uint32_t i; - - if (iBytes%iBlockSize) - { - return 0; - } - - iBytes /= iBlockSize; - - for (i=0;i