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

Block Cipher Modes of Operation

Learners will configure block cipher modes like AES-CBC and AES-GCM to ensure data integrity and confidentiality in streaming embedded sensor data.

In this lesson, you will learn how to configure AES-CBC and AES-GCM to secure streaming sensor data against eavesdropping and tampering.

When encrypting sensor telemetry, we cannot simply encrypt raw blocks individually; an attacker could identify patterns or swap cipher blocks to manipulate data. We use Block Cipher Modes to chain these blocks together, ensuring each block depends on the previous ones or a unique nonce.

AES-CBC (Cipher Block Chaining)

CBC provides confidentiality. Each plaintext block is XORed with the previous ciphertext block before being encrypted. This masks patterns in your sensor readings.

  • Constraint: You must use an Initialization Vector (IV) that is random and never reused with the same key. If the IV is predictable, the mode becomes vulnerable to dictionary attacks.
// Concept: CBC encryption flow
void encrypt_sensor_data(uint8_t *plaintext, uint8_t *iv, uint8_t *key) {
    uint8_t prev_ciphertext[16];
    memcpy(prev_ciphertext, iv, 16);
    
    // For each 16-byte block
    xor_block(plaintext, prev_ciphertext); // XOR with previous block
    aes_encrypt(plaintext, key);          // Encrypt
    memcpy(prev_ciphertext, plaintext, 16);
}

AES-GCM (Galois/Counter Mode)

CBC protects confidentiality but not integrity. An attacker could flip bits in transit, and your embedded device would decrypt the corrupted data without knowing it was altered.

AES-GCM is the gold standard for IoT because it provides Authenticated Encryption with Associated Data (AEAD). It creates an authentication tag alongside the ciphertext. During decryption, the hardware verifies this tag; if the data was modified by even a single bit, the decryption routine will return an error, allowing your device to discard the packet immediately.

Selecting Your Mode

  • Use AES-CBC only if you are working on legacy systems where memory is extremely constrained and you have a separate, proven Message Authentication Code (MAC) scheme already in place.
  • Use AES-GCM for all modern streaming telemetry. It is faster on hardware with AES-NI instructions and provides integrated integrity checking, which is vital for remote sensors where untrusted network paths are common.

Key Takeaway: While CBC provides basic confidentiality, GCM is essential for IoT because it combines encryption with hardware-verified integrity, preventing data tampering in transit.