AlanQuatermain/aqtoolkit

Fix key length function has a bug

ucheema opened this issue · 1 comments

if you try decrypting with a 16 byte key it converts the keylength to 24 bytes

the following function should be changed to add <= for 16 and 24 byte comparisons

static void FixKeyLengths( CCAlgorithm algorithm, NSMutableData * keyData, NSMutableData * ivData )
{
NSUInteger keyLength = [keyData length];
switch ( algorithm )
{
case kCCAlgorithmAES128:
{
if ( keyLength <= 16 )
{
[keyData setLength: 16];
}
else if ( keyLength <= 24 )
{
[keyData setLength: 24];
}
else
{
[keyData setLength: 32];
}

        break;

Guess this also goes for the kCCAlgorithmCAST

case kCCAlgorithmCAST:
{
    if ( keyLength <= 5 )
    {
        [keyData setLength: 5];
    }
    else if ( keyLength > 16 )
    {
        [keyData setLength: 16];
    }

    break;
}