diff options
author | lloyd <[email protected]> | 2014-02-02 17:02:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-02-02 17:02:19 +0000 |
commit | 5492417158c2eca5ba8c3eb3c7370749d125fac4 (patch) | |
tree | 2ac5c2ec5601b99c8caceb2f77b318ec41a37a2d /src | |
parent | 43b79ef586143d93a6843f8e9a34f774103f46b3 (diff) |
Add the CMAC constants for 256 and 512 bit block ciphers
Also add test vectors for Threefish-512 CMAC and EAX, both
generated by the library.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/mac/cmac/cmac.cpp | 34 | ||||
-rw-r--r-- | src/tests/data/aead/eax.vec | 9 | ||||
-rw-r--r-- | src/tests/data/mac/cmac.vec | 9 |
3 files changed, 46 insertions, 6 deletions
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp index 16524faec..b4c9cb129 100644 --- a/src/lib/mac/cmac/cmac.cpp +++ b/src/lib/mac/cmac/cmac.cpp @@ -16,9 +16,7 @@ namespace Botan { */ secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in) { - const byte polynomial = (in.size() == 16) ? 0x87 : 0x1B; - - const byte poly_xor = (in[0] & 0x80) ? polynomial : 0; + const bool top_carry = (in[0] & 0x80); secure_vector<byte> out = in; @@ -30,7 +28,26 @@ secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in) carry = (temp >> 7); } - out[out.size()-1] ^= poly_xor; + if(top_carry) + { + switch(in.size()) + { + case 8: + out[out.size()-1] ^= 0x1B; + break; + case 16: + out[out.size()-1] ^= 0x87; + break; + case 32: + out[out.size()-2] ^= 0x4; + out[out.size()-1] ^= 0x25; + break; + case 64: + out[out.size()-2] ^= 0x1; + out[out.size()-1] ^= 0x25; + break; + } + } return out; } @@ -133,8 +150,13 @@ MessageAuthenticationCode* CMAC::clone() const */ CMAC::CMAC(BlockCipher* cipher) : m_cipher(cipher) { - if(m_cipher->block_size() != 8 && m_cipher->block_size() != 16) - throw Invalid_Argument("CMAC cannot use the cipher " + m_cipher->name()); + if(m_cipher->block_size() != 8 && m_cipher->block_size() != 16 && + m_cipher->block_size() != 32 && m_cipher->block_size() != 64) + { + throw Invalid_Argument("CMAC cannot use the " + + std::to_string(m_cipher->block_size() * 8) + + " bit cipher " + m_cipher->name()); + } m_state.resize(output_length()); m_buffer.resize(output_length()); diff --git a/src/tests/data/aead/eax.vec b/src/tests/data/aead/eax.vec index 90b7e2903..6b6a408a7 100644 --- a/src/tests/data/aead/eax.vec +++ b/src/tests/data/aead/eax.vec @@ -1458,3 +1458,12 @@ Nonce = 000102030405060708090A0B0C0D0E0F AD = 000102030405060708090A0B0C0D0E0F In = 000102030405060708090A0B0C0D0E0F Out = 600FA4149AF252C87B828C780AEFF8BC33D7D11DCDC19936 + +# Threefish vectors generated by us + +[Threefish-512/EAX] +Key = 2E749EE66C1E6A162E749EE66C1E6A162E749EE66C1E6A169315F0C4AF8500EB9315F0C4AF8500EB9315F0C4AF8500EBDADBCE3EE3B8FC50DADB3F8050DAEBDC +Nonce = 000102030405060708090A0B0C0D0E0F +AD = 000102030405060708090A0B0C0D0E0F +In = 000102030405060708090A0B0C0D0E0F +Out = 5E8EEADAB182F96CC0144B722F3383FBFC9F462072B9D82FE49F9AD148DA83F23CE248546FC580FAB0A01E21BCE063FF54FFB5038A3FEDD2296B535936EFDE77E51125C9F4EFC4AE073F5A98921C601F diff --git a/src/tests/data/mac/cmac.vec b/src/tests/data/mac/cmac.vec index 55c476294..3859d6464 100644 --- a/src/tests/data/mac/cmac.vec +++ b/src/tests/data/mac/cmac.vec @@ -145,3 +145,12 @@ Key = 420D2C372E496D403A9F520158FCCDA6D6BCE14E6EAD2B90918B919E5E8621A0 In = 4DD7C1974501D1E454D23C509FE2265BC375CA Out = CB1C20084C5DACB3270F118633DB4F33 +[CMAC(Blowfish)] +Key = 0000000000000000 +In = 0000000000000000000000000000000000000000000000000000000000000000 +Out = CE2A6A95E8C3CAB9 + +[CMAC(Threefish-512)] +Key = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +In = 0000000000000000000000000000000000000000000000000000000000000000 +Out = C07C71A284C7A63023146376F895E83543EA3547A9268861CD00B7AC405AFC34A9EC86A30622D38C7E765521B148AAB5DEDD3AE80496ED56BCCB17B2E3D18009 |