npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mac_encrypt

v1.1.5

Published

Cipher with aes-cmac and compute MAC for CAN/Eth frames and SHE cmd args

Readme

MAC_encrypt

Module Node.js pour le chiffrement AES-CMAC et le calcul de tags MAC (Message Authentication Code) sur des trames CAN/Ethernet, dans le cadre du protocole SHE (Secure Hardware Extension) défini par AUTOSAR.

Description

mac_encrypt fournit les fonctionnalités suivantes :

  • Reconstruction de trames CAN à partir de leurs champs (type, FreshValue, payload, MSB, LSB, padding) pour trois types de trames :
  • FVSyncFrame (Sync) : trame de synchronisation du compteur anti-rejeu
  • FVReSyncFrame (ReSync) : trame de re-synchronisation contenant 6 FreshValues concaténés
  • SC_FD (Secured Container) : trame sécurisée contenant le payload applicatif
  • Chiffrement AES-CMAC (encrypt_Frame) : calcul du MAC complet (16 octets) d'une trame reconstruite avec une clé AES-CMAC
  • Vérification de MAC (verifyMac) : comparaison du tMAC (8 premiers octets du MAC) avec le tMAC attendu
  • Key Derivation Function (KDF) : dérivation de clé via la fonction de compression Miyaguchi-Preneel

Installation

npm install mac_encrypt

Dépendances

| Module | Version | Description | |--------|---------|-------------| | aes-js | ^3.1.2 | Implémentation AES en JavaScript | | node-aes-cmac | ^0.1.1 | Implémentation AES-CMAC | | miyaguchipreneel | ^1.1.4 | Fonction de compression Miyaguchi-Preneel |

Utilisation

const MAC_encrypt = require('mac_encrypt');

// Paramètres d'une trame SC_FD
var type = '0x453';
var name = 'USM_A101SC_FD';
var fv = Buffer.from('000005d4be4e', 'hex');
var msb = Buffer.from('000005d4', 'hex');
var lsb = Buffer.from('be4e', 'hex');
var payload = Buffer.from('00045308f1171567a02af6', 'hex');
var pad = Buffer.from('000000', 'hex');
var tMAC = Buffer.from('0b2c4e4388cd84b6', 'hex');

// Instanciation
var mac = new MAC_encrypt(type, name, '', 'USM', '16', tMAC, fv, payload, msb, lsb, pad);

// Reconstruction de la trame
var frame = mac.buildFrame();
// => Buffer: 045300045308f1171567a02af6000005be4e

// Chiffrement AES-CMAC
var bufferKey = Buffer.from('10357f020289ad8f512662ba988f1111', 'hex');
var cipheredFrame = mac.encrypt_Frame(frame, bufferKey);
// => Buffer de 16 octets (MAC complet)

// Vérification du tMAC (8 premiers octets)
var isValid = mac.verifyMac(bufferKey);
// => true

Constructeur

new MAC_encrypt(type, name, timestamp, ecuName, dlc, tmac, fv, payload, msb, lsb, pad)

| Paramètre | Type | Description | |-----------|------|-------------| | type | String | Identifiant CAN de la trame (ex: '0x453' ou '453') | | name | String | Nom de la trame (doit contenir Sync, ReSync ou SC_FD) | | timestamp | String | Horodatage de la trame | | ecuName | String | Nom de l'ECU émettrice | | dlc | String/Buffer | Data Length Code | | tmac | String/Buffer | tMAC attendu (8 octets) | | fv | Buffer | FreshValue / compteur anti-rejeu | | payload | Buffer | Données applicatives de la trame | | msb | Buffer | 4 octets MSB du FreshValue complet | | lsb | Buffer | 2 octets LSB du FreshValue complet | | pad | Buffer | Octets de padding |

Méthodes

| Méthode | Description | |---------|-------------| | buildFrame() | Reconstruit le message à chiffrer selon le type de trame | | encrypt_Frame(msg, key) | Calcule le MAC AES-CMAC complet (16 octets) | | verifyMac(key) | Vérifie que le tMAC correspond aux 8 premiers octets du MAC calculé | | KDF(k) | Dérive une clé via Miyaguchi-Preneel (protocole SHE) |

Tests

Les tests sont écrits avec Jest et couvrent 27 cas de test répartis en trois catégories :

Lancer les tests

npm test

Catégories de tests

Construction de trames (buildFrame) — Tests 001 à 006

Vérifient la reconstruction correcte des messages pour chaque type de trame (ReSync, Sync, SC_FD), avec et sans le préfixe 0x sur l'identifiant CAN.

| Test | Description | |------|-------------| | MAC_encrypt-001 | buildFrame ReSync (0x id) | | MAC_encrypt-002 | buildFrame Sync (0x id) | | MAC_encrypt-003 | buildFrame SC_FD (0x type) | | MAC_encrypt-004 | buildFrame ReSync (no 0x type) | | MAC_encrypt-005 | buildFrame Sync (no 0x type) | | MAC_encrypt-006 | buildFrame SC_FD (no 0x type) |

Chiffrement de trames (encrypt_Frame) — Tests 007 à 012

Vérifient que le MAC AES-CMAC calculé correspond aux valeurs attendues pour chaque type de trame.

| Test | Description | |------|-------------| | MAC_encrypt-007 | cipher ReSync frame (0x id) | | MAC_encrypt-008 | cipher ReSync frame (no 0x type) | | MAC_encrypt-009 | cipher Sync frame (0x type) | | MAC_encrypt-010 | cipher Sync frame (no 0x type) | | MAC_encrypt-011 | cipher SC_FD frame (0x type) | | MAC_encrypt-012 | cipher SC_FD frame (no 0x type) |

Vérification de MAC (verifyMac) — Tests 013 à 027

Testent la vérification du tMAC sur des trames réelles capturées (SC_FD, Sync, ReSync) pour différentes ECU (BCM, CDM, ATCU, ADAS, PWT, ECM).

| Test | Description | |------|-------------| | MAC_encrypt-013 | verify MAC for ciphered SC_FD frame | | MAC_encrypt-014 | verify MAC for ciphered Sync frame (CDM) | | MAC_encrypt-015 | verify MAC for ciphered ReSync frame (CDM) | | MAC_encrypt-016 | verify MAC for ciphered SC_FD frame | | MAC_encrypt-017 | verify MAC for ciphered Sync frame (CDM) | | MAC_encrypt-018 | verify MAC for ciphered ReSync frame (CDM) | | MAC_encrypt-019 | verify MAC for ciphered ReSync frame (CDM) | | MAC_encrypt-020 | verify MAC for ciphered Sync frame (CDM) | | MAC_encrypt-021 | verify MAC for ciphered ReSync frame (ADAS) | | MAC_encrypt-022 | verify MAC for ciphered Sync frame (CDM) | | MAC_encrypt-023 | verify MAC for ciphered Sync frame (CDM) | | MAC_encrypt-024 | verify MAC for ciphered Sync frame (ECM) (type 0x) | | MAC_encrypt-025 | verify MAC for ciphered ECM (type 0x) | | MAC_encrypt-026 | verify MAC for ciphered Sync frame (ECM) (type 0x) | | MAC_encrypt-027 | verify MAC for ciphered Sync frame (PWT) #1 (type 0x) |

Structure du projet

MAC_encrypt/
├── MAC_encrypt.js   # Module principal
├── test.js          # Suite de tests Jest (27 tests)
├── package.json     # Métadonnées npm et dépendances
├── LICENSE          # Licence MIT
└── README.md        # Ce fichier

Liens utiles

  • Dépôt Git : https://gitlabee.dt.renault.com/mac/mac_encrypt
  • Wiki : https://gitlabee.dt.renault.com/mac/mac_encrypt/-/wikis/MAC_encrypt
  • Issues : https://gitlabee.dt.renault.com/mac/mac_encrypt/-/issues
  • Spécification SHE AUTOSAR : https://www.autosar.org/standards/classic-platform (SHE - Secure Hardware Extension)
  • AES-CMAC (RFC 4493) : https://datatracker.ietf.org/doc/html/rfc4493
  • Jest : https://jestjs.io/

Auteur

Rémi COHEN-SCALI

Licence

MIT