|
| 1 | +ID Unit |
| 2 | +======= |
| 3 | + |
| 4 | +.. include:: ../refs/unit.id.ref |
| 5 | + |
| 6 | +The ``ID Unit`` is a crypto coprocessor with hardware-based secure key storage, integrated with ATECC608B hardware cryptographic chip, using I2C communication interface. The chip has a built-in 10Kb EEPROM for storing keys, certificates, data, consumption records and security configurations. |
| 7 | + |
| 8 | +Support the following products: |
| 9 | + |
| 10 | + |IDUnit| |
| 11 | + |
| 12 | +Micropython Example:: |
| 13 | + |
| 14 | + import os, sys, io |
| 15 | + import M5 |
| 16 | + from M5 import * |
| 17 | + from hardware import * |
| 18 | + from unit import IDUnit |
| 19 | + |
| 20 | + |
| 21 | + i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) |
| 22 | + id_0 = IDUnit(i2c0) |
| 23 | + print(id_0.get_sha256_hash('Hello M5', 1)) |
| 24 | + print(id_0.get_generate_key(0, False)) |
| 25 | + print(id_0.randrange(500, 1000, 5)) |
| 26 | + |
| 27 | +UIFLOW2 Example: |
| 28 | + |
| 29 | + |example.png| |
| 30 | + |
| 31 | +.. only:: builder_html |
| 32 | + |
| 33 | + |cores3_id_example.m5f2| |
| 34 | + |
| 35 | + |
| 36 | +class IDUnit |
| 37 | +------------ |
| 38 | + |
| 39 | +Constructors |
| 40 | +------------ |
| 41 | + |
| 42 | +.. class:: IDUnit(i2c) |
| 43 | + |
| 44 | + Create a IDUnit object |
| 45 | + |
| 46 | + :param object i2c: the I2C object. |
| 47 | + |
| 48 | + UIFLOW2: |
| 49 | + |
| 50 | + |init.png| |
| 51 | + |
| 52 | + |
| 53 | +Methods |
| 54 | +------- |
| 55 | + |
| 56 | +.. method:: IDUnit.get_revision_number() -> int |
| 57 | + |
| 58 | + Returns the ATECC608B revision number. A revision number refers to a version identifier that indicates a specific |
| 59 | + iteration or update of the hardware design. The revision number helps distinguish between different versions of the same chip model. |
| 60 | + |
| 61 | + - Return: ``int``: hexdecimal |
| 62 | + |
| 63 | + UIFLOW2: |
| 64 | + |
| 65 | + |get_revision_number.png| |
| 66 | + |
| 67 | + |
| 68 | +.. method:: IDUnit.get_serial_number() -> str |
| 69 | + |
| 70 | + Returns the ATECC serial number. |
| 71 | + |
| 72 | + 9-byte serial number is structured as follows: |
| 73 | + |
| 74 | + First 4 Bytes: These bytes are the first part of the serial number, which includes a fixed pattern and a portion that is unique to the device. |
| 75 | + Next 2 Bytes: These bytes are reserved and typically set to 0x00 or other reserved values. |
| 76 | + Last 3 Bytes: These bytes are the final part of the serial number and are unique to the device. |
| 77 | + |
| 78 | + - Return: ``string`` |
| 79 | + |
| 80 | + UIFLOW2: |
| 81 | + |
| 82 | + |get_serial_number.png| |
| 83 | + |
| 84 | + |
| 85 | +.. method:: IDUnit.randint(min, max) -> int |
| 86 | + |
| 87 | + Returns the random number(4 byte). generate true random numbers using its hardware-based random number generator(RNG). |
| 88 | + This RNG is often used in secure applications where high-quality randomness is needed, such as in key generation. |
| 89 | + |
| 90 | + :param int min: 0 ~ 4294967295. |
| 91 | + :param int max: 0 ~ 4294967295. |
| 92 | + |
| 93 | + - Return: ``int``: 0 ~ 4294967295 |
| 94 | + |
| 95 | + UIFLOW2: |
| 96 | + |
| 97 | + |randint.png| |
| 98 | + |
| 99 | + |
| 100 | +.. method:: IDUnit.random() -> float |
| 101 | + |
| 102 | + Returns a random floating point number in the range [0.0 ~ 1.0]. |
| 103 | + |
| 104 | + - Return: ``float``: 0.0 ~ 1.0 |
| 105 | + |
| 106 | + UIFLOW2: |
| 107 | + |
| 108 | + |random.png| |
| 109 | + |
| 110 | + |
| 111 | +.. method:: IDUnit.randrange(min, max, step) -> int |
| 112 | + |
| 113 | + The first form returns a random integer from the range(0, max). |
| 114 | + The second form returns a random integer from the range (min, max, step) in steps of step. |
| 115 | + For instance, calling randrange(1, 10, 2) will return odd numbers between 1 and 9 inclusive. |
| 116 | + |
| 117 | + :param int min: 0 ~ 4294967295. |
| 118 | + :param int max: 0 ~ 4294967295. |
| 119 | + :param int step: 0 ~ 4294967295. |
| 120 | + |
| 121 | + - Return: ``int``: 0 ~ 4294967295 |
| 122 | + |
| 123 | + UIFLOW2: |
| 124 | + |
| 125 | + |randrange_max.png| |
| 126 | + |randrange.png| |
| 127 | + |
| 128 | + |
| 129 | +.. method:: IDUnit.uniform(min, max) -> float |
| 130 | + |
| 131 | + Return a random floating point number N such that min <= N <= max for min <= max, and max <= N <= min for max < min. |
| 132 | + |
| 133 | + :param float min: |
| 134 | + :param float max: |
| 135 | + |
| 136 | + - Return: ``float``: |
| 137 | + |
| 138 | + UIFLOW2: |
| 139 | + |
| 140 | + |uniform.png| |
| 141 | + |
| 142 | + |
| 143 | +.. method:: IDUnit.get_generate_key(slot_num, private_key) -> bytearray |
| 144 | + |
| 145 | + Returns the generates a private or public key. A private key is a confidential piece of data that is used in |
| 146 | + cryptography to perform various functions. A public key is a cryptographic key that is paired with a private |
| 147 | + key in public-key cryptography. |
| 148 | + |
| 149 | + :param int slot_num: 0 ~ 4 |
| 150 | + :param bool private_key: True or False |
| 151 | + |
| 152 | + - Return: ``bytearray``: |
| 153 | + |
| 154 | + UIFLOW2: |
| 155 | + |
| 156 | + |get_generate_key.png| |
| 157 | + |
| 158 | + |
| 159 | +.. method:: IDUnit.get_ecdsa_sign(slot, message) -> bytearray |
| 160 | + |
| 161 | + Returns the ECDSA signatures. ECDSA is widely used in digital signatures |
| 162 | + for ensuring the authenticity and integrity of messages and documents. |
| 163 | + |
| 164 | + :param int slot: 0 ~ 4 |
| 165 | + :param message: ``string`` or ``list`` or ``bytearray`` |
| 166 | + |
| 167 | + - Return: ``bytearray``: |
| 168 | + |
| 169 | + UIFLOW2: |
| 170 | + |
| 171 | + |get_ecdsa_sign.png| |
| 172 | + |
| 173 | + |
| 174 | +.. method:: IDUnit.get_verify_ecdsa_sign(message, sign, key) -> bool |
| 175 | + |
| 176 | + Returns the verify ecsda signature status. A signature verification in the Elliptic Curve Digital Signature Algorithm (ECDSA) |
| 177 | + is the process of checking whether a given digital signature is valid and was indeed generated by the holder of the corresponding |
| 178 | + private key or public key. This process ensures that the message or data. |
| 179 | + |
| 180 | + :param message: ``string`` or ``list`` or ``bytearray`` |
| 181 | + :param sign: ``bytearray`` |
| 182 | + :param key: ``bytearray`` |
| 183 | + |
| 184 | + - Return: ``bool``: True or False |
| 185 | + |
| 186 | + UIFLOW2: |
| 187 | + |
| 188 | + |get_verify_ecdsa_sign.png| |
| 189 | + |
| 190 | + |
| 191 | +.. method:: IDUnit.get_sha256_hash(message, format) -> str |
| 192 | + |
| 193 | + Get the generate the SHA-256 hash value. SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash |
| 194 | + function that produces a fixed-size, 256-bit (32-byte) hash value, regardless of the size of the input data. |
| 195 | + |
| 196 | + :param message: ``string`` |
| 197 | + :param format: 0: hexdecimal, 1: base64 |
| 198 | + |
| 199 | + - Return: ``string``: |
| 200 | + |
| 201 | + UIFLOW2: |
| 202 | + |
| 203 | + |get_sha256_hash.png| |
| 204 | + |
| 205 | + |
| 206 | +.. method:: IDUnit.set_certificate_signing_request(slot_num, private_key, country, state_prov, city, org, org_unit, file_path) -> None |
| 207 | + |
| 208 | + A Certificate Signing Request (CSR) is a block of encoded text that is sent to a Certificate Authority (CA) when you apply for |
| 209 | + an SSL/TLS certificate. It contains information that the CA uses to create your certificate, including your public key and some |
| 210 | + information about your organization. |
| 211 | + |
| 212 | + :param int slot_num: 0 ~ 4 |
| 213 | + :param bool private_key: True or False |
| 214 | + :param str country: country name example: China |
| 215 | + :param str state_prov: states or province name |
| 216 | + :param str city: city name |
| 217 | + :param str org: organization or company name |
| 218 | + :param str org_unit: organization or company unit name |
| 219 | + :param str file_path: Store the file to flash or SD |
| 220 | + |
| 221 | + UIFLOW2: |
| 222 | + |
| 223 | + |set_certificate_signing_request.png| |
| 224 | + |
| 225 | + |
0 commit comments