mirror of
https://github.com/vgough/encfs.git
synced 2024-11-23 00:13:20 +01:00
parent
8bda1c8a46
commit
87fac6af57
@ -206,11 +206,17 @@ ssize_t MACFileIO::readOneBlock( const IORequest &req ) const
|
|||||||
uint64_t mac = cipher->MAC_64( tmp.data + macBytes,
|
uint64_t mac = cipher->MAC_64( tmp.data + macBytes,
|
||||||
readSize - macBytes, key );
|
readSize - macBytes, key );
|
||||||
|
|
||||||
|
// Constant time comparision to prevent timing attacks
|
||||||
|
unsigned char fail = 0;
|
||||||
for(int i=0; i<macBytes; ++i, mac >>= 8)
|
for(int i=0; i<macBytes; ++i, mac >>= 8)
|
||||||
{
|
{
|
||||||
int test = mac & 0xff;
|
int test = mac & 0xff;
|
||||||
int stored = tmp.data[i];
|
int stored = tmp.data[i];
|
||||||
if(test != stored)
|
|
||||||
|
fail |= (test ^ stored);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( fail > 0 )
|
||||||
{
|
{
|
||||||
// uh oh..
|
// uh oh..
|
||||||
long blockNum = req.offset / bs;
|
long blockNum = req.offset / bs;
|
||||||
@ -222,8 +228,6 @@ ssize_t MACFileIO::readOneBlock( const IORequest &req ) const
|
|||||||
throw ERROR(
|
throw ERROR(
|
||||||
_("MAC comparison failure, refusing to read"));
|
_("MAC comparison failure, refusing to read"));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user