Skip to content

Instantly share code, notes, and snippets.

@michpappas
Created April 13, 2018 08:59
Show Gist options
  • Save michpappas/07f0e7275d45b8dbcadb890b2f056cb0 to your computer and use it in GitHub Desktop.
Save michpappas/07f0e7275d45b8dbcadb890b2f056cb0 to your computer and use it in GitHub Desktop.

Revisions

  1. michpappas created this gist Apr 13, 2018.
    45 changes: 45 additions & 0 deletions s96-sha204a_test_mac.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/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())