mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-01-01 10:56:27 -05:00
Revise UDI
Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
parent
21fffd3fed
commit
f3c4e6c818
@ -332,7 +332,7 @@ Response to `FW_CMD_GET_UDI`.
|
|||||||
|--------|----------------|-----------------------------------------------------|
|
|--------|----------------|-----------------------------------------------------|
|
||||||
| status | 1 | `STATUS_OK`/`STATUS_BAD` |
|
| status | 1 | `STATUS_OK`/`STATUS_BAD` |
|
||||||
| udi | 4 | Integer (LE) with Reserved (4 bit), Vendor (2 byte),|
|
| udi | 4 | Integer (LE) with Reserved (4 bit), Vendor (2 byte),|
|
||||||
| | | Product (1 byte), Revision (4 bit) |
|
| | | Product ID (6 bit), Product Revision (6 bit) |
|
||||||
| udi | 4 | Integer serial number (LE) |
|
| udi | 4 | Integer serial number (LE) |
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#
|
#
|
||||||
# The tool use HKDF (RFC5869) to generate the UDS.
|
# The tool use HKDF (RFC5869) to generate the UDS.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2022 - Tillitis AB
|
# Copyright (C) 2022, 2023 - Tillitis AB
|
||||||
# SPDX-License-Identifier: GPL-2.0-only
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
#
|
#
|
||||||
#=======================================================================
|
#=======================================================================
|
||||||
@ -20,6 +20,11 @@ from secrets import token_bytes
|
|||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from hkdf import Hkdf
|
from hkdf import Hkdf
|
||||||
|
|
||||||
|
VID_MAX = 2**16 - 1
|
||||||
|
PID_MAX = 2**6 - 1
|
||||||
|
REV_MAX = 2**6 - 1
|
||||||
|
SERIAL_MAX_EXPR = "(2**32-1)"
|
||||||
|
SERIAL_MAX = eval(SERIAL_MAX_EXPR)
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
@ -63,23 +68,23 @@ def gen_udi(verbose, pid, vid, rev, serial):
|
|||||||
print("Generating UDI")
|
print("Generating UDI")
|
||||||
|
|
||||||
if vid == None:
|
if vid == None:
|
||||||
vid = int(input("Enter Vendor ID (0 -- 65535): "))
|
vid = int(input("Enter Vendor ID (0 -- %d): " % VID_MAX))
|
||||||
|
|
||||||
if pid == None:
|
if pid == None:
|
||||||
pid = int(input("Enter Product ID (0 -- 255): "))
|
pid = int(input("Enter Product ID (0 -- %d): " % PID_MAX))
|
||||||
|
|
||||||
if rev == None:
|
if rev == None:
|
||||||
rev = int(input("Enter revision (0 -- 15): "))
|
rev = int(input("Enter Product Revision (0 -- %d): " % REV_MAX))
|
||||||
|
|
||||||
if serial == None:
|
if serial == None:
|
||||||
serial = int(input("Enter serial number (0 -- (2**32 -1)): "))
|
serial = int(input("Enter serial number (0 -- %d %s): " % (SERIAL_MAX, SERIAL_MAX_EXPR)))
|
||||||
|
|
||||||
assert vid < 65536
|
assert vid <= VID_MAX
|
||||||
assert pid < 256
|
assert pid <= PID_MAX
|
||||||
assert rev < 16
|
assert rev <= REV_MAX
|
||||||
assert serial < 2**32
|
assert serial <= SERIAL_MAX
|
||||||
|
|
||||||
udi_hex = ("0%04x%02x%1x%08x" % (vid, pid, rev, serial))
|
udi_hex = "0%04x%03x%08x" % (vid, pid << 6 | rev, serial)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print("\nGenerated UDI:")
|
print("\nGenerated UDI:")
|
||||||
@ -108,10 +113,10 @@ def main():
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-v", "--verbose", help="Verbose operation", action="store_true")
|
parser.add_argument("-v", "--verbose", help="Verbose operation", action="store_true")
|
||||||
parser.add_argument("--ent", help="User supplied entropy", type=str)
|
parser.add_argument("--ent", help="User supplied entropy", type=str)
|
||||||
parser.add_argument("--vid", help="Vendor id (0 -- 65535)", type=int)
|
parser.add_argument("--vid", help="Vendor ID (0 -- %d)" % VID_MAX, type=int)
|
||||||
parser.add_argument("--pid", help="Product id (0 -- 255", type=int)
|
parser.add_argument("--pid", help="Product ID (0 -- %d" % PID_MAX, type=int)
|
||||||
parser.add_argument("--rev", help="Revision number (0 -- 15)", type=int)
|
parser.add_argument("--rev", help="Product Revision (0 -- %d)" % REV_MAX, type=int)
|
||||||
parser.add_argument("--serial", help="Serial number (0 -- (2**31 - 1))", type=int)
|
parser.add_argument("--serial", help="Serial number (0 -- %d %s)" % (SERIAL_MAX, SERIAL_MAX_EXPR), type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
|
Loading…
Reference in New Issue
Block a user