Skip to content

Instantly share code, notes, and snippets.

@michpappas
Created April 13, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michpappas/07f0e7275d45b8dbcadb890b2f056cb0 to your computer and use it in GitHub Desktop.
Save michpappas/07f0e7275d45b8dbcadb890b2f056cb0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import hashlib
# Using mode = 0x06, ie:
# Bit 7 = 0: MBZ
# Bit 6 = 0: SN[2:3], SN[4:7] set to zero
# Bit 5 = 0: OTP[0:7] set to zero
# Bit 4 = 0: OTP[0:10] set to zero
# Bit 3 = 0: MBZ
# Bit 2 = 1: Value of TempKey.SourceFlag = Input
# Bit 1 = 1: First 32 bytes filled with value in TempKey
# Bit 0 = 0: Second 32 bytes filled with value in challenge
mac_in = [
# 32 bytes: TempKey[0:31]
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
# 32 bytes: Challenge[0:31]
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
# 1 byte: Opcode
0x08,
# 1 byte: Mode
0x06,
# 2 bytes: Param2[LSB], Param2[MSB]
0x00, 0x00,
# 8 bytes: OTP[0:7] or zeros
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
# 3 bytes OTP[8:10] or zeros
0x00, 0x00, 0x00,
# 1 byte SN[8]
0xee,
# 4 bytes: SN[4:7] or zeros
0x00, 0x00, 0x00, 0x00,
# 2 bytes: SN[0:1]
0x01, 0x23,
# 2 bytes SN[2:3] or zeros
0x00, 0x00
]
print(hashlib.sha256(bytes(mac_in)).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment