blatann.gap.smp_crypto module

blatann.gap.smp_crypto.lesc_pubkey_to_raw(public_key, little_endian=True)

Converts from a python public key to the raw (x, y) bytes for the nordic

Return type

bytearray

blatann.gap.smp_crypto.lesc_privkey_to_raw(private_key, little_endian=True)
Return type

bytearray

blatann.gap.smp_crypto.lesc_pubkey_from_raw(raw_key, little_endian=True)

Converts from raw (x, y) bytes to a public key that can be used for the DH request

Return type

EllipticCurvePublicKey

blatann.gap.smp_crypto.lesc_privkey_from_raw(raw_priv_key, raw_pub_key, little_endian=True)
Return type

EllipticCurvePrivateKey

blatann.gap.smp_crypto.lesc_generate_private_key()

Generates a new private key that can be used for LESC pairing

Return type

EllipticCurvePrivateKey

Returns

The generated private key

blatann.gap.smp_crypto.lesc_compute_dh_key(private_key, peer_public_key, little_endian=False)

Computes the DH key for LESC pairing given our private key and the peer’s public key

Parameters
  • private_key (EllipticCurvePrivateKey) – Our private key

  • peer_public_key (EllipticCurvePublicKey) – The peer’s public key

  • little_endian – whether or not to return the shared secret in little endian

Return type

bytes

Returns

The shared secret

blatann.gap.smp_crypto.ble_ah(key, p_rand)

Function for calculating the ah() hash function described in Bluetooth core specification 4.2 section 3.H.2.2.2.

This is used for resolving private addresses where a private address is prand[3] || aes-128(irk, prand[3]) % 2^24

Parameters
  • key (bytes) – the IRK to use, in big endian format

  • p_rand (bytes) – The random component, first 3 bytes of the address

Return type

bytes

Returns

The last 3 bytes of the encrypted hash

blatann.gap.smp_crypto.private_address_resolves(peer_addr, irk)

Checks if the given peer address can be resolved with the IRK

Private Resolvable Peer Addresses are in the format [4x:xx:xx:yy:yy:yy], where 4x:xx:xx is a random number hashed with the IRK to generate yy:yy:yy This function checks if the random number portion hashed with the IRK equals the hashed part of the address

Parameters
  • peer_addr (PeerAddress) – The peer address to check

  • irk (bytes) – The identity resolve key to try

Return type

bool

Returns

True if it resolves, False if not