Skip to content

Commit

Permalink
Call cipher.SetKey() before cipher.BlockSize() (Issue 408)
Browse files Browse the repository at this point in the history
Variable block size ciphers need the key set before they can return an accurate size for BlockSize(). This issue surfaced during Kalyna testing with authenticated encryption modes. In particular, EAX mode, which effectively uses CMAC:

    AlgorithmParameters params = MakeParameters(Name::BlockSize(), 64)
        (Name::IV(), ConstByteArrayParameter((const byte *)iv, 64));

    EAX<Kalyna>::Encryption kalyna;
    kalyna.SetKey(key, 64, params);
  • Loading branch information
noloader committed May 13, 2017
1 parent 0611e11 commit e226523
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmac.cpp
Expand Up @@ -43,9 +43,9 @@ static void MulU(byte *k, unsigned int length)
void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
BlockCipher &cipher = AccessCipher();
unsigned int blockSize = cipher.BlockSize();

cipher.SetKey(key, length, params);

unsigned int blockSize = cipher.BlockSize();
m_reg.CleanNew(3*blockSize);
m_counter = 0;

Expand Down

1 comment on commit e226523

@noloader
Copy link
Collaborator Author

@noloader noloader commented on e226523 May 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to this commit, the result was:

$ ./test.exe
*** Error in `./test.exe': free(): invalid next size (fast): 0x0000000000e7a570 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x791fb)[0x7f236847d1fb]
/lib64/libc.so.6(+0x8288a)[0x7f236848688a]
/lib64/libc.so.6(cfree+0x4c)[0x7f236848a2bc]
./test.exe[0x407875]
./test.exe[0x40341e]
/lib64/libc.so.6(__libc_start_main+0xf1)[0x7f2368424401]
./test.exe[0x403a7a]
======= Memory map: ========
00400000-00526000 r-xp 00000000 08:02 9047902                            /home/cryptopp/test.exe
00725000-00748000 r--p 00125000 08:02 9047902                            /home/cryptopp/test.exe
00748000-00749000 rw-p 00148000 08:02 9047902                            /home/cryptopp/test.exe

After the commit the result is:

$ ./test.exe
terminate called after throwing an instance of 'CryptoPP::InvalidArgument'
  what():  CMAC: 64 is not a supported cipher block size

We're making progress.

Also see Issue 408.

Please sign in to comment.