You are currently viewing 一文了解TSMaster中Seed&key的两种处理方法

Learn about the two methods of handling Seed&key in TSMaster in one article

overviewPreface

During the UDS diagnostic process, it will involve the security access problem, which is often referred to as Seed&Key. TSMaster provides two Seed&Key handling methods: the first one is to load the DLL file directly; the second one is to add the security algorithm directly in TSMaster's compiler.

Loading external Seed&Key DLLs

TSMaster diagnostic module supports loading Seed&Key algorithm through dll, which is compatible with the calculation interface of mainstream tools, as shown in the following figure:

Select Open Parser Path in TSMaster Tools->System Information->python Environment Settings;

[1] Load DLL

[2] Delete DLL

【3】 DLL Verifier, through this button, users can judge whether the dll interface they loaded is correct or not, and whether the algorithm meets the design requirements. As shown in the figure below:

As shown in the interface above, after the user selects the Level of Seed, input the value of Demo Seed and click GenKey to judge. If the interface of the DLL is unified with the interface defined in the template, a message will be output: Generate Key Success, and then the user will compare the key value with the target value to further confirm whether the algorithm in the DLL meets the design requirements. 

[4] Open the path where the Seed&Key interface project is located in the TSMaster installation directory. Users can copy this project to add their own Seed&Key algorithms.

"Default SeedKey function interface

Currently, in order to be loaded directly by the diagnostic module of TSMaster, the DLL must implement one of the following three function interfaces: 

[1] Interface 1: 

unsigned int GenerateKeyEx( const unsigned char* ipSeedArray, /* Array for the seed [in] */ unsigned int iSeedArraySize, /* Length of the array for the seed [in] */ const unsigned int iSecurityLevel, /* Security level [in] */ const char* ipVariant, /* Name of the active variant [in] */ unsigned char* iopKeyArray, /* Array for the key [in, out] */ unsigned int iMaxKeyArraySize, /* Maximum length of the array for the key [in] */ unsigned int& oActualKeyArraySize); /* Length of the key [out] */ unsigned int iMaxKeyArraySize, /* Maximum length of the array for the key [in] */ 

[2] Interface 2: 

unsigned int GenerateKeyExOpt( const unsigned char* ipSeedArray, /* Array for the seed [in] */ unsigned int iSeedArraySize, /* Length of the array for the seed [in] */ const unsigned int iSecurityLevel, /* Security level [in] */ const char* ipVariant, /* Name of the active variant [in] */ const char* iPara , /* */ unsigned char* iopKeyArray, /* Array for the key [in, out] */ unsigned int iMaxKeyArraySize, /* Maximum length of the array for the key [in] */ unsigned int& oActualKeyArraySize) /* Length of the key [out] */ 

[3] Interface 3:

bool ASAP1A_CCP_ComputeKeyFromSeed( const unsigned char* ipSeedArray, /* Array for the seed [in] */ unsigned short iSeedArraySize, /* Length of the array for the seed [in] */ unsigned char* iopKeyArray, /* Array for the key [in, out] */ unsigned short iMaxKeyArraySize, /* Maximum length of the array for the key [in] */ unsigned short* opSizeKey) /* Length of the key [out] */ 

The user's DLL can be loaded directly into the TP layer module as long as it implements any of the above function interfaces. If the loading fails, check the following conditions: 

1. whether it is released in Release mode, if it is in Debug mode, the above failures often occur. 

2. Whether it is released on x86 platform, currently TSMaster supports X86 version, the DLL used for debugging must be in X86 mode.

"How to be compatible with other function interfaces

In daily use, it often happens that the user has already developed a dll, but if the interface of the dll is not any of the three mentioned above, it can not be directly loaded into the diagnostic module of TSMaster. For this situation, the following solution is recommended to solve this problem:

The following is a practical example to explain how to be compatible with the user's existing DLL file. 

1. the user's existing DLL with the name UserSeedKey.dll. the API functions inside this function are: 

The function void GetKeyFromSeed01(byte* ASeed, byte* AKey) is called when Seed level is 1; 

The function void GetKeyFromSeed03(byte* ASeed, byte* AKey) is called when the Seed level is 3; 

The function void GetKeyFromSeed11(byte* ASeed, byte* AKey) is called when the Seed level is 11; 

This dll does not support the above default loading interface and cannot be loaded directly into TSMaster for use. Therefore, these DLLs need to be wrapped one more layer before they can be loaded into the diagnostic module of TSMaster. 

2. Select the GenerateKeyEx template project provided in the TSMaster installation directory, and call the function interfaces of the above DLL in that project. The basic idea is: 

Use Loadlibrary to dynamically user existing dlls. 

The GetProcAddress function is used to dynamically obtain the actual function pointer used to compute the Key based on the Level parameter passed in. 

➢ If the acquisition of the function pointer is successful, the Seed value is transferred using the function pointer and the corresponding Key value is calculated. 

The detailed call example function is shown below:

3. After the GenerateKeyEx project is finished, TSMaster loads the dll of GenerateKeyEx directly, it should be noted that users need to copy the existing UserSeedKey.dll to the root directory of TSMaster or the directory where GenerateKeyEx.dll is located. If you don't copy it, GenerateKeyEx.dll will fail to find the dependency dll when executing and the unlocking will fail. 

Summary:  

In the TSMaster installation directory, there are template projects that encapsulate the Seed&Key algorithm. For example, GenerateKeyEx, GenerateKeyExOpt ASAP1A_CCP_ComputeKeyFromSeed, user can get the dll function which can be loaded directly based on this template project. 

There are also projects for secondary dll wrappers, such as GenerateKeyEx_Wrapper_Demo, which demonstrates how to generate a dll that can be directly loaded into the TSMaster Diagnostics Module based on the packaging of the already existing SeedKey algorithm library.

II. Using the built-in algorithm editor

The basic steps are shown below:

Caveats:

1】 Interface of algorithmic function, TSMaster currently provides the most commonly used form of interface, if the user has their own special form of interface, which can not be covered, please contact TOSUN to add this interface to the options.

[2] All interface functions define a return value of s32. This constraint is added to increase the rigor of the function. A return value of 0 indicates success, while other values have corresponding error codes. When editing the code, the user must not forget to enter the return value in the last line, otherwise the system will consider that the algorithm fails to execute after the function is executed, and will not be executed in the future. As shown below:

[3] After adding the algorithm, click OK to exit. the TSMaster built-in compiler automatically interprets the algorithm and prepares it for use in performing the diagnostic.

If you need demos or ask other technical questions, you can leave a message on the official website. 

For inquiries, e-mail: sales@tosunai.cn

Service Hotline: 021-59560506

The latest version of TSMaster software is available for free download at: http://www.tosun.tech/TOSUNSoftware/TSMaster_Setup_beta.exe

发表回复