AUTOSAR Crypto Stack: Csm, CryIf, KeyM — Implementation Guide for Automotive ECUs
By Shreyansh, Founder & CTO, Agnile Technologies
By Shreyansh, Founder & CTO, Agnile Technologies
TL;DR — The AUTOSAR Classic Crypto Stack layers four cooperating modules: Csm (application-facing job-based crypto operations plus a direct key-management API), CryIf (channel and key-slot routing), the Crypto Driver (Hardware Security Module-backed or software fallback), and KeyM (certificate and key lifecycle). Done right, it gives Secure Onboard Communication, secure boot, and secure diagnostics a single crypto API structured for audit review and a clean ASIL-grade qualification path. Done wrong — soft-fallback overuse, async callback races, broken key-slot routing — it generates the most expensive integration debt in a Classic Platform programme.
Editorial Process: Written and reviewed by Agnile engineers working day-to-day in automotive cybersecurity and safety. AI tooling is used to assist with drafting, outlining, and copy-editing; every claim, standards reference, and technical statement is verified by a human engineer before publication.
Crypto in an automotive ECU has three constraints that general-purpose libraries do not handle well: keys must never reach application memory, primitives must execute on dedicated hardware whenever it exists, and operations must be sequenced with hard real-time requirements. A monolithic crypto library either pulls keys into RAM and defeats the threat model, or executes primitives on the MCU and misses control-loop deadlines. The AUTOSAR Classic Crypto Stack is the architectural answer: a layered set of modules where the application sees a uniform job-based API, the Hardware Security Module sees a direct primitive dispatch, and the key material never crosses the boundary in either direction.
The stack also serves a second purpose. ISO/SAE 21434 Clause 10 requires evidence that cryptographic protections are correctly specified, implemented, and verified. A single Crypto Stack — with documented configuration, deterministic dispatch, and qualifiable modules — gives the cybersecurity case a single point of audit rather than a tour of every Software Component that happens to call AES.
AUTOSAR Classic Crypto Stack — module boundaries
Application / Software Components / SecOC / Diagnostics
callers of Csm_* APIs and KeyM services
Csm — Crypto Service Manager
job queue, priorities, synchronous or asynchronous jobs, direct API for key management
CryIf — Crypto Interface
channel mapping, key-slot routing, multiplexing across Crypto Driver Objects
Crypto Driver(s)
vendor Hardware Security Module driver and / or software fallback driver
Hardware — HSM, AES engine, SHA accelerator, TRNG
keys never leave the Hardware Security Module domain
KeyM — Key Manager. Service module beside the stack that calls Csm; provisions and updates key elements and verifies certificates, with validity time from StbM.
Csm is the application-facing module. It exposes two API shapes. The job-based API — Csm_Encrypt(), Csm_Decrypt(), Csm_MacGenerate(), Csm_MacVerify(), Csm_SignatureGenerate(), Csm_SignatureVerify() — submits a job descriptor that names the primitive, the input buffer, the output buffer, and the key slot. Each job is configured for asynchronous or synchronous processing; an asynchronous call returns immediately and completion arrives through a configured callback. Job priorities are configured per job and queue depths per queue; high-priority jobs (a brake command MAC verify, for instance) are queued ahead of lower-priority telemetry hashing.
The direct API serves a narrower purpose: synchronous key-management calls — setting, validating and reading key elements — that map one-to-one onto CryIf and the Crypto Driver. Low-latency primitives use a job configured for synchronous processing instead, where the caller can afford to block and the buffer is small. A typical use is a one-shot SHA-256 over a 64-byte challenge during diagnostic authentication. Synchronous jobs keep call sites simpler when async overhead is not justified.
CryIf is the routing layer. It binds Csm jobs to channels, channels to Crypto Driver Objects, and key slots to driver instances. A typical configuration has one Crypto Driver Object for the Hardware Security Module path and one for the software fallback path; CryIf dispatches a given job to the Crypto Driver Object of the channel its Csm queue maps to, not based on the job content, and translates the job’s key reference into that driver’s key. This is the right place to enforce the rule that production key slots only ever route to the HSM driver.
CryIf also handles multiplexing. Multiple Csm jobs can be in flight against the same Crypto Driver Object, limited by driver queue depth; CryIf serialises them in configured order and propagates completions back through Csm. Misconfiguration in this layer is the failure mode that loses days during integration: a job that “should” run on the HSM but actually runs on the software driver produces correct functional output and silently undermines every cybersecurity claim built on it.
The Crypto Driver implements the actual primitives. In production, the driver is a vendor Basic Software package supplied for the silicon’s Hardware Security Module — for AURIX HSM, for the S32 family’s embedded security module, for RH850’s ICUM, for STM Chorus and Microchip parts. These vendor drivers expose a uniform interface to CryIf, so the higher layers do not need to be rewritten when silicon changes; the configuration changes, the application code does not.
A pure software driver is provided as a fallback. It executes AES, SHA, CMAC, HMAC, ECDSA, and RSA on the MCU using a vetted library. Its role is development and non-sensitive workloads only. Long-term keys, SecOC session keys, and secure-boot verification keys must live in HSM-protected storage; if the software driver touches them, the threat model collapses.
KeyM owns the lifecycle. Key elements are referenced by identifier, never by raw value, throughout the rest of the stack. KeyM writes key elements into Csm keys held by the HSM-backed Crypto Driver (or in NvM), maintains certificate chains and validates them against a trusted-time source, surfaces revocation and renewal events, and brokers key derivation through Csm. Applications and Basic Software modules never handle key material: each Csm job references its key by identifier in configuration, and KeyM updates the key elements behind that identifier.
The trusted-time source is the integration question that programmes underestimate. KeyM cannot evaluate X.509 notBefore / notAfter windows without one. A defensible architecture sources signed timestamps from a backend over an authenticated channel, caches them with a bounded staleness, and gates certificate validation on time-source health. Without that, a stale certificate either slips through or every boot fails, and neither outcome is acceptable.
The numbered sequence below traces a single job-based Csm_Encrypt() call from application to Hardware Security Module and back. The same shape applies to MAC generation, signature verification, and key derivation jobs.
Application calls Csm_Encrypt(jobId, mode, dataPtr, dataLength, resultPtr, resultLengthPtr)
Job descriptor was configured at design time with primitive (AES-128 CBC), key slot identifier, callback function, and priority. Application supplies the operation mode, the plaintext pointer and length, and the output buffer for the ciphertext.
Csm queues the job and returns E_OK
Csm enqueues the job at its configured priority. The function returns synchronously without blocking; the application proceeds with other work.
Csm dispatches to CryIf_ProcessJob()
On the next dispatch tick, Csm calls CryIf_ProcessJob() with the dequeued descriptor. CryIf resolves the job's channel to its Crypto Driver Object and translates the key reference to that driver's key.
CryIf invokes Crypto_ProcessJob() on the Hardware Security Module driver
The vendor Crypto Driver receives the job, marshals input into HSM-accessible memory (typically a shared mailbox), and triggers the HSM via its mailbox or interrupt mechanism.
Hardware Security Module executes AES-CBC with the in-HSM key
The HSM core retrieves the key from its protected slot, executes the AES-CBC encryption on the supplied plaintext, and writes the ciphertext into the shared mailbox. Key material never leaves the HSM.
HSM signals completion; Crypto Driver picks up the result
An interrupt or completion bit notifies the driver. The driver copies the ciphertext output into the buffer the application supplied, sets the result code, and calls back into CryIf.
CryIf notifies Csm; Csm invokes the configured callback
Csm dispatches the completion to the application-registered callback on the configured task. The callback receives the result code and may now consume the ciphertext.
Modern Csm implementations supply a stable set of primitives drawn from NIST FIPS 197 (AES), FIPS 180-4 (SHA-2), FIPS 186-5 (ECDSA), and SP 800-38B (CMAC). In practice every Crypto Stack provides:
The Crypto Stack is the single point of contact for every cybersecurity-relevant Basic Software module on the ECU. Three patterns recur:
When the Crypto Stack participates in a function with an Automotive Safety Integrity Level above QM, every module in the stack inherits that requirement. Csm, CryIf, and KeyM packages are available from Basic Software vendors with ASIL-B and ASIL-D qualification reports; the Crypto Driver comes from the BSW vendor or the silicon vendor with its own report. The qualification is per supplier, per target, per release, and the release recommendation in WP-06-04 must reference the specific report version. Custom adaptations — non-trivial configuration deltas, custom callbacks, custom Crypto Driver Objects — require explicit qualification treatment in the project Cybersecurity Plan and may shift evidence work onto the project rather than the tool.
The Clause 10 cybersecurity case benefits from the Crypto Stack’s centralisation. Rather than enumerating cryptographic correctness in every Software Component, the case can reference the Crypto Stack qualification and the project-specific configuration; reviewers see a single audit point rather than dozens.
| Pitfall | Impact | Fix |
|---|---|---|
| Key slot bound to software driver | Production key in MCU memory; Hardware Security Module bypassed silently. | Add CryIf configuration check in CI: every production key slot must resolve to the HSM Crypto Driver Object. |
| Async callback reentrancy | Race conditions between SecOC, secure boot, and KeyM jobs completing on shared task contexts. | Document task contexts for every callback; restrict callback bodies to short, non-blocking work; queue follow-up actions explicitly. |
| Trusted-time absent in KeyM | X.509 validity windows unenforceable; certificate revocation impossible in field. | Provision an authenticated time source with bounded staleness; gate KeyM certificate validation on time-source health. |
| Job priority inversion | Safety-critical MAC verify queued behind low-priority telemetry hashes; control loop overruns. | Tier the Csm job priorities by criticality; reserve a high-priority lane for SecOC on safety-critical PDUs. |
| Software-fallback overuse | Latency budget met in benchmarks; cybersecurity property absent in production. | Production builds disable the software Crypto Driver for any key slot above a documented sensitivity threshold. |
The Adaptive Platform’s ara::crypto Functional Cluster preserves the Classic stack’s architectural intent in a different API style. C++ objects replace job descriptors; synchronous calls that return ara::core::Result replace callbacks; keys and certificates live in the Key Storage Provider and X.509 provider, with access control through Identity and Access Management, rather than a standalone KeyM. The Hardware Security Module remains the root of trust, and the same primitive set (AES, SHA-2, ECDSA, CMAC, HMAC) is exposed. Programmes that run mixed Classic and Adaptive ECUs typically maintain the same key hierarchy across both, with cross-platform services anchored in the Hardware Security Module on each side. The trade-offs are detailed in the comparison of AUTOSAR Classic vs Adaptive.
The Crypto Stack is one of the highest-leverage parts of an AUTOSAR Classic Basic Software stack: it is the single audit point for cryptographic claims, the integration boundary for the Hardware Security Module, and the call site for every other cybersecurity Basic Software module on the ECU. Get the configuration right — production key slots routed only to the HSM driver, KeyM anchored to a trusted-time source, priority lanes that respect safety criticality — and the rest of the cybersecurity stack inherits a clean foundation. Get it wrong, and every downstream claim becomes contestable.
Agnile Technologies provides AUTOSAR Crypto Stack integration across the major silicon families used in Tier-1 ECU programmes. Engage us before you freeze the CryIf channel map — that is the design moment when the wrong default sets up integration debt for the programme’s lifetime.
Cryptographic operations always use the job-based API; the direct API is mainly for key management and is always synchronous. The real choice is per job: synchronous processing for low-latency primitives where the call site can afford to block briefly (a hash on a small buffer, for example); asynchronous processing for everything else, especially MAC, signature verification, and any operation routed to the Hardware Security Module. Asynchronous jobs return immediately and the caller is notified through a callback, which fits the AUTOSAR Classic event-driven runtime far better than blocking primitives.
It can run, but X.509 validity windows then cannot be enforced. KeyM relies on a trusted time service to evaluate notBefore and notAfter on certificates; without it, every certificate either has to be treated as currently valid or rejected, neither of which is acceptable in production. A trusted time source — typically a backend-anchored, signed timestamp — is part of any defensible KeyM integration.
Development, hardware-in-the-loop simulation, and ECUs without a Hardware Security Module where the keys involved are not high-value. A software Crypto Driver should never hold long-term Secure Onboard Communication keys, secure-boot root verification keys, or signing keys in production; it is a development convenience and a fallback for non-sensitive workloads.
Secure Onboard Communication calls Csm for MAC compute and verify operations; Csm routes those jobs through CryIf to the Hardware Security Module-backed Crypto Driver. The SecOC module never touches keys directly; KeyM owns the key lifecycle, CryIf owns the channel mapping, and the Crypto Driver owns the actual primitive execution.
Yes — the ara::crypto Functional Cluster. The architectural intent is the same (application-facing API, internal routing, driver-level execution, key lifecycle service), but the API surface is C++ object-based and synchronous rather than C job-based, and keys and certificates live in the Key Storage Provider and X.509 provider, with access control enforced through Identity and Access Management.
Post-quantum primitives will arrive as additional Csm primitives — likely ML-KEM for key establishment and ML-DSA for signing as those become AUTOSAR-standardised. Architectures should be designed today to accept new primitives without re-architecting call sites: avoid hardcoding algorithm identifiers in application code, and route all crypto through Csm rather than direct primitive calls.
Two failure modes recur. First, async callback races: SecOC, secure boot, and KeyM all submit jobs that complete on a different task; reentrancy and ordering bugs surface late and are hard to reproduce. Second, key-slot and channel misconfiguration: a SecOC PDU routed to the wrong key slot, or a Csm job routed to a software driver instead of the HSM, both produce silent functional success with no real cybersecurity property.
Agnile supports engineering teams from architecture and requirements through implementation, validation, release, and evidence preparation.