-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
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))
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels