In short
SecOC appends a truncated freshness value and a truncated MAC to a message. The MAC is calculated with a secret key over the message's Data ID, its payload and the complete freshness value, so a receiver detects both manipulated and replayed frames. It authenticates; it does not encrypt.
Best for: Engineers implementing, testing or analysing authenticated in-vehicle messages
E2E protection detects faults, but not attackers: anyone who knows the CRC algorithm can calculate a valid CRC for a forged frame. SecOC (Secure Onboard Communication), specified by AUTOSAR, adds what a CRC cannot: a message authentication code (MAC) calculated with a secret key that only the legitimate sender and receivers have. A device plugged into the bus can still read the messages, but it can no longer forge or replay them unnoticed.
This guide follows the AUTOSAR SecOC specification, release R22-11.
The secured message
SecOC turns an authentic PDU, the normal message payload, into a secured PDU by appending authentication information:
| authentic payload | truncated freshness value | truncated MAC |
An optional secured PDU header can also carry the length. The two added fields:
- Freshness value (FV): a counter or timestamp that increases with every message. Only its least significant bits are sent.
- Authenticator: usually a MAC, of which only the most significant bits are sent.
The MAC is calculated over three things concatenated:
DataToAuthenticator = Data ID | authentic payload | complete freshness value
The Data ID (SecOCDataId, 16 bits) identifies the message, so a valid MAC from one message cannot be reused on another. The complete freshness value goes into the MAC, even though only part of it is sent; the receiver must rebuild the rest.
Profile 1: 24-bit CMAC, 8-bit freshness
The specification defines profiles for common configurations. Profile 1, also called 24Bit-CMAC-8Bit-FV, is designed for classical CAN:
| Parameter | Profile 1 |
|---|---|
| MAC algorithm | CMAC based on AES-128, per NIST SP 800-38B |
| Truncated freshness value | 8 least significant bits |
| Truncated MAC | 24 most significant bits |
| Complete freshness value length | Not specified by the profile |
Profile 2 (24Bit-CMAC-No-FV) uses the same MAC without any freshness value, and the specification restricts it to cases where no synchronised freshness value is established. Without freshness, recorded frames can be replayed.
A sender and a receiver in Python
First the MAC. Python's cryptography package provides AES-CMAC; the RFC 4493 test vectors check it:
from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.cmac import CMAC
def aes_cmac(key, data):
mac = CMAC(algorithms.AES(key))
mac.update(data)
return mac.finalize()
# RFC 4493 test vectors: AES-128 key, empty message and a 16-byte message
key = bytes.fromhex("2b7e151628aed2a6abf7158809cf4f3c")
print(aes_cmac(key, b"").hex())
print(aes_cmac(key, bytes.fromhex("6bc1bee22e409f96e93d7e117393172a")).hex())
Output:
bb1d6929e95937287fa37d129b756746
070a16b46b4d4144f79bdd9dd04a287c
Both values match RFC 4493's examples. Then Profile 1: the sender appends the low byte of the freshness counter and the first three MAC bytes; the receiver rebuilds the full counter from its own last accepted value and the received low byte, recalculates the MAC and compares:
FV_BYTES = 4 # complete freshness value: a 32-bit counter in this example
def authenticator(key, data_id, payload, freshness):
"""SecOC: MAC over Data ID | authentic payload | complete freshness value."""
data = data_id.to_bytes(2, "big") + payload + freshness.to_bytes(FV_BYTES, "big")
return aes_cmac(key, data)
def secure(key, data_id, payload, freshness):
"""Profile 1 (24Bit-CMAC-8Bit-FV): payload | 8 LSB of the freshness | 24 MSB of the MAC."""
return payload + bytes([freshness & 0xFF]) + authenticator(key, data_id, payload, freshness)[:3]
class Receiver:
def __init__(self, key, data_id, payload_length):
self.key, self.data_id, self.length, self.last = key, data_id, payload_length, 0
def verify(self, pdu):
payload, low, mac = pdu[:self.length], pdu[self.length], pdu[self.length + 1:]
freshness = (self.last & ~0xFF) | low # rebuild the full counter from its low byte
if freshness <= self.last:
freshness += 0x100 # the low byte wrapped since the last message
if authenticator(self.key, self.data_id, payload, freshness)[:3] != mac:
return "rejected"
self.last = freshness
return f"accepted {payload.hex(' ')} (freshness {freshness})"
key = bytes.fromhex("000102030405060708090a0b0c0d0e0f")
frames = [secure(key, 0x0123, bytes([0x88, 0x13, 0x00, 0x00]), fv) for fv in (254, 255, 256)]
tampered = bytearray(frames[2])
tampered[0] ^= 0x01
receiver = Receiver(key, 0x0123, payload_length=4)
for name, pdu in [("frame 254", frames[0]), ("frame 255", frames[1]), ("replay of 255", frames[1]),
("frame 256", frames[2]), ("tampered", bytes(tampered))]:
print(f"{name:<14} {pdu.hex(' ')} {receiver.verify(pdu)}")
Output:
frame 254 88 13 00 00 fe 3a 1c 8f accepted 88 13 00 00 (freshness 254)
frame 255 88 13 00 00 ff 54 66 13 accepted 88 13 00 00 (freshness 255)
replay of 255 88 13 00 00 ff 54 66 13 rejected
frame 256 88 13 00 00 00 94 d4 01 accepted 88 13 00 00 (freshness 256)
tampered 89 13 00 00 00 94 d4 01 rejected
What happened:
- The replay is rejected although the frame is byte-for-byte identical to a valid one. The receiver has already accepted freshness 255, so it rebuilds the next value as 511, and the MAC calculated with 511 does not match.
- Frame 256 is accepted although its low byte is
00: the receiver sees that the low byte wrapped and adds 256. - One flipped bit in the payload changes the MAC completely, so the tampered frame is rejected.
Real implementations add an acceptance window (SecOCRxAcceptanceWindow) that limits how far ahead a received freshness value may be, synchronisation of freshness values between ECUs, and a limited number of verification attempts. Freshness management and key handling are manufacturer-specific; the specification's annex describes several approaches based on counters and timestamps.
The cost on classical CAN
Profile 1 adds 4 bytes to every secured message. On classical CAN, that leaves 4 of 8 bytes for data:
| Bus | Frame payload | SecOC Profile 1 overhead | Left for data |
|---|---|---|---|
| Classical CAN | 8 bytes | 1 byte FV + 3 bytes MAC | 4 bytes |
| CAN FD | up to 64 bytes | 4 bytes, or more with longer truncation | up to 60 bytes |
A 24-bit MAC means an attacker who sends random MACs has a 1 in 16 777 216 chance per attempt. The specification notes that truncation lowers the security level against forging single MACs and that NIST considers MAC sizes of 64 bits and above sufficient against guessing attacks. That trade-off between payload space and security is easier to make on CAN FD, where a frame has room for longer MACs.
What SecOC does and does not do
| SecOC provides | SecOC does not provide |
|---|---|
| Authenticity: the message came from a holder of the key | Confidentiality: payloads are still readable |
| Integrity: the payload was not changed | Protection if the sending ECU itself is compromised |
| Freshness: a recorded frame cannot be replayed | Availability: an attacker can still flood or disturb the bus |
For reverse engineering, this means SecOC-protected messages are still readable: the authentic payload is in clear text, and only the last bytes look random. You can decode the signals; you cannot send modified versions without the key.
For safety, SecOC and E2E are complementary: E2E protection detects random faults, SecOC detects deliberate manipulation. Messages can carry both. Regulations such as UN R155 require manufacturers to manage cybersecurity risks across the vehicle; the ISO/SAE 21434 and UN R155 guide explains the framework in which such measures are chosen.
Frequently asked questions
What is SecOC in AUTOSAR?
Secure Onboard Communication, an AUTOSAR module that authenticates messages between ECUs. It appends a freshness value and a MAC, calculated with a secret key over the message's Data ID, payload and freshness value, so receivers detect forged and replayed messages.
What is a freshness value in SecOC?
A counter or timestamp that increases with every message and is included in the MAC. Because a replayed message carries an old freshness value, its MAC no longer verifies. Only the low bits are sent; the receiver rebuilds the rest.
Does SecOC encrypt CAN messages?
No. SecOC authenticates messages but does not encrypt them. The payload remains readable on the bus; what an attacker cannot do without the key is send a modified or replayed message that the receiver accepts.
Why is the SecOC MAC truncated?
Classical CAN frames have only 8 bytes. A full 128-bit CMAC would not fit, so SecOC sends only the most significant bits, 24 in Profile 1. This lowers resistance to guessing, which is why truncation lengths are chosen per message and longer MACs are easier on CAN FD.
References
DBC Utility
One desktop app for DBC files and CAN recordings.
One-time $34 · Windows & Linux · Files stay on your computer