pytropicsquare
 
Loading...
Searching...
No Matches
tropicsquare.TropicSquare Class Reference
Inheritance diagram for tropicsquare.TropicSquare:
tropicsquare.ports.micropython.TropicSquareMicroPython

Public Member Functions

 __init__ (self)
 
bytes certificate (self)
 
bytes public_key (self)
 
bytes chipid (self)
 
tuple riscv_fw_version (self)
 
tuple spect_fw_version (self)
 
 fw_bank (self)
 
bool start_secure_session (self, int pkey_index, bytes shpriv, bytes shpub)
 
bool abort_secure_session (self)
 
str get_log (self)
 
bytes ping (self, bytes data)
 L3 Commands #.
 
bytes get_random (self, int nbytes)
 
 get_serial_code (self)
 
 r_config_read (self, address)
 
 i_config_read (self, address)
 
bytes mem_data_read (self, int slot)
 
bool mem_data_write (self, bytes data, int slot)
 
bool mem_data_erase (self, int slot)
 
bool ecc_key_generate (self, int slot, int curve)
 
bytes ecc_key_store (self, int slot, int curve, bytes key)
 
tuple ecc_key_read (self, int slot)
 
bool ecc_key_erase (self, int slot)
 
tuple ecdsa_sign (self, int slot, bytes hash)
 
tuple eddsa_sign (self, int slot, bytes message)
 
bool mcounter_init (self, int index, int value)
 
bool mcounter_update (self, int index)
 
int mcounter_get (self, int index)
 
 mac_and_destroy (self, slot, data)
 

Public Attributes

 public_key
 

Protected Member Functions

 _l2_get_response (self)
 
 _l2_get_info_req (self, object_id, req_data_chunk=GET_INFO_DATA_CHUNK_0_127)
 
 _l2_handshake_req (self, ehpub, p_keyslot)
 
 _l2_get_log (self)
 
 _l2_encrypted_command (self, command_size, command_ciphertext, command_tag)
 
 _l2_encrypted_session_abt (self)
 
 _l2_sleep_req (self, sleep_mode)
 
 _l2_startup_req (self, startup_id)
 
 _call_command (self, data)
 
 _spi_cs (self, value)
 
 _spi_write (self, data)
 
bytes _spi_read (self, int len)
 
 _spi_readinto (self, bytearray buffer)
 
 _spi_write_readinto (self, tx_buffer, bytearray rx_buffer)
 
 _get_ephemeral_keypair (self)
 
 _hkdf (self, salt, shared_secret, length)
 
 _x25519_exchange (self, private_bytes, public_bytes)
 
 _aesgcm (self, key)
 

Protected Attributes

 _secure_session
 
 _certificate
 

Constructor & Destructor Documentation

◆ __init__()

tropicsquare.TropicSquare.__init__ (   self)

Member Function Documentation

◆ _aesgcm()

tropicsquare.TropicSquare._aesgcm (   self,
  key 
)
protected

◆ _call_command()

tropicsquare.TropicSquare._call_command (   self,
  data 
)
protected

◆ _get_ephemeral_keypair()

tropicsquare.TropicSquare._get_ephemeral_keypair (   self)
protected

◆ _hkdf()

tropicsquare.TropicSquare._hkdf (   self,
  salt,
  shared_secret,
  length 
)
protected

◆ _l2_encrypted_command()

tropicsquare.TropicSquare._l2_encrypted_command (   self,
  command_size,
  command_ciphertext,
  command_tag 
)
protected

◆ _l2_encrypted_session_abt()

tropicsquare.TropicSquare._l2_encrypted_session_abt (   self)
protected

◆ _l2_get_info_req()

tropicsquare.TropicSquare._l2_get_info_req (   self,
  object_id,
  req_data_chunk = GET_INFO_DATA_CHUNK_0_127 
)
protected

◆ _l2_get_log()

tropicsquare.TropicSquare._l2_get_log (   self)
protected

◆ _l2_get_response()

tropicsquare.TropicSquare._l2_get_response (   self)
protected

◆ _l2_handshake_req()

tropicsquare.TropicSquare._l2_handshake_req (   self,
  ehpub,
  p_keyslot 
)
protected

◆ _l2_sleep_req()

tropicsquare.TropicSquare._l2_sleep_req (   self,
  sleep_mode 
)
protected

◆ _l2_startup_req()

tropicsquare.TropicSquare._l2_startup_req (   self,
  startup_id 
)
protected

◆ _spi_cs()

tropicsquare.TropicSquare._spi_cs (   self,
  value 
)
protected

◆ _spi_read()

bytes tropicsquare.TropicSquare._spi_read (   self,
int  len 
)
protected

◆ _spi_readinto()

tropicsquare.TropicSquare._spi_readinto (   self,
bytearray  buffer 
)
protected

◆ _spi_write()

tropicsquare.TropicSquare._spi_write (   self,
  data 
)
protected

◆ _spi_write_readinto()

tropicsquare.TropicSquare._spi_write_readinto (   self,
  tx_buffer,
bytearray  rx_buffer 
)
protected

◆ _x25519_exchange()

tropicsquare.TropicSquare._x25519_exchange (   self,
  private_bytes,
  public_bytes 
)
protected

◆ abort_secure_session()

bool tropicsquare.TropicSquare.abort_secure_session (   self)
Abort secure session

Returns:
    bool: True if secure session was aborted

◆ certificate()

bytes tropicsquare.TropicSquare.certificate (   self)
Get X509 certificate from the chip

Returns:
    bytes: X509 certificate

◆ chipid()

bytes tropicsquare.TropicSquare.chipid (   self)

◆ ecc_key_erase()

bool tropicsquare.TropicSquare.ecc_key_erase (   self,
int  slot 
)
Erase ECC key

Args:
    slot (int): Slot for key

Returns:
    bool: True if key was erased

Raises:
    ValueError: If slot is larger than ECC_MAX_KEYS

◆ ecc_key_generate()

bool tropicsquare.TropicSquare.ecc_key_generate (   self,
int  slot,
int  curve 
)
Generate ECC key

Args:
    slot (int): Slot for key
    curve (int): Curve (ECC_CURVE_P256 or ECC_CURVE_ED25519)

Returns:
    bool: True if key was generated

Raises:
    ValueError: If slot is larger than ECC_MAX_KEYS or curve is invalid

◆ ecc_key_read()

tuple tropicsquare.TropicSquare.ecc_key_read (   self,
int  slot 
)
Read ECC key

Args:
    slot (int): Slot for key

Returns:
    tuple: Curve, origin, public key

Raises:
    ValueError: If slot is larger than ECC_MAX_KEYS

◆ ecc_key_store()

bytes tropicsquare.TropicSquare.ecc_key_store (   self,
int  slot,
int  curve,
bytes  key 
)
Store own ECC key

Args:
    slot (int): Slot for key
    curve (int): Curve (ECC_CURVE_P256 or ECC_CURVE_ED25519)
    key (bytes): Private key

Returns:
    bool: True if key was stored

Raises:
    ValueError: If slot is larger than ECC_MAX_KEYS or curve is invalid

◆ ecdsa_sign()

tuple tropicsquare.TropicSquare.ecdsa_sign (   self,
int  slot,
bytes  hash 
)
Sign hash with ECC key

Args:
    slot (int): Slot with ECC key (ECC_CURVE_P256)
    hash (bytes): Hash to sign

Returns:
    tuple: R and S values of the signature

◆ eddsa_sign()

tuple tropicsquare.TropicSquare.eddsa_sign (   self,
int  slot,
bytes  message 
)
Sign message with ECC key

Args:
    slot (int): Slot with ECC key (ECC_CURVE_ED25519)
    message (bytes): Message

Returns:
    tuple: R and S values of the signature

◆ fw_bank()

tropicsquare.TropicSquare.fw_bank (   self)

◆ get_log()

str tropicsquare.TropicSquare.get_log (   self)
Get log from the RISC Firmware

Returns:
    str: Log message

◆ get_random()

bytes tropicsquare.TropicSquare.get_random (   self,
int  nbytes 
)
Get random bytes

Args:
    nbytes (int): Number of bytes to generate

Returns:
    bytes: Random bytes

◆ get_serial_code()

tropicsquare.TropicSquare.get_serial_code (   self)

◆ i_config_read()

tropicsquare.TropicSquare.i_config_read (   self,
  address 
)

◆ mac_and_destroy()

tropicsquare.TropicSquare.mac_and_destroy (   self,
  slot,
  data 
)

◆ mcounter_get()

int tropicsquare.TropicSquare.mcounter_get (   self,
int  index 
)
Get monotonic counter value

Args:
    index (int): Counter index

Returns:
    int: Counter value

◆ mcounter_init()

bool tropicsquare.TropicSquare.mcounter_init (   self,
int  index,
int  value 
)
Initialize monotonic counter

Args:
    index (int): Counter index
    value (int): Initial value

Returns:
    bool: True if counter was initialized

◆ mcounter_update()

bool tropicsquare.TropicSquare.mcounter_update (   self,
int  index 
)
Decrement monotonic counter

Args:
    index (int): Counter index

Returns:
    bool: True if counter was updated

◆ mem_data_erase()

bool tropicsquare.TropicSquare.mem_data_erase (   self,
int  slot 
)
Erase memory slot

Args:
    slot (int): Memory slot

Returns:
    bool: True if data was erased

◆ mem_data_read()

bytes tropicsquare.TropicSquare.mem_data_read (   self,
int  slot 
)
Read data from memory slot

Args:
    slot (int): Memory slot

Returns:
    bytes: Data from memory slot

◆ mem_data_write()

bool tropicsquare.TropicSquare.mem_data_write (   self,
bytes  data,
int  slot 
)
Write data to memory slot

Args:
    data (bytes): Data to write (Maximum 444 bytes)
    slot (int): Memory slot

Returns:
    bool: True if data was written

Raises:
    ValueError: If data size is larger than 444

◆ ping()

bytes tropicsquare.TropicSquare.ping (   self,
bytes  data 
)

L3 Commands #.

Returns data back

Args:
    data (bytes): Data to send

Returns:
    bytes: Data from input

◆ public_key()

bytes tropicsquare.TropicSquare.public_key (   self)
Get public key from the X509 certificate

In case certificate is not loaded before, it will load also certificate

Returns:
    bytes: Public key

◆ r_config_read()

tropicsquare.TropicSquare.r_config_read (   self,
  address 
)

◆ riscv_fw_version()

tuple tropicsquare.TropicSquare.riscv_fw_version (   self)
Get RISCV firmware version

Returns:
    tuple: Firmware version (major, minor, patch, release)

◆ spect_fw_version()

tuple tropicsquare.TropicSquare.spect_fw_version (   self)
Get SPECT firmware version

Returns:
    tuple: Firmware version (major, minor, patch, release)

◆ start_secure_session()

bool tropicsquare.TropicSquare.start_secure_session (   self,
int  pkey_index,
bytes  shpriv,
bytes  shpub 
)
Initialize secure session for L3 commands

Args:
    phkey_index (int): Pairing key index
    shpriv (bytes): Pairing private key
    shpub (bytes): Pairing public key

Returns:
    bool: True if secure session was established

Raises:
    TropicSquareError: If secure session handshake failed

Member Data Documentation

◆ _certificate

tropicsquare.TropicSquare._certificate
protected

◆ _secure_session

tropicsquare.TropicSquare._secure_session
protected

◆ public_key

tropicsquare.TropicSquare.public_key

The documentation for this class was generated from the following file: