Contents

Hash functions and MACs

Hashes fingerprint data; message authentication codes add a secret key so receivers can detect changes made by someone without that key.

6 min read · Discipline stake: Security BSW Software Update

Why it exists

A brake controller receives a torque request. A central computer downloads a software image. In both cases, the receiver needs to detect unexpected changes. For the torque request, it also needs evidence that someone holding an authorized key created the message.

A cryptographic hash gives data a compact fingerprint. A message authentication code (MAC) adds a secret key, allowing a receiver to check authenticity as well as integrity.

The distinction matters: an attacker who replaces a software image can also calculate its new hash. A digest becomes useful against an attacker only when the expected value comes from a trusted source, such as a verified, signed update manifest.

What it is

A hash function maps input data to a fixed-length result called a digest. The same bytes always produce the same digest. No secret key is required.

Useful security properties are:

  • Preimage resistance: given a digest, finding an input that produces it should be computationally infeasible.
  • Second-preimage resistance: given an input, finding a different input with the same digest should be infeasible.
  • Collision resistance: finding any pair of different inputs with the same digest should be infeasible.

Collisions must exist because the input space is larger than the digest space. Security means that finding useful collisions is impractical.

SHA-256, SHA-384 and SHA-512 belong to the Secure Hash Algorithm 2 (SHA-2) family specified in FIPS PUB 180-4. Their names identify their digest lengths in bits. SHA-3, specified in FIPS PUB 202, provides a different internal construction. Select the exact algorithm required by the protocol; SHA3-256 and SHA-256 produce different results.

SHA-1 and MD5 are broken for collision resistance. Do not select them for new security designs. A collision attack does not automatically recover an original input or secret key, but it invalidates their use where collision resistance is required.

A MAC takes a secret key and a message and produces an authentication tag. A receiver holding the same key can verify it. Anyone holding that key can also generate valid tags.

Building block Keys needed What a successful check establishes Main limitation
Hash None Data matches a trusted expected digest An attacker can replace an unprotected digest
MAC Shared secret for generation and verification Data was authenticated by a holder of the secret Verifiers can also create valid tags
Digital signature Private key to sign; public key to verify Data verifies under the selected public key Requires a trusted binding between that key and its owner

None of these mechanisms encrypts the data. Replay protection also requires additional protocol rules.

How it works

Hashing bytes

A hash processes the exact input bytes, including their order and encoding. Hashing can happen incrementally while an image is read from storage; the complete image need not fit in memory.

Common vehicle uses include:

  • Image digests: compare downloaded software with the digest bound into an authenticated manifest.
  • Measured boot: hash boot components and record measurements for later appraisal or attestation. Measurement records what loaded; it does not itself block execution as secure boot does.
  • Merkle trees: hash individual chunks, then combine their hashes into a tree. A trusted root digest allows a chunk to be checked using a path of sibling hashes, without reading the entire dataset.

The tree format must define ordering and distinguish leaf data from internal nodes. Otherwise, different structures may be interpreted as the same hash input.

Authenticating messages

HMAC, specified in FIPS PUB 198-1, combines a cryptographic hash with a secret key through a defined inner and outer construction. HMAC-SHA-256 is one example. It is not simply a hash with a key appended.

AES-CMAC uses the Advanced Encryption Standard (AES) block cipher through the cipher-based MAC construction specified in NIST SP 800-38B. Using AES for a MAC does not encrypt the message. AES-CMAC can suit controllers with AES acceleration, but actual performance depends on the implementation and workload.

The sender authenticates the agreed message fields. The receiver reconstructs the same input, verifies the tag and releases the message only after the required checks pass.

Truncation and freshness in SecOC

AUTOSAR Secure Onboard Communication (SecOC) can transmit a shortened MAC tag to reduce communication overhead. Both sides must agree on the algorithm, retained tag bits and input encoding.

A shorter tag saves payload space but makes successful guessing more likely. Its suitability depends on the attacker’s opportunities to submit guesses, key lifetime and consequences of accepting a forged message. Choose the length through a security assessment, alongside limits on verification attempts.

A valid MAC alone does not stop replay: a captured message still has a valid tag. SecOC therefore authenticates a freshness value, such as counter-based state, together with the message and its configured data identifier. Receivers enforce freshness rules. When only part of the freshness value is transmitted, they must reconstruct the full value consistently.

MAC verification and replay rejection
Sender ECUholds shared key K
Receiver ECUholds shared key K
Mallorycaptures and replays traffic
Compute tagMAC with K over message and freshness counter
Message, counter, tag
Verify tagRecompute with K; compare tags
Accept fresh messageCheck freshness; update replay protection state
Replay captured messageSame message, counter and valid tag
Reject stale counterFreshness check fails despite valid tag

Simplified counter-based example: authenticated inputs and freshness rules are protocol-defined, and a valid MAC alone does not prevent replay.

When to use it — and when not

Use hashes for fingerprints, authenticated image checks and tree-based integrity verification. Use MACs when communicating parties can securely share a secret, as in protected control messages between electronic control units (ECUs).

Use signatures when many devices must verify software without receiving a secret that would also let them authorize software. This is especially relevant to secure boot and update distribution.

Do not use an unkeyed hash as message authentication. Do not use a plain cryptographic hash for password storage; passwords need a dedicated password-hashing scheme. When confidentiality is also required, use an established authenticated-encryption protocol.

Best practices

  • Use maintained cryptographic libraries and the algorithm required by the system’s security profile. Verify implementations with published test vectors.
  • Define exactly which bytes are authenticated: payload, message identity, freshness and relevant context. Specify field lengths and byte order.
  • Separate keys across purposes and trust domains. Sharing one MAC key widely increases the number of components able to forge messages.
  • Use the library’s verification API or a constant-time comparison for tags. For the configured length, comparison timing must not reveal how many leading bytes matched. Ordinary equality functions may return at the first mismatch.
  • Define freshness behavior across resets, lost messages and resynchronization. Test stale messages and manipulated freshness fields.
  • For images, protect the expected digest and ensure verified bytes cannot change before installation or execution.

Common pitfalls

  • Treating a matching digest as proof of an authorized sender.
  • Constructing a custom MAC as hash(key || message). Some hash constructions permit length-extension attacks; use HMAC.
  • Shortening tags to fit a frame without assessing repeated forgery attempts.
  • Assuming a longer digest compensates for weak keys, broken freshness handling or unauthenticated metadata.
  • Accepting a message after MAC verification fails because its signals appear plausible.
  • Assuming every holder of a shared MAC key has a distinct, provable identity. A valid tag identifies the key-holding group unless the key architecture provides finer separation.

What it means for your discipline

  • Cybersecurity Core

    Selects hash and MAC algorithms, sets authentication-tag lengths and replay protections, and reviews key separation and verification behavior.

  • Base software Partial

    Configures cryptographic services and SecOC authentication inputs, tag truncation and freshness handling; checks verification failures before releasing received signals.

  • HPC & application software Partial

    Uses cryptographic libraries to hash exact byte sequences and verify authentication tags; avoids ambiguous serialization and timing-sensitive comparisons.

  • Software update & OTA Partial

    Binds image digests to authenticated update manifests and checks that the bytes verified are the bytes installed.

No direct stake: E/E architecture · Functional safety · Hardware & silicon · Networks & communication · Diagnostics & lifecycle

Where it sits in the software stack

Generic layered software of a central HPC (application processor with hypervisor, plus a safety island) and of a classic MCU-based ECU (AUTOSAR Classic). Highlighted modules matter for this topic. Click any module to open its page.

HPC · application processor (MPU) and safety island (MCU)
  • Security services — Provides hash and MAC operations with controlled key access and authentication-tag verification.
  • OTA client · UCM — Checks downloaded image digests against authenticated manifests and ensures verified bytes are the bytes installed.
  • Secure boot chain · TEE — Hashes boot components for integrity verification or measurement, depending on the boot design.
MCU-based ECU · AUTOSAR Classic
  • Memory · crypto · WdgM — Provides configured hash and MAC jobs through cryptographic services.
  • Communication — Verifies SecOC tags over message fields, data identifiers and freshness values before releasing received data.
  • Flash bootloader · secure boot — Checks firmware digests against authenticated metadata before accepting an image.