Skip to content

Authentication failed #3

@dominikrein

Description

@dominikrein

Hi,

I've got auth failed for my DESFire EV3 with AES encryption, not sure if this code has ever been tested against...
Had success with following changes. There were the wrong initialization vectors used for cbc, as these are always the last encrypted bytes, never the unencrypted.
Furthermore the Cipher-Object has to be initialized again after every use.

DESFire_DEF.py

def Decrypt(self, dataEnc):
        #todo assert on blocksize
        block = self.Cipher.decrypt(bytes(dataEnc))
        return list(bytearray(block))
def Encrypt(self, data):
        #todo assert on blocksize
        block = list(bytearray(self.Cipher.encrypt(bytes(data))))
        return block

DESFire.py

def authenticate(self, key_id, key, challenge = None):
       # [...]
        key.CiperInit()
        RndB = key.Decrypt(RndB_enc)
        key.IV = RndB_enc[-key.CipherBlocksize:]
        key.Cipher = AES.new(bytes(key.keyBytes), AES.MODE_CBC, bytes(key.IV))

       # [...]

        RndAB_enc = key.Encrypt(RndAB)
        key.IV = RndAB_enc[-key.CipherBlocksize:]
        key.Cipher = AES.new(bytes(key.keyBytes), AES.MODE_CBC, bytes(key.IV))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions