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_decrypt

v1.3.0

Published

Pure JavaScript implementation for deciphering SHE arguments (M1, M2, etc)

Readme

SHE_decrypt

License: MIT

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

[TOC]

Description

SHE_decrypt est une implémentation pure JavaScript pour le déchiffrement des arguments des commandes SHE (Secure Hardware Extension) utilisées dans le provisionnement des clés MAC pour les trames CAN/Ethernet dans le cadre du protocole AUTOSAR.

Ce module permet de :

  • Déchiffrer le registre M2 d'une commande SHE de provisionnement de clés
  • Extraire le CID (Counter ID) d'un message SHE déchiffré
  • Extraire le FID (Flag ID) d'un message SHE déchiffré
  • Extraire la clé provisionnée (KEY) du registre M2
  • Extraire le canal (Channel) des registres de la commande SHE
  • Vérifier l'intégrité M3 via AES-CMAC
  • Vérifier les registres M4/M5 pour la validation complète du provisionnement

L'implémentation repose sur la fonction de compression Miyaguchi-Preneel fournie par le module npm miyaguchipreneel, le chiffrement AES-CBC via aes-js, et AES-CMAC via node-aes-cmac.

Prérequis

Installation

npm install

Dépendances

| Module | Version | Description | |--------------------|-----------|--------------------------------------------------| | aes-js | ^3.1.2 | Implémentation AES en JavaScript pur | | miyaguchipreneel | ^1.1.4 | Fonction de compression Miyaguchi-Preneel | | posix-getopt | ^1.2.1 | Parsing des options en ligne de commande | | printf | ^0.6.1 | Formatage de chaînes style printf | | she_encrypt | ^2.1.0 | Module compagnon pour le chiffrement SHE | | jest | ^29.7.0 | Framework de tests |

Utilisation

API JavaScript

SHE_decrypt expose une API utilisant node:Buffer pour une manipulation directe des trames CAN/Ethernet :

const she = require('she_decrypt');

var frameBuf = Buffer.from('<votre trame CAN en hexadécimal>', 'hex');
var frameKey = Buffer.from('<votre clé Kmaster en hexadécimal>', 'hex');

var she_decrypt = new she();

// Déchiffrer le registre M2
var decM2 = she_decrypt.decrypt_M2(frameBuf, frameKey);

// Extraire les informations du message SHE
var cid  = she_decrypt.getCID(decM2);     // Counter ID
var fid  = she_decrypt.getFID(decM2);     // Flag ID
var key  = she_decrypt.getKEY(decM2);     // Clé provisionnée
var chan = she_decrypt.getChannel(frameBuf); // Canal (CAN/Ethernet)

// Vérifier l'intégrité M3 (M2 chiffré) avec la clé d'authentification (Kmaster)
var m3valid = she_decrypt.check_M3(frameKey, M1, M2, M3);

Ligne de commande

Le script bin/she_decrypt permet le déchiffrement en ligne de commande :

she_decrypt: usage: she_decrypt [OPTIONS] [ARGUMENTS]

    Analyse les trames CAN/Ethernet de provisionnement et extrait les
    messages SHE pour les déchiffrer.

    OPTIONS:
       [-v|--verbose=[<integer>]]  Mode verbeux (niveau de détail).
       [-h|--help]                 Afficher ce message d'aide.
       [-c|--cid]                  Afficher le CID du message SHE.
       [-f|--fid]                  Afficher le FID du message SHE.
       [-C|--channel]              Afficher le canal du message SHE.

    ARGUMENTS:
       [-m|--msg=[<SHEmsg>]]       Message SHE à déchiffrer.
       [-M|--msg-file=[<SHEfile>]] Fichier contenant le message SHE à
                                   déchiffrer. Si '-', lit sur STDIN
                                   (comportement par défaut).
       [-K|--Kmaster=[<key>]]      Clé Kmaster pour le déchiffrement.
                                   Valeur par défaut :
                                     0153F7000099ED9F320451AA8A7D9707

Copyright © 2023-2025 RENAULT GROUP / Rémi COHEN SCALI <[email protected]>

Exemples

Déchiffrer un message depuis STDIN :

cat tests/msg.txt | ./bin/she_decrypt

Déchiffrer avec affichage du CID et FID :

cat tests/msg.txt | ./bin/she_decrypt -cf
# CID = 0x2000085

Déchiffrer un fichier directement :

./bin/she_decrypt -M tests/msg.txt

Déchiffrer avec options longues et mode verbeux :

./bin/she_decrypt --verbose --cid --fid --msg-file tests/msg2.txt

Tests

Les tests sont exécutés avec Jest :

npm test

Structure des tests

Les tests sont organisés en deux suites dans le répertoire tests/ :

| Fichier | Type | Nombre | Description | |-----------------------|-----------|--------|------------------------------------------------------| | nominal.test.ts | Nominaux | 33 | Tests de bon fonctionnement | | error.test.ts | Erreurs | 10 | Tests de gestion des erreurs (M4/M5 invalides) |

Tests nominaux (TSDECNomXXX)

Les tests nominaux couvrent les scenarii suivants :

  • Affichage de l'aide : options courtes (-h) et longues (--help)
  • Déchiffrement via STDIN : messages lus depuis msg.txt et msg2.txt
  • Déchiffrement via fichier : option -M / --msg-file
  • Extraction CID/FID : options courtes (-cf) et longues (--cid --fid)
  • Mode verbeux : combinaisons avec -v / --verbose
  • Validation M4/M5 : vérification des registres d'intégrité

Tests d'erreur (TSDECErrXXX)

Les tests d'erreur valident la gestion des cas suivants :

  • Registre M4 invalide lors du déchiffrement
  • Registre M5 invalide lors du déchiffrement
  • Combinaisons M4/M5 invalides avec différents fichiers de messages

Fichiers de données de test

# SHE 1 Prov (M1/M2/M3) EVC
00000000000000000000000000000011e9550f568a7cb43c8e82fc97f09ea71d63ca54eeaff2963a95fa68d64833950a17ad655772b0c644632c855c0da059aa
00000000000000000000000000000041f2d9f8203a15339a63f8d3a649c687b397f25c4d4c84c3800daa5fc684e081979469a496ea1908b9a643e036f50176b6
0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750
00000000000000000000000000000041d0712612d44d059fd935ade25c1425dd8f6ff806fb9977181489902088883a5d7283f224c7e7df8f6c5a906ba932131a
00000000000000000000000000000041d0712612d44d059fd935ade25c1425dd8f6ff806fb9977181489902088883a5d7283f224c7e7df8f6c5a906ba932131a
# SHE 1 Prov (M1/M2/M3) EVC
00000000000000000000000000000011e9550f568a7cb44c8e82fc97f09ea71d63ca54eeaff2963a95fa68d64833950a17ad655772b0c644632c855c0da059aa
00000000000000000000000000000041f2d9f8203a1533aa63f8d3a649c687b397f25c4d4c84c3800daa5fc684e081979469a496ea1908b9a643e036f50176b6

Liens utiles

Licence

Ce projet est sous licence MIT.

Copyright © 2023-2025 Rémi COHEN-SCALI

Auteur

Rémi COHEN SCALI — [email protected] FID = 0 Kmaster: 0f90af60245edfd794c4e606202371ae CID = 0x2000087 FID = 2 Kmac: ed28a6fbae79f25c17112917711a54ad

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/all_mac/SHE_decrypt$ cat tests/msg2.txt | ./bin/she_decrypt -cf CID = 0x200001e FID = 0 Kmaster: c85c499d7ed56116302371372834c3ae CID = 0x2000020 FID = 2 Kmac: 99900b0679387f91ea4db0119e07979a

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/all_mac/SHE_decrypt$ cat tests/msg3.txt | ./bin/she_decrypt -cf she_decrypt: error: SHE message for Kmac was not correctly deciphered !

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/all_mac/SHE_decrypt$ cat tests/msg_error.txt | ./bin/she_decrypt -cf she_decrypt: error: SHE message for Kmaster was not correctly deciphered ! she_decrypt: error: SHE message for Kmac was not correctly deciphered !

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/all_mac/SHE_decrypt$

</details>

<details><summary>Usage examples</summary>

Here is the deciphering of the examples SHE msgs generated in the README.md of SHE_encrypt module. The messages were generated with the following commands:

```bash
./bin/generate_she.js -k A123456789B123456789C123456789D1 -m 1F987654321E987654321D987654321C -c 0x2000001
./bin/generate_she.js -K -k 123456789B123456789C123456789D12 -m A123456789B123456789C123456789D1 -c 0x2000002 -C 1
./bin/generate_she.js -K -k 23456789B123456789C123456789D123 -m A123456789B123456789C123456789D1 -c 0x2000003 -C 2
./bin/generate_she.js -K -k 3456789B123456789C123456789D1234 -m A123456789B123456789C123456789D1 -c 0x2000004 -C 3
./bin/generate_she.js -K -k 456789B123456789C123456789D12345 -m A123456789B123456789C123456789D1 -c 0x2000005 -C 4
./bin/generate_she.js -K -k 56789B123456789C123456789D123456 -m A123456789B123456789C123456789D1 -c 0x2000006 -C 5

and produced the following SHE messages:

00000000000000000000000000000011c44f5059d23ce5fd079a19cc8b1b5804aacc41183dc38b140c392f16a21c2a92fff0a3eb96f502d96e64edac0bc338a2
00000000000000000000000000000041eeb96ef0669d947bdb5986718728728067125e06117dc0f61318952c008f7e96546a16ca23f1e3b890c74cb7a57840d4
00000000000000000000000000000051d719bb4cd7ee7466235668e914c8da40db467e3ab4738cbc0b3e9b4f2e32605bce732465323c03b7df4380776c05f6e4
00000000000000000000000000000061721fddd669375ee9a4102c756470f45718e8a40ff19995324a33af0b1ed5959de73a7ceffb2f30de4f7a94a68826e5b9
00000000000000000000000000000071d22671dc00fcc446d965a621af39c29aac811e52c989b47307377b9eaa6242dda137c4c9c0fdc04daa949bd62c5230a9
0000000000000000000000000000008114d7f1abf977ced2a85d1bfbfae1e9f22eea974476f58cec023ca846017df276a5cd817929cdec2e64ed3dc4c7e4e974

The commands for deciphering these messages are shown here after:

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "00000000000000000000000000000011c44f5059d23ce5fd079a19cc8b1b5804aacc41183dc38b140c392f16a21c2a92fff0a3eb96f502d96e64edac0bc338a2" | ./bin/she_decrypt -cf -K 1F987654321E987654321D987654321C
CID = 0x2000001
FID = 0
Kmaster: a123456789b123456789c123456789d1

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "00000000000000000000000000000041eeb96ef0669d947bdb5986718728728067125e06117dc0f61318952c008f7e96546a16ca23f1e3b890c74cb7a57840d4" | ./bin/she_decrypt -cfC -K A123456789B123456789C123456789D1
CID = 0x2000002
FID = 2
Channel = 1
Kmac: 123456789b123456789c123456789d12

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "00000000000000000000000000000051d719bb4cd7ee7466235668e914c8da40db467e3ab4738cbc0b3e9b4f2e32605bce732465323c03b7df4380776c05f6e4" | ./bin/she_decrypt -cfC -K A123456789B123456789C123456789D1
CID = 0x2000003
FID = 2
Channel = 2
Kmac: 23456789b123456789c123456789d123

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "00000000000000000000000000000061721fddd669375ee9a4102c756470f45718e8a40ff19995324a33af0b1ed5959de73a7ceffb2f30de4f7a94a68826e5b9" | ./bin/she_decrypt -cfC -K A123456789B123456789C123456789D1
CID = 0x2000004
FID = 2
Channel = 3
Kmac: 3456789b123456789c123456789d1234

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "00000000000000000000000000000071d22671dc00fcc446d965a621af39c29aac811e52c989b47307377b9eaa6242dda137c4c9c0fdc04daa949bd62c5230a9" | ./bin/she_decrypt -cfC -K A123456789B123456789C123456789D1
CID = 0x2000005
FID = 2
Channel = 4
Kmac: 456789b123456789c123456789d12345

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ echo "0000000000000000000000000000008114d7f1abf977ced2a85d1bfbfae1e9f22eea974476f58cec023ca846017df276a5cd817929cdec2e64ed3dc4c7e4e974" | ./bin/she_decrypt -cfC -K A123456789B123456789C123456789D1
CID = 0x2000006
FID = 2
Channel = 5
Kmac: 56789b123456789c123456789d123456

Another way of deciphering all these messages (contained in the tests/msgsw500.txt file) is through a file containing all messages. Then use:

a047461@FRUH112777 MINGW64 ~/OneDrive - Alliance/Sources/MAC/export/repos/all_mac/SHE_decrypt$ cat tests/msgsw500.txt | ./bin/she_decrypt -cfC -K 1F987654321E987654321D987654321C
CID = 0x2000001
FID = 0
Kmaster: a123456789b123456789c123456789d1
CID = 0x2000002
FID = 2
Channel = 1
Kmac: 123456789b123456789c123456789d12
CID = 0x2000003
FID = 2
Channel = 2
Kmac: 23456789b123456789c123456789d123
CID = 0x2000004
FID = 2
Channel = 3
Kmac: 3456789b123456789c123456789d1234
CID = 0x2000005
FID = 2
Channel = 4
Kmac: 456789b123456789c123456789d12345
CID = 0x2000006
FID = 2
Channel = 5
Kmac: 56789b123456789c123456789d123456

# or by providing the file on the command line:
# ./bin/she_decrypt -cfC -K 1F987654321E987654321D987654321C -M tests/msgsw500.txt

The tool find a Kmaster as the first message, decipher it and get the key for deciphering all others. Each time it find a Kmaster it try to use it for further messages.

For testing the SHE_decrypt.js component and script, use

rcoscali@ubuntu-lx-23-10:~/Sources/she_decrypt$ npm test

> [email protected] test
> jest --colors --json > results.json

 PASS  ./test.js
 PASS  tests/nominal.test.ts

Test Suites: 2 passed, 2 total
Tests:       31 passed, 31 total
Snapshots:   0 total
Time:        2.13 s, estimated 3 s
Ran all test suites.
rcoscali@ubuntu-lx-23-10:~/Sources/she_decrypt$