Original PDU payload (e.g., 6 bytes VehicleSpeed) ┌────────────────────────────────────────────────┐ │ Original PDU Data │ └────────────────────────────────────────────────┘ SecOC adds authentication data (appended or interleaved): ┌──────────────────────────────────┬──────┬──────┐ │ Original PDU Data │ FV │ MAC │ │ (unchanged) │(2-4B)│(4-8B)│ └──────────────────────────────────┴──────┴──────┘ FV = Freshness Value (truncated — lower nibble of trip counter) MAC = Message Authentication Code (truncated AES-128-CMAC) On CAN (8 byte DLC): leaves 0-2 bytes for payload → Most SecOC-protected CAN PDUs use dedicated message IDs with only the auth field → Or use CAN-FD 64-byte payload to fit original data + FV + MAC comfortably
AUTOSAR SecOC: Authenticated On-Board Communication
MAC Algorithms and HSM Integration
/* SecOC MAC computation via SHE (Secure Hardware Extension) API */
/* Key stored in HSM — never exposed to main MCU core */
#include "Crypto_30_LibCv.h"
#include "SecOC.h"
SecOC_VerificationStatusType SecOC_VerifyMac(
const uint8* pdu_data, uint32 pdu_len,
const uint8* fv, uint8 fv_len,
const uint8* received_mac, uint8 mac_len)
{
uint8 computed_mac[16]; /* Full 128-bit AES-CMAC */
uint8 concatenated[256];
uint32 concat_len = 0;
/* Construct MAC input: FV || PDU data */
memcpy(concatenated, fv, fv_len);
concat_len += fv_len;
memcpy(concatenated + concat_len, pdu_data, pdu_len);
concat_len += pdu_len;
/* Request AES-128-CMAC from HSM (SHE API) */
Crypto_30_LibCv_MacGenerate(
CRYPTO_KEY_IDX_SECOC_VEHICLESPEED, /* Key slot in HSM */
concatenated, concat_len,
computed_mac /* HSM writes result here */
);
/* Compare truncated MAC (first 4 bytes = 32-bit truncated CMAC) */
if (memcmp(computed_mac, received_mac, mac_len) == 0) {
return SECOC_VERIFICATIONSUCCESS;
}
return SECOC_VERIFICATIONFAILURE; /* Inject attack detected */
}Freshness Value Manager (FVM)
| FVM Component | Storage | Bits Transmitted | Bits in NvM |
|---|---|---|---|
| Trip Counter (MSB) | NvM — persists across resets | 0 bits (not transmitted) | 16–24 bits |
| Message Counter (LSB) | RAM — resets on power cycle | 4–8 bits (transmitted in PDU) | 8–16 bits |
| Full Freshness Value | Reconstructed: Trip||Message | — | 24–40 bits total |
/* AUTOSAR FVM: reconstruct full freshness value from received truncated nibble */
#include "FVM.h"
#include "NvM.h"
#define FV_NIBBLE_BITS 4 /* bits transmitted in PDU */
#define FV_MSB_BITS 28 /* bits stored in NvM (trip counter) */
uint32 FVM_ReconstructFV(uint8 received_nibble, uint32 nvm_trip_counter)
{
uint32 full_fv;
uint32 nibble_max = (1u << FV_NIBBLE_BITS);
/* Reconstruct: check if nibble wrapped around trip counter boundary */
uint32 lsb_part = received_nibble & (nibble_max - 1);
uint32 current_lsb = nvm_trip_counter & (nibble_max - 1);
if (lsb_part < current_lsb) {
/* Wrap-around detected: increment MSB part */
full_fv = ((nvm_trip_counter >> FV_NIBBLE_BITS) + 1) << FV_NIBBLE_BITS;
} else {
full_fv = nvm_trip_counter & ~(nibble_max - 1);
}
full_fv |= lsb_part;
/* Detect replay: FV must be greater than last accepted FV */
if (full_fv <= FVM_GetLastAcceptedFV(PDU_ID_VEHICLESPEED)) {
return FVM_REPLAY_DETECTED;
}
FVM_UpdateLastAcceptedFV(PDU_ID_VEHICLESPEED, full_fv);
return full_fv;
}Gateway SecOC Impact: Re-Authentication
⚠️ Signal Gateways Must Re-MAC SecOC PDUs
When a SecOC-protected CAN PDU is routed through a gateway ECU, the gateway must verify the incoming MAC using the source domain key, then compute a new MAC using the destination domain key before forwarding. This re-authentication adds 50–200 µs latency (AES-CMAC on HSM) per routed PDU. A PDU gateway (byte copy without signal decode) cannot re-MAC — it lacks access to both keys — so the interface must be classified as a trusted internal path. Classify all gateway routing interfaces explicitly as trusted or untrusted in the security architecture before implementation.
Summary
SecOC protects on-board communication against injection, replay, and spoofing by appending a truncated MAC and Freshness Value to every protected PDU. The HSM computes AES-128-CMAC without exposing the key to the main MCU core. The FVM reconstructs the full freshness counter from the transmitted nibble plus NvM trip counter — enabling replay detection with minimal PDU overhead. Gateway ECUs must explicitly handle SecOC re-authentication for cross-domain signal routing.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.