This command is used to retrieve secure random bytes directly from the chip’s internal True Random Number Generator (TRNG). This command is particularly useful when a host system requires high-entropy randomness for operations such as mnemonic generation, nonces, or secure key creation—without altering any state within the card.
This command does not store, derive, or modify any cryptographic material on the card. It is a read-only operation, offering entropy sourced directly from the hardware.
def gen_random(self, size: Int):
card.gen_random(size: Int)
For example, gen_random(16)
📘 Note
Application Protocol Data Unit (APDU) Components
The following table outlines the components of the Application Protocol Data Unit (APDU).
Field | Description | Value |
CLA | This field specifies the class of the instruction. | 0x80 |
INS | This field specifies the particular command or operation that the smart card or secure element should execute. | 0xD3 |
P1 | First parameter of the instruction that specifies the details about the operation being requested. | random output data size in bytes (between 16 and 64, mod 4) |
P2 | First parameter of the instruction that specifies additional details about the operation being requested. | 0x00 |
Data | Key data | raw data |
Response
The following table outlines the possible responses that you will receive:
Response Code | Description |
0x9000 | Success |
0x6A86 | P1 is invalid |