allow per-block rand bytes to be use independently from block MAC

git-svn-id: http://encfs.googlecode.com/svn/trunk@62 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
Valient Gough 2010-09-06 04:23:22 +00:00
parent 832d3da98b
commit 0d24e66ec9
3 changed files with 39 additions and 41 deletions

View File

@ -80,7 +80,7 @@ FileNode::FileNode(DirNode *parent_, const FSConfigPtr &cfg,
shared_ptr<FileIO> rawIO( new RawFileIO( _cname ) ); shared_ptr<FileIO> rawIO( new RawFileIO( _cname ) );
io = shared_ptr<FileIO>( new CipherFileIO( rawIO, fsConfig )); io = shared_ptr<FileIO>( new CipherFileIO( rawIO, fsConfig ));
if(cfg->config->blockMACBytes) if(cfg->config->blockMACBytes || cfg->config->blockMACRandBytes)
io = shared_ptr<FileIO>(new MACFileIO(io, fsConfig)); io = shared_ptr<FileIO>(new MACFileIO(io, fsConfig));
} }

View File

@ -879,8 +879,9 @@ void selectBlockMAC(int *macBytes, int *macRandBytes)
"within a block will be caught and will cause a read error.")); "within a block will be caught and will cause a read error."));
if(addMAC) if(addMAC)
{
*macBytes = 8; *macBytes = 8;
else
*macBytes = 0;
// xgroup(setup) // xgroup(setup)
cout << _("Add random bytes to each block header?\n" cout << _("Add random bytes to each block header?\n"
@ -903,11 +904,6 @@ void selectBlockMAC(int *macBytes, int *macRandBytes)
randSize = 8; randSize = 8;
*macRandBytes = randSize; *macRandBytes = randSize;
} else
{
*macBytes = 0;
*macRandBytes = 0;
}
} }
static static
@ -1305,7 +1301,7 @@ void showFSInfo( const boost::shared_ptr<EncFSConfig> &config )
cout << autosprintf(_("Salt Size: %i bits"), cout << autosprintf(_("Salt Size: %i bits"),
8*(int)config->salt.size()) << "\n"; 8*(int)config->salt.size()) << "\n";
} }
if(config->blockMACBytes) if(config->blockMACBytes || config->blockMACRandBytes)
{ {
if(config->subVersion < 20040813) if(config->subVersion < 20040813)
{ {

View File

@ -66,7 +66,7 @@ MACFileIO::MACFileIO( const shared_ptr<FileIO> &_base,
, randBytes( cfg->config->blockMACRandBytes ) , randBytes( cfg->config->blockMACRandBytes )
, warnOnly( cfg->opts->forceDecode ) , warnOnly( cfg->opts->forceDecode )
{ {
rAssert( macBytes > 0 && macBytes <= 8 ); rAssert( macBytes >= 0 && macBytes <= 8 );
rAssert( randBytes >= 0 ); rAssert( randBytes >= 0 );
rLog(Info, "fs block size = %i, macBytes = %i, randBytes = %i", rLog(Info, "fs block size = %i, macBytes = %i, randBytes = %i",
cfg->config->blockSize, cfg->config->blockSize,
@ -183,17 +183,16 @@ ssize_t MACFileIO::readOneBlock( const IORequest &req ) const
ssize_t readSize = base->read( tmp ); ssize_t readSize = base->read( tmp );
// don't store zeros if configured for zero-block pass-through // don't store zeros if configured for zero-block pass-through
bool skipBlock; bool skipBlock = true;
if( _allowHoles ) if( _allowHoles )
{ {
skipBlock = true;
for(int i=0; i<readSize; ++i) for(int i=0; i<readSize; ++i)
if(tmp.data[i] != 0) if(tmp.data[i] != 0)
{ {
skipBlock = false; skipBlock = false;
break; break;
} }
} else } else if(macBytes > 0)
skipBlock = false; skipBlock = false;
if(readSize > headerSize) if(readSize > headerSize)
@ -257,12 +256,14 @@ bool MACFileIO::writeOneBlock( const IORequest &req )
memset( newReq.data, 0, headerSize ); memset( newReq.data, 0, headerSize );
memcpy( newReq.data + headerSize, req.data, req.dataLen ); memcpy( newReq.data + headerSize, req.data, req.dataLen );
if(randBytes) if(randBytes > 0)
{ {
if(!cipher->randomize( newReq.data+macBytes, randBytes, false )) if(!cipher->randomize( newReq.data+macBytes, randBytes, false ))
return false; return false;
} }
if(macBytes > 0)
{
// compute the mac (which includes the random data) and fill it in // compute the mac (which includes the random data) and fill it in
uint64_t mac = cipher->MAC_64( newReq.data+macBytes, uint64_t mac = cipher->MAC_64( newReq.data+macBytes,
req.dataLen + randBytes, key ); req.dataLen + randBytes, key );
@ -272,6 +273,7 @@ bool MACFileIO::writeOneBlock( const IORequest &req )
newReq.data[i] = mac & 0xff; newReq.data[i] = mac & 0xff;
mac >>= 8; mac >>= 8;
} }
}
// now, we can let the next level have it.. // now, we can let the next level have it..
bool ok = base->write( newReq ); bool ok = base->write( newReq );