Android Hardware Reverse Engineering

Side-Channel Attacks on Android TEE: Power Analysis for TrustZone Vulnerabilities

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction to Android TEE and Side-Channel Threats

The Android TrustZone Environment (TEE) is a critical security component on modern Android devices, providing a secure execution environment isolated from the rich operating system (Normal World). It’s designed to protect sensitive operations like cryptographic key management, DRM, and secure boot. However, even deeply embedded secure components are not immune to sophisticated attacks. Side-channel analysis, particularly power analysis, presents a formidable threat by exploiting physical leakages from the device’s hardware. This article delves into the principles of power analysis attacks targeting TrustZone, outlining the methodology for exploiting power consumption anomalies to extract secret information or identify vulnerabilities.

ARM TrustZone technology partitions a system-on-chip (SoC) into two virtual worlds: the Secure World and the Normal World. The Secure World hosts the TEE OS and trusted applications (TAs), while the Normal World runs Android. Communication between these worlds is strictly controlled via an API. Our focus is on how a malicious actor, with physical access, can observe the power traces of TEE operations to infer secret data.

Understanding Power Analysis and TrustZone Operations

Power analysis attacks capitalize on the fact that electronic components consume varying amounts of power depending on the operations they perform. Cryptographic algorithms, in particular, exhibit distinct power signatures related to data processing, especially when manipulating secret keys. For instance, an AES encryption round involving a ‘0’ bit might consume slightly different power than one involving a ‘1’ bit. Over many operations, these subtle differences accumulate and can be statistically analyzed to reveal the underlying secrets.

Within the TrustZone, trusted applications perform sensitive tasks. When a Normal World application requests a service from a TA (e.g., signing a transaction, decrypting data), the TEE processes this request using its isolated resources. It’s during these TEE-specific operations, especially those involving cryptographic primitives like AES, RSA, or ECC, that valuable side-channel information can be leaked through power consumption.

Setting Up the Power Analysis Attack Environment

Hardware Requirements:

  • Target Android Device: An unlocked device, preferably with root access to install custom TAs and control workload.
  • High-Speed Oscilloscope: Capable of sampling at several GS/s (Giga-samples per second) with sufficient memory depth.
  • Current Measurement Probe/Shunt Resistor: A low-value (e.g., 0.1-1 Ohm) non-inductive resistor inserted in series with the target’s power supply line, or a dedicated current probe.
  • Fixture for Device: To ensure stable connections and repeatable measurements.
  • Differential Probe: For measuring voltage across the shunt resistor.
  • PC with Data Acquisition Software: To control the oscilloscope and analyze collected traces.

Software Requirements:

  • Android Debug Bridge (ADB): For device communication.
  • Custom Trusted Application (TA): A TA deployed to the TEE that performs the target cryptographic operation with controlled inputs.
  • Normal World Client Application: An Android app to invoke the TA repeatedly.
  • Analysis Software: Python libraries (NumPy, SciPy), MATLAB, or specialized tools like ChipWhisperer for trace processing and statistical analysis (e.g., CPA, DPA).

Physical Setup Steps:

  1. Identify Power Rail: Locate the VCC rail supplying power to the SoC or a specific component performing the cryptographic operations within the TEE. This often requires referring to device schematics or careful probing.
  2. Solder Shunt Resistor: Desolder the existing power line and solder a small shunt resistor (e.g., 0.5 Ohm) in series. This resistor converts current fluctuations into measurable voltage drops.
  3. Connect Oscilloscope: Attach the differential probe leads across the shunt resistor. Connect the oscilloscope to the PC via USB or Ethernet.
  4. Grounding: Ensure proper grounding to minimize noise.
  5. Control Target: Use ADB and the client application to trigger the specific TEE operation multiple times, varying known inputs while keeping the secret key constant.
# Example: Basic ADB commands to invoke a TA operation (conceptual) adb shell am start -n com.example.clientapp/.MainActivity adb shell input tap 500 1000 # Simulate button press to trigger TA for i in range(1000): # Trigger the TA with known plaintext "Hello{i}" client.invoke_ta_aes_encrypt("Hello" + str(i).zfill(3)) # Collect power trace concurrently 

Methodology: Data Collection and Analysis

Data Collection:

The core of power analysis is collecting numerous power traces while the TEE performs the target operation. For each trace, a known input (e.g., plaintext for encryption) is provided, and the corresponding power consumption profile is recorded. Crucially, the secret key inside the TEE remains constant. Synchronization is vital; the oscilloscope trigger should be aligned with the exact moment the cryptographic operation begins within the TEE. This can be achieved by toggling a GPIO pin from the TEE or by precisely timing the Normal World call.

// Conceptual Trusted Application (TA) snippet // Invoked from Normal World with some input data TEE_Result TA_InvokeCommandEntryPoint(void* sess_ctx, uint32_t cmd_id, uint32_t param_types, TEE_Param params[TEE_NUM_PARAMS]) { switch (cmd_id) { case TA_AES_ENCRYPT: // For power analysis, we'd trigger power measurement here TEE_CipherDoFinal(ctx, TEE_ALG_AES_ECB_NOPAD, params[0].memref.buffer, params[0].memref.size, params[1].memref.buffer, params[1].memref.size); break; // ... other commands } return TEE_SUCCESS; } 

Data Analysis:

Once thousands of traces are collected, the real work begins:

  1. Preprocessing: Align all traces to a common point to compensate for timing jitters. Filtering might be applied to remove high-frequency noise.
  2. Hypothesis Generation: Based on the known cryptographic algorithm, formulate a power consumption model. For example, in AES, the first sub-byte operation (S-box) involves lookup tables. The power consumed by this operation is often correlated with intermediate values derived from the plaintext and a portion of the secret key.
  3. Correlation Power Analysis (CPA): For each possible key byte (0-255), predict the intermediate value at a specific point in the algorithm (e.g., after the first S-box). Then, compute the hypothetical power consumption for each trace based on this intermediate value. Finally, calculate the Pearson correlation coefficient between the hypothetical power consumption and the actual power traces at every sample point. The correct key byte will show a significantly higher correlation peak at the precise time the operation occurs.
  4. Differential Power Analysis (DPA): Divide traces into two groups based on a predicted intermediate bit. Compute the average power trace for each group and find the difference. A clear peak in the differential trace indicates a leakage related to that bit.
# Conceptual Python for CPA (simplified) import numpy as np from scipy.stats import pearsonr # Assuming 'traces' is a 2D array: (num_traces, num_samples) # Assuming 'plaintexts' is a 1D array of input data # Assuming 'target_intermediate_func' calculates an intermediate value (e.g., S-box output) num_traces, num_samples = traces.shape possible_key_bytes = range(256) correlations = np.zeros((len(possible_key_bytes), num_samples)) for k_guess in possible_key_bytes: hypothesized_power = np.array([target_intermediate_func(pt, k_guess) for pt in plaintexts]) for sample_idx in range(num_samples): correlations[k_guess, sample_idx] = pearsonr(hypothesized_power, traces[:, sample_idx])[0] # The key_guess with the highest correlation peak at a relevant time point is likely correct. best_guess = np.argmax(np.max(correlations, axis=1)) print(f"Most likely key byte guess: {best_guess}") 

Challenges and Mitigations

Power analysis attacks are powerful but face challenges:

  • Noise: Environmental noise, internal SoC activity, and measurement noise can obscure the subtle cryptographic signals. Averaging many traces helps reduce random noise.
  • Synchronization: Precise alignment of traces is crucial. Jitter in software or hardware can severely impact analysis.
  • Countermeasures: TEEs employ various mitigations:
    • Masking: Randomizing intermediate values by combining them with random masks, making correlations difficult.
    • Shuffling: Randomizing the order of operations.
    • Constant-Time Implementations: Ensuring cryptographic operations take the same amount of time and consume constant power regardless of data or key values.
    • Power Randomization: Introducing random noise into power consumption or actively changing power supply characteristics.

Conclusion

Power analysis represents a sophisticated and potent threat to the Android TrustZone Environment. By meticulously observing the current draw during cryptographic operations within the TEE, attackers can potentially bypass the isolation mechanisms and extract secret keys or sensitive data. While setting up such an attack requires specialized hardware, expertise, and significant effort, its success can completely compromise the security guarantees of the TEE. Developers of trusted applications and TEE OS must rigorously implement side-channel resistant cryptographic primitives and employ robust countermeasures to protect against these advanced hardware-level attacks, ensuring the integrity of the Secure World.

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner