Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 892 of 93612. IoT Connectivity and SecurityFree lesson

Foundations of Asymmetric Key Cryptography

Learners will implement RSA or ECC algorithms to manage secure key exchanges between resource-constrained IoT devices and central servers.

In this lesson, you will learn how to implement RSA and ECC algorithms to facilitate secure, authenticated key exchanges between resource-constrained IoT devices and a central server.

While symmetric cryptography (learned in lesson 23) is fast, it suffers from the "key distribution problem"—you cannot safely share a secret key over an insecure channel without it being intercepted. Asymmetric cryptography solves this by using a mathematically linked pair of keys: a public key, which can be distributed openly to encrypt data or verify signatures, and a private key, which is kept strictly confidential by the device to decrypt data or sign messages.

Selecting the Right Algorithm

For resource-constrained embedded systems, we evaluate algorithms based on CPU cycles and memory footprint:

  1. RSA (Rivest-Shamir-Adleman): Relies on the difficulty of factoring large prime numbers. RSA keys (typically 2048-bit) are computationally expensive and consume significant RAM during modular exponentiation, making them taxing for low-power microcontrollers.
  2. ECC (Elliptic Curve Cryptography): Relies on the algebraic structure of elliptic curves. ECC provides equivalent security to RSA with much smaller key sizes (e.g., a 256-bit ECC key offers comparable security to a 3072-bit RSA key). This results in smaller payloads and significantly lower energy consumption, making it the industry standard for IoT.

Implementing an Ephemeral Key Exchange

In practice, you rarely use asymmetric keys to encrypt bulk data. Instead, you use them to perform a Key Exchange (like ECDH - Elliptic Curve Diffie-Hellman), where the client and server agree on a temporary symmetric session key.

// Conceptual flow for an ECC-based exchange
void perform_key_exchange(void) {
    uint8_t device_priv[32]; // Private key stored in secure element
    uint8_t server_pub[64];  // Public key received via MQTT/CoAP
    uint8_t shared_secret[32];

    // Compute shared secret using Elliptic Curve scalar multiplication
    ecc_compute_shared_secret(device_priv, server_pub, shared_secret);
    
    // Derive symmetric session key from shared_secret for TLS/AES
    derive_session_key(shared_secret, session_key);
}

By keeping the private key inside a hardware secure element, even if an attacker extracts the firmware, they cannot derive the identity of the device or intercept the encrypted session traffic.

Key Takeaway: Use ECC instead of RSA for IoT applications to achieve stronger security with lower power, memory, and bandwidth overhead.