Skip to main content
emobility.academy
M.TechFunctional safety & cybersecurityAdvanced About 9 weeksADAS & AUTOSAR

Secure Onboard Communication (SecOC) for ADAS Signals on CAN

Implement AUTOSAR-style Secure Onboard Communication on CAN: the DIYguru EV kit's STM32 sends ADAS signals with a truncated CMAC and freshness value, and a Linux receiver verifies them. Spoofing, replay and tampering attacks are tested, and the cost in bus load, latency and CPU time is measured.

Tools: AUTOSAR Blockset · CAN

Secure Onboard Communication (SecOC) for ADAS Signals on CAN: Students using a diagnostic scan tool on an electric car at DIYguru
Representative photo from DIYguru's EV lab, not of this specific project.

The problem

Classic CAN has no authentication, so any node, or an attacker with access to the bus, can send frames that look legitimate. SecOC adds a message authentication code and freshness value to protected PDUs, which lets receivers reject forged and replayed frames. It costs payload bytes, computation and key management effort. This project implements SecOC on real CAN hardware and measures both its protection and its cost.

Objectives

  • Explain SecOC: authentic PDU, secured PDU, freshness value, MAC and truncation.
  • Design a secured PDU layout for ADAS signals within 8-byte classic CAN frames.
  • Implement CMAC-AES generation on the STM32 and verification on Linux.
  • Implement freshness management with counters and resynchronisation.
  • Test spoofing, replay and tampering attacks and measure overhead.

What you need

Tools and toolboxes

  • STM32CubeIDE with STM32 HAL — Firmware for the sender ECU using the bxCAN peripheral and a software AES-CMAC implementation.
  • AUTOSAR Blockset — Models the sender software component and generates its ARXML description, including the secured PDU in the communication configuration.
  • Linux SocketCAN with can-utils — Receives frames for verification and acts as the attacker node that injects and replays frames.
  • Python with python-can and cryptography — Implements the receiver verification and attack scripts with a standard CMAC implementation.
  • Vector DaVinci or EB tresos (industry reference only) — Named as the tools industry uses to configure the SecOC module; not required for this project.

From the EV Embedded Development Kit

  • STM32F103C8T6 microcontroller unit (Arm Cortex-M3)
  • CAN bus interface with screw terminal
  • Analog potentiometer input
  • 16×2 LCD with contrast control
  • RGB LEDs and a buzzer
  • Serial UART interface

Software

  • STM32CubeIDE
  • MATLAB with Simulink and AUTOSAR Blockset
  • Ubuntu Linux with SocketCAN and can-utils
  • Python with python-can and cryptography

Extra parts and data

  • USB-CAN adapter for the PC — Connects the Linux receiver and attacker scripts to the kit's CAN screw terminal; it must be supported by SocketCAN.
  • 120-ohm termination resistor (if the adapter has none) — A two-node bench bus needs termination at both ends.

Key concepts

Secured PDU
The authentic payload followed by a truncated freshness value and a truncated MAC. On classic CAN the authentic payload must shrink to leave room for them.
CMAC
A message authentication code based on a block cipher such as AES-128. It proves the sender knew the shared key and the data was not changed.
Freshness value
A counter or time value included in the MAC calculation so an old frame replayed later fails verification.
Truncation
Only part of the MAC and freshness are sent to save bytes. Shorter MACs raise the chance an attacker guesses a valid one, so length is a security trade-off.

Step-by-step guide

  1. 1

    Define the protected signals

    Choose a safety-relevant frame: a BrakeRequest from an ADAS ECU with requested deceleration (from the potentiometer) and a request flag, sent every 20 ms. Define threats from a prior TARA: spoofed brake requests, replayed requests and modified values. Set requirements for detection, acceptable added latency and the number of consecutive verification failures before the receiver reports an attack. Keep the threats in a short table with the expected receiver reaction for each.

    Checkpoint: A requirement list with threats, detection and latency targets for the protected frame.

  2. 2

    Design the secured PDU layout

    Fit everything into 8 bytes: for example 3 bytes of authentic payload, 1 byte of truncated freshness and 4 bytes of truncated MAC. Define the full freshness counter (for example 32 bits) kept on both sides, with only the lowest byte sent, and the data used for the MAC: data ID, full freshness and authentic payload. Discuss the security level of a 32-bit MAC against online guessing at 50 frames per second.

    Checkpoint: A byte-level layout diagram and a written justification of MAC and freshness lengths.

  3. 3

    Model the sender component

    In Simulink with AUTOSAR Blockset, create a sender software component that reads the potentiometer value, forms the BrakeRequest signal and sends it through a sender port. Map it to AUTOSAR and export ARXML, then inspect the generated description for the port interface and data element. Describe in the report where a SecOC module and secured I-PDU would be configured in a full Classic stack.

    Checkpoint: Exported ARXML that shows the component, port and data element for BrakeRequest.

  4. 4

    Implement CMAC on the STM32

    Add a small, well-tested software AES-128 and CMAC implementation to the firmware, since the STM32F103 has no crypto accelerator. Verify it against the published CMAC test vectors for AES-128 before using it. Store a test key in flash and mark it clearly as a lab key. Measure CMAC computation time with the DWT cycle counter. Keep the key in one place in the code so it can be replaced easily.

    Checkpoint: CMAC output matches the published test vectors, with measured cycles per MAC.

  5. 5

    Build the secured sender

    Every 20 ms, increment the freshness counter, compute the CMAC over data ID, full counter and payload, truncate it and pack the secured PDU into the CAN frame. Persist the counter's upper bits to flash periodically so it never repeats after reset, and start each power cycle beyond the last stored value. Show the counter and request on the LCD and stream debug data over UART.

    Checkpoint: candump shows secured frames at 20 ms with an incrementing freshness byte and changing MAC.

  6. 6

    Build the receiver verification

    In Python with python-can and the cryptography library, receive the frame, reconstruct the full freshness value from the received low byte and the receiver's last accepted counter within an acceptance window, compute the CMAC and compare the truncated values. Accept only if the MAC matches and the counter is greater than the last accepted one. Log results and count consecutive failures.

    Checkpoint: The receiver verifies every legitimate frame over a 10-minute run with no false rejections.

  7. 7

    Test attacks

    From a second SocketCAN script acting as attacker, send forged BrakeRequest frames with random MACs, replay recorded legitimate frames, and modify the payload of captured frames while keeping the MAC. Run each attack while the legitimate sender is active. Confirm the receiver rejects every attack frame and raises an attack report after the configured number of failures. Do this only on the isolated bench bus.

    Checkpoint: An attack test table showing all forged, replayed and modified frames rejected.

  8. 8

    Test freshness resynchronisation

    Reset the sender, disconnect it for a period, and drop frames on purpose to test the acceptance window. Check that the receiver resynchronises after gaps smaller than the window and rejects frames beyond it. Measure how many frames are lost during resynchronisation and decide whether a separate resynchronisation message is needed. Record behaviour if the sender's stored counter is lost.

    Checkpoint: Resynchronisation results for reset, disconnection and dropped-frame cases.

  9. 9

    Measure overhead

    Measure CMAC time on the STM32 per frame and as a share of CPU at 50 frames per second, receiver verification time, and added end-to-end latency compared with an unprotected version of the same frame. Calculate bus load for the unprotected and protected designs, including the lost payload bytes. Extrapolate how many protected frames the STM32 could handle per second.

    Checkpoint: An overhead table with CPU share, latency, bus load and maximum protected frame rate.

  10. 10

    Report

    Document requirements, PDU layout, ARXML, firmware and receiver design, attack and resynchronisation tests and overhead. Discuss key management, which this project simplifies with a lab key: production systems need secure key storage, key distribution and update. State limits: software crypto, one protected frame and a bench bus. Relate the design to SecOC and CAN FD, where larger payloads ease truncation trade-offs.

    Checkpoint: A report with attack results, overhead figures and a clear key management discussion.

Testing & validation

  • CMAC implementation matches published test vectors.
  • No false rejections of legitimate frames over long runs.
  • All forged, replayed and modified frames rejected on the bench bus.
  • Correct resynchronisation within the acceptance window.
  • Measured CPU, latency and bus-load overhead.

Expected results

A working SecOC-style protected CAN frame between the kit STM32 and a Linux receiver, shown to reject spoofing, replay and tampering, with measured computation, latency and bus-load costs.

Research angle for your M.Tech thesis

Research questions: how should MAC length, freshness length and acceptance window be chosen for classic CAN SecOC under payload, CPU and resynchronisation constraints, and what is the real cost on a low-end Cortex-M3 without crypto hardware? Metrics: CPU cycles per MAC, added latency, bus load, attack success probability for given truncation and frames lost on resynchronisation. Baselines: unprotected frames and CAN FD layouts. A measured cost and security trade-off on real hardware with released code supports a conference paper on in-vehicle network security.

Take it further

  • Move to CAN FD and compare MAC length choices.
  • Add a freshness value manager that broadcasts a synchronised time counter.
  • Protect several frames with different keys and measure scheduling impact.
  • Compare with an intrusion detection approach on the HCRL Car-Hacking dataset.

Viva and review questions

Why include a freshness value in the MAC?

Without it a recorded valid frame would verify again when replayed; the counter makes each frame's MAC unique and lets the receiver reject old ones.

Why send only part of the MAC?

Classic CAN has only 8 bytes, so the MAC is truncated to leave room for the signal, accepting a higher but still bounded guessing probability.

What happens if the sender's counter resets to zero?

The receiver would reject its frames as old, so the counter's upper bits are stored in flash and restarted beyond the last stored value.

Does SecOC stop a compromised ECU that holds the key?

No. It authenticates the sender's knowledge of the key, so a compromised key holder can still send valid frames; key isolation and other controls are needed.

Learn it at DIYguru

These DIYguru courses and programmes teach what this project needs.

Related EV projects

All 100 ADAS & AUTOSAR projects