Merge pull request #29 from VladLupashevskyi/egs52

Introduce seed key for EGS52
This commit is contained in:
JinGen Lim 2023-08-09 13:37:10 +08:00 committed by GitHub
commit df1f8256f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
namespace UnlockECU
{
/// <summary>
/// Implementation of VGSSecurityAlgo for 2 bytes seed/key pairs
/// </summary>
class VGSSecurityAlgo2Bytes : SecurityProvider
{
public override bool GenerateKey(byte[] inSeed, byte[] outKey, int accessLevel, List<Parameter> 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";
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
namespace UnlockECU
{
/// <summary>
/// Implementation of extended VGS Algo with different keys for multiplication and xor
/// </summary>
class VGSSecurityAlgoExt : SecurityProvider
{
public override bool GenerateKey(byte[] inSeed, byte[] outKey, int accessLevel, List<Parameter> 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";
}
}
}

View File

@ -11787,6 +11787,59 @@
}
]
},
{
"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": "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",
"Aliases": [],