From 7651faac72f7d64207c67f8d5278b45c29c402ce Mon Sep 17 00:00:00 2001 From: Vlad Lupashevskyi Date: Tue, 8 Aug 2023 22:25:13 +0200 Subject: [PATCH 1/2] Introduce seed key for EGS52 --- .../Security/VGSSecurityAlgo2Bytes.cs | 32 +++++++++++++++++++ UnlockECU/db.json | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 UnlockECU/UnlockECU/Security/VGSSecurityAlgo2Bytes.cs diff --git a/UnlockECU/UnlockECU/Security/VGSSecurityAlgo2Bytes.cs b/UnlockECU/UnlockECU/Security/VGSSecurityAlgo2Bytes.cs new file mode 100644 index 0000000..d47061d --- /dev/null +++ b/UnlockECU/UnlockECU/Security/VGSSecurityAlgo2Bytes.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace UnlockECU +{ + /// + /// Implementation of VGSSecurityAlgo for 2 bytes seed/key pairs + /// + class VGSSecurityAlgo2Bytes : SecurityProvider + { + public override bool GenerateKey(byte[] inSeed, byte[] outKey, int accessLevel, List parameters) + { + byte[] cryptoKeyBytes = GetParameterBytearray(parameters, "K"); + uint cryptoKey = cryptoKeyBytes[1] | ((uint)cryptoKeyBytes[0]) << 8; + if ((inSeed.Length != 2) || (outKey.Length != 2)) + { + return false; + } + + uint seed = inSeed[0] | ((uint)inSeed[1]) << 8; + uint seedKey = cryptoKey * (cryptoKey ^ seed); + + outKey[0] = (byte)(seedKey >> 8); + outKey[1] = (byte)seedKey; + return true; + } + public override string GetProviderName() + { + return "VGSSecurityAlgo2Bytes"; + } + } +} diff --git a/UnlockECU/db.json b/UnlockECU/db.json index dad935b..984e218 100644 --- a/UnlockECU/db.json +++ b/UnlockECU/db.json @@ -11787,6 +11787,38 @@ } ] }, + { + "EcuName": "EGS52", + "Aliases": [], + "AccessLevel": 5, + "SeedLength": 4, + "KeyLength": 4, + "Provider": "VGSSecurityAlgo", + "Origin": "EGS52_27_05@VladLupashevskyi-@rnd-ash", + "Parameters": [ + { + "Key": "K", + "Value": "5AA5A5A5", + "DataType": "ByteArray" + } + ] + }, + { + "EcuName": "EGS52", + "Aliases": [], + "AccessLevel": 1, + "SeedLength": 2, + "KeyLength": 2, + "Provider": "VGSSecurityAlgo2Bytes", + "Origin": "EGS52_27_01_27_02@VladLupashevskyi-@rnd-ash", + "Parameters": [ + { + "Key": "K", + "Value": "5AA5", + "DataType": "ByteArray" + } + ] + }, { "EcuName": "Subaru_2EE2", "Aliases": [], From f675456c0b803a1f92dbd311fbc489ab3c32cfcc Mon Sep 17 00:00:00 2001 From: Vlad Lupashevskyi Date: Tue, 8 Aug 2023 23:19:30 +0200 Subject: [PATCH 2/2] Introduce seed key for EGS53 --- .../UnlockECU/Security/VGSSecurityAlgoExt.cs | 35 +++++++++++++++++++ UnlockECU/db.json | 21 +++++++++++ 2 files changed, 56 insertions(+) create mode 100644 UnlockECU/UnlockECU/Security/VGSSecurityAlgoExt.cs diff --git a/UnlockECU/UnlockECU/Security/VGSSecurityAlgoExt.cs b/UnlockECU/UnlockECU/Security/VGSSecurityAlgoExt.cs new file mode 100644 index 0000000..3de80ef --- /dev/null +++ b/UnlockECU/UnlockECU/Security/VGSSecurityAlgoExt.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +namespace UnlockECU +{ + /// + /// Implementation of extended VGS Algo with different keys for multiplication and xor + /// + class VGSSecurityAlgoExt : SecurityProvider + { + public override bool GenerateKey(byte[] inSeed, byte[] outKey, int accessLevel, List parameters) + { + byte[] cryptoKeyMultBytes = GetParameterBytearray(parameters, "M"); + uint cryptoKeyMult = BytesToInt(cryptoKeyMultBytes, Endian.Big); + + byte[] cryptoKeyXorBytes = GetParameterBytearray(parameters, "X"); + uint cryptoKeyXor = BytesToInt(cryptoKeyXorBytes, Endian.Big); + + if ((inSeed.Length != 4) || (outKey.Length != 4)) + { + return false; + } + + long seed = BytesToInt(inSeed, Endian.Big); + long seedKey = cryptoKeyMult * (cryptoKeyXor ^ seed); + + IntToBytes((uint)seedKey, outKey, Endian.Big); + return true; + } + public override string GetProviderName() + { + return "VGSSecurityAlgoExt"; + } + } +} diff --git a/UnlockECU/db.json b/UnlockECU/db.json index 984e218..c58c1fd 100644 --- a/UnlockECU/db.json +++ b/UnlockECU/db.json @@ -11818,6 +11818,27 @@ "DataType": "ByteArray" } ] + }, + { + "EcuName": "EGS53", + "Aliases": [], + "AccessLevel": 1, + "SeedLength": 4, + "KeyLength": 4, + "Provider": "VGSSecurityAlgoExt", + "Origin": "EGS53_27_05@VladLupashevskyi-@rnd-ash", + "Parameters": [ + { + "Key": "X", + "Value": "6BB6B6B6", + "DataType": "ByteArray" + }, + { + "Key": "M", + "Value": "49949494", + "DataType": "ByteArray" + } + ] }, { "EcuName": "Subaru_2EE2",