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

she_encrypt

v2.2.3

Published

Cryptographic function for ciphering SHE commands args (M1-M3/M4-M5)

Readme

SHE_encrypt

License: MIT

Platform: SW1xx Platform: SW2xx Platform: SW4xx Platform: SW5xx

Description

Package NodeJS implémentant le protocole SHE (Secure Hardware Extension) Key Update conforme aux spécifications AUTOSAR. Il permet de calculer les registres de commande SHE (M1/M2/M3 et M4/M5) nécessaires au provisionnement des clés cryptographiques (Kmaster et Kmac) dans les ECU automobiles.

Le calcul repose sur :

  • Miyaguchi-Preneel (fonction de compression pour la dérivation de clés)
  • AES-128 CBC/ECB (chiffrement)
  • AES-CMAC (authentification par MAC)

Composants

| Fichier | Description | |---|---| | SHE_encrypt.js | Classe principale exposant l'API de calcul SHE | | bin/generate_she.js | Commande CLI pour générer les messages SHE | | usage_help.json | Texte d'aide de la CLI (partagé avec les tests) | | test.js | Tests unitaires de la classe SHE_encrypt | | test.ts | Tests d'intégration de la commande generate_she.js |

Registres SHE calculés

Les registres de commande SHE pour le provisionnement de clé sont :

  • M1 = UID | SheID | AuthID
  • M2 = AES_CBC_K1(CID | FID | padding | Knew)
  • M3 = AES-CMAC_K2(M1 | M2)
  • M4 = M1 | AES_ECB_K3(CID | padding)
  • M5 = AES-CMAC_K4(M4)

Où K1 à K4 sont dérivées via Miyaguchi-Preneel à partir de Kmaster/Knew et de constantes SHE.

Installation

npm install

Utilisation

API programmatique

const SHE = require('./SHE_encrypt.js');

// Paramètres
var is_k_mac = true;                                          // true pour Kmac, false pour Kmaster
var k_master = Buffer.from("0153F7000099ED9F320451AA8A7D9707", 'hex');
var key      = Buffer.from("10357F020289AD8F512662BA988F1111", 'hex');
var cid      = 0x200104E;
var channel  = 1;                                             // canal 1 à 5 (pour Kmac uniquement)

var she = new SHE(is_k_mac, k_master, key, cid, channel);

// Résultats
console.log("M1 =", she.M1.toString('hex'));
console.log("M2 =", she.M2.toString('hex'));
console.log("M3 =", she.M3.toString('hex'));
console.log("M4 =", she.M4.toString('hex'));
console.log("M5 =", she.M5.toString('hex'));

Méthodes exposées :

  • KDF_ENC(key) — Dérivation de clé pour le chiffrement
  • KDF_MAC(key) — Dérivation de clé pour le MAC
  • build_M2(cid, key, is_k_mac) — Construction de M2 en clair
  • encrypt_M2(m2, key) — Chiffrement de M2
  • build_M3(m1, m2, key) — Calcul de M3 (CMAC)
  • build_M4(is_k_mac, cid, key) — Construction de M4
  • build_M5(m4, key) — Calcul de M5 (CMAC)
  • keyConfirmation(key) — Confirmation de clé

Ligne de commande

# Afficher l'aide
node ./bin/generate_she.js -h

# Générer un Kmaster (provisionnement de clé maître)
node ./bin/generate_she.js \
  -k A123456789B123456789C123456789D1 \
  -m 1F987654321E987654321D987654321C \
  -c 0x2000001

# Générer un Kmac sur le canal 1
node ./bin/generate_she.js -K \
  -k 123456789B123456789C123456789D12 \
  -m A123456789B123456789C123456789D1 \
  -c 0x2000002 -C 1

# Mode verbeux
node ./bin/generate_she.js -v -K \
  -k 123456789B123456789C123456789D12 \
  -m A123456789B123456789C123456789D1 \
  -c 0x2000002 -C 1

Options de la CLI

| Option | Description | |---|---| | -h, --help | Afficher l'aide | | -v, --verbose | Augmenter la verbosité (cumulable) | | -K, --iskmac | Générer un Kmac au lieu d'un Kmaster | | -k, --key <key> | Clé à provisionner (hex, 128 bits) | | -m, --master <kmaster> | Clé Kmaster d'authentification (hex, 128 bits) | | -c, --cid <cid> | Counter ID (décimal ou hexadécimal avec préfixe 0x) | | -C, --channel <n> | Canal Kmac (1 à 5) |

Exemple de sortie

CID      = 33554433 (0x2000001)
M1       = 00000000000000000000000000000011
M2       = c44f5059d23ce5fd079a19cc8b1b5804aacc41183dc38b140c392f16a21c2a92
M3       = fff0a3eb96f502d96e64edac0bc338a2
M4       = 00000000000000000000000000000011a7e57c5f614167ee29e745c8777632e4
M5       = 8ceef7c0a4aa4bef36762e0de066d8db
M1|M2|M3 = 00000000000000000000000000000011 c44f5059d23ce5fd079a19cc8b1b5804aacc41183dc38b140c392f16a21c2a92 fff0a3eb96f502d96e64edac0bc338a2
M4|M5    = 00000000000000000000000000000011a7e57c5f614167ee29e745c8777632e4 8ceef7c0a4aa4bef36762e0de066d8db

Tests

Les tests utilisent Jest et sont répartis en deux fichiers :

  • test.js — Tests unitaires de la classe SHE_encrypt (KDF, chiffrement, calcul des registres M1-M5, confirmation de clé, cas d'erreur)
  • test.ts — Tests d'intégration de la commande generate_she.js (aide, génération Kmaster/Kmac, canaux, options longues, cas d'erreur CLI)

Exécuter les tests

# Lancer tous les tests avec couverture de code
npm test

# Lancer uniquement les tests unitaires
npx jest test.js

# Lancer uniquement les tests d'intégration
npx jest test.ts

# Lancer un test spécifique
npx jest -t "TSHEEncNom001"

# Debug d'un test
npm run dbgtest

Couverture de code

La couverture est collectée sur SHE_encrypt.js et générée dans le répertoire coverage/. Après exécution des tests, ouvrir coverage/lcov-report/index.html pour consulter le rapport.

Structure du projet

SHE_encrypt/
├── SHE_encrypt.js          # Classe principale
├── bin/
│   └── generate_she.js     # Commande CLI
├── usage_help.json          # Texte d'aide (partagé CLI/tests)
├── test.js                  # Tests unitaires
├── test.ts                  # Tests d'intégration
├── package.json
├── LICENSE
└── coverage/                # Rapports de couverture (généré)

Dépendances

| Package | Rôle | |---|---| | aes-js | Implémentation AES en JavaScript (CBC/ECB) | | node-aes-cmac | Calcul AES-CMAC | | miyaguchipreneel | Fonction de compression Miyaguchi-Preneel | | posix-getopt | Parsing des options CLI (style POSIX) | | printf | Formatage de chaînes (style C) | | jest | Framework de tests |

Liens utiles

Auteur

Rémi COHEN SCALI[email protected]

Licence

Ce projet est distribué sous licence MIT.

Copyright © 2023-2026 RENAULT GROUP