AlanQuatermain / aqtoolkit

A toolkit consisting of a bunch of generally useful routines and extensions I wrote when putting together other projects.
http://blog.alanquatermain.net/code
BSD 3-Clause "New" or "Revised" License
785 stars 149 forks source link

Fix key length function has a bug #17

Open ucheema opened 12 years ago

ucheema commented 12 years ago

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;
rckoenes commented 11 years ago

Guess this also goes for the kCCAlgorithmCAST

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

    break;
}