{"action":"opened","issue":{"url":"https://api.github.com/repos/Legrandin/pycryptodome/issues/238","repository_url":"https://api.github.com/repos/Legrandin/pycryptodome","labels_url":"https://api.github.com/repos/Legrandin/pycryptodome/issues/238/labels{/name}","comments_url":"https://api.github.com/repos/Legrandin/pycryptodome/issues/238/comments","events_url":"https://api.github.com/repos/Legrandin/pycryptodome/issues/238/events","html_url":"https://github.com/Legrandin/pycryptodome/issues/238","id":380900164,"node_id":"MDU6SXNzdWUzODA5MDAxNjQ=","number":238,"title":"AES-CMAC incorrect result","user":{"login":"windsurfer1122","id":34011197,"node_id":"MDQ6VXNlcjM0MDExMTk3","avatar_url":"https://avatars3.githubusercontent.com/u/34011197?v=4","gravatar_id":"","url":"https://api.github.com/users/windsurfer1122","html_url":"https://github.com/windsurfer1122","followers_url":"https://api.github.com/users/windsurfer1122/followers","following_url":"https://api.github.com/users/windsurfer1122/following{/other_user}","gists_url":"https://api.github.com/users/windsurfer1122/gists{/gist_id}","starred_url":"https://api.github.com/users/windsurfer1122/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windsurfer1122/subscriptions","organizations_url":"https://api.github.com/users/windsurfer1122/orgs","repos_url":"https://api.github.com/users/windsurfer1122/repos","events_url":"https://api.github.com/users/windsurfer1122/events{/privacy}","received_events_url":"https://api.github.com/users/windsurfer1122/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-14T21:44:57Z","updated_at":"2018-11-14T21:44:57Z","closed_at":null,"author_association":"NONE","body":"Tried to verify a message with AES-CMAC.\r\nUsed module [cryptography](https://cryptography.io/en/latest/hazmat/primitives/mac/cmac/) before and wanted to switch to [pycryptodome](https://www.pycryptodome.org/en/latest/src/hash/cmac.html).\r\nBut results do not match.\r\n\r\nDo I miss something here or is this an issue with pycryptodome?\r\n\r\n```\r\nData length in bytes: 128\r\nData: 7f504b4780000001000000c000000008000000c00000000e000000000f1bbeb00000000000000180000000000f1bbcd05550393030302d4243555339383132335f30302d554e434841525445443244534b4d5032000000000000000000000000daf49a4bd188b5c794bda67f32af1331be6ad3aa1ee556fabfdbf8b6b45cbc13\r\nExpected SHA-1: 676c8812462b36d09e5594ef3e0b26551d7f76bd\r\nExpected AES-CMAC: 12701ce27476d6c23f76104ca42fedbc\r\n\r\n>>>>> Test A with cryptography 2.3.1\r\nSHA-1: 676c8812462b36d09e5594ef3e0b26551d7f76bd = Correct\r\nAES-CMAC: 12701ce27476d6c23f76104ca42fedbc = Correct\r\n\r\n>>>>> Test B with pycryptodomex 3.7.0\r\nSHA-1: 676c8812462b36d09e5594ef3e0b26551d7f76bd = Correct\r\nAES-CMAC: e9429f1f589ec53efce0832a7f6603fc = Wrong!!!\r\n```\r\n\r\n```python\r\n#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n### ^^^ see https://www.python.org/dev/peps/pep-0263/\r\n\r\nimport sys\r\n\r\n### Test A with cryptography\r\nimport cryptography.hazmat.backends\r\nimport cryptography.hazmat.primitives.hashes\r\nimport cryptography.hazmat.primitives.cmac\r\nimport cryptography.hazmat.primitives.ciphers.algorithms\r\n\r\n### Test B with pycryptodomex\r\nimport Cryptodome.Hash\r\nimport Cryptodome.Cipher.AES\r\n\r\n\r\nData = bytes.fromhex(\"7f504b4780000001000000c000000008000000c00000000e000000000f1bbeb00000000000000180000000000f1bbcd05550393030302d4243555339383132335f30302d554e434841525445443244534b4d5032000000000000000000000000daf49a4bd188b5c794bda67f32af1331be6ad3aa1ee556fabfdbf8b6b45cbc13\")\r\nKey = bytes.fromhex(\"2e7b71d7c9c9a14ea3221f188828b8f8\")\r\nExpected_SHA1 = bytes.fromhex(\"676c8812462b36d09e5594ef3e0b26551d7f76bd\")\r\nExpected_CMAC = bytes.fromhex(\"12701ce27476d6c23f76104ca42fedbc\")\r\n\r\nprint (\"Data length in bytes:\", len(Data))\r\nprint (\"Data:\", Data.hex())\r\nprint (\"Expected SHA-1:\", Expected_SHA1.hex())\r\nprint (\"Expected AES-CMAC:\", Expected_CMAC.hex())\r\nprint()\r\n\r\n\r\n### Test A with cryptography\r\n### https://cryptography.io/en/latest/hazmat/primitives/mac/cmac/\r\nprint(\">>>>> Test A with cryptography\", cryptography.__version__)\r\nHash_SHA1_A = cryptography.hazmat.primitives.hashes.Hash(cryptography.hazmat.primitives.hashes.SHA1(), backend=cryptography.hazmat.backends.default_backend())\r\nHash_SHA1_A.update(Data)\r\nHash_SHA1_A_Digest = Hash_SHA1_A.copy().finalize()\r\nprint (\"SHA-1:\", Hash_SHA1_A_Digest.hex(), \"=\", \"Correct\" if Hash_SHA1_A_Digest == Expected_SHA1 else \"Wrong!!!\")\r\n\r\nHash_CMAC_A = cryptography.hazmat.primitives.cmac.CMAC(cryptography.hazmat.primitives.ciphers.algorithms.AES(Key), backend=cryptography.hazmat.backends.default_backend())\r\nHash_CMAC_A.update(Data)\r\nHash_CMAC_A_Digest = Hash_CMAC_A.copy().finalize()\r\nprint (\"AES-CMAC:\", Hash_CMAC_A_Digest.hex(), \"=\", \"Correct\" if Hash_CMAC_A_Digest == Expected_CMAC else \"Wrong!!!\")\r\nprint()\r\n\r\n\r\n### Test B with PyCryptodome\r\n### https://www.pycryptodome.org/en/latest/src/hash/cmac.html\r\nprint(\">>>>> Test B with pycryptodomex\", Cryptodome.__version__)\r\nHash_SHA1_B = Cryptodome.Hash.SHA1.new()\r\nHash_SHA1_B.update(Data)\r\nHash_SHA1_B_Digest = Hash_SHA1_B.copy().digest()\r\nprint (\"SHA-1:\", Hash_SHA1_B_Digest.hex(), \"=\", \"Correct\" if Hash_SHA1_B_Digest == Expected_SHA1 else \"Wrong!!!\")\r\n\r\nHash_CMAC_B = Cryptodome.Hash.CMAC.new(Key, ciphermod=Cryptodome.Cipher.AES)\r\nHash_CMAC_B.update(Data)\r\nHash_CMAC_B_Digest = Hash_CMAC_B.copy().digest()\r\nprint (\"AES-CMAC:\", Hash_CMAC_B_Digest.hex(), \"=\", \"Correct\" if Hash_CMAC_B_Digest == Expected_CMAC else \"Wrong!!!\")\r\nprint()\r\n```\r\n"}}
{"actor":{"display_login":"windsurfer1122"}}