Seed and Key Algorithm
- Updated2025-10-13
- 3 minute(s) read
To restrict access to an ECU, you can add a defined login mechanism to ECU software. The Association for Standardization of Automation and Measuring Systems (ASAM) defines this seed, which may be stored in the A2L file. A typical login mechanism may happen as follows:
- Connect to the ECU.
- Exchange station identifications.
- Get the seed for the key.
- Calculate the key using a seed and key DLL as ASAM defines.
- Unlock the ECU protection by sending the calculated key.
ASAM AE Common defines the seed and key algorithm in the Seed and Key and Checksum Calculation API Version 1.0. The specification defines the Win32 APIs for seed and key calculation and checksum calculation.
Definition for Seed and Key Algorithm
Function name: ASAP1A_CCP_ComputeKeyFromSeed
| Parameter | Description |
|---|---|
| 1 | Pointer to the seed data, retrieved from the ECU GET_SEED command. |
| 2 | Seed data size in number of bytes. |
| 3 | Pointer to key data, returning the calculated key. |
| 4 | Key data size in number of bytes. |
| 5 | Key data size in number of bytes. |
The calling convention is as defined in the WIN32 API Specification for ASAP1b, section 2.4.
Seed and Key Example
The following example shows a possible header file for a library for key calculation.
/*
// Header file for ASAP1a CCP V2.1 Seed and Key Algorithm
*/
#ifndef _SEEDKEY_H_
#define _SEEDKEY_H_
#ifndef DllImport
#define DllImport __declspec( dllimport )
#endif
#ifndef DllExport
#define DllExport __declspec( dllexport )
#endif
#ifdef SEEDKEYAPI_IMPL // only defined by implementor of SeedKeyApi
#define SEEDKEYAPI DllExport __cdecl
#else
#define SEEDKEYAPI DllImport __cdecl
#endif
#ifdef __cplusplus
extern "C" {
#endif
BOOL SEEDKEYAPI ASAP1A_CCP_ComputeKeyFromSeed (BYTE *Seed,
unsigned short SizeSeed, BYTE *Key, unsigned short MaxSizeKey,
unsigned short *SizeKey);
// Seed: Pointer to seed data
// SizeSeed:Size of seed data (length of "Seed")
// Key: Pointer, where DLL should insert the calculated key data.
// MaxSizeKey: Maximum size of "Key".
// SizeKey: Should be set from DLL corresponding to the number of data
// inserted to "Key" (at most "MaxSizeKey")
// Result: The value FALSE (= 0) indicates that the key could not be
// calculated from seed data (for example, "MaxSizeKey" is too small).
// TRUE (!= 0) indicates success of key calculation.
#ifdef __cplusplus
}
#endif
#endif //_SEEDKEY_H_Checksum Algorithm
ASAM proposed a WIN32 API function to have a common interface to implement the checksum algorithms for verifying ECU calibration and program data. For details, refer to the ASAM Seed and Key and Checksum Calculation API Version 1.0.
Definition for a Checksum Algorithm
Function name: BOOL CalcChecksum(struct TRange *ptr, int nRanges, BYTE *pnChecksum, int *pnSignificant, WORD nFlags)
| Parameter | Description |
|---|---|
| 1 | Pointer to an array of ranges, stored in structures of type TRange. |
| 2 | Number of ranges stored in the array that parameter 1 points to. |
| 3 | Pointer to a byte array where the checksum must be stored. The DLL writes a maximum of 8 bytes, so the caller should reserve space for 8 bytes of data. |
| 4 | Length of actually calculated checksum (1...8). |
| 5 |
Flag field for commanding how the algorithm works. Currently, only bit 0 is defined:
All other bits are reserved and should be set to 0. |
TRange is defined as follows:
struct TRange
{
char *pMem;
unsigned long lLen;
} The calling convention is as defined in the WIN32 API Specification for ASAP1b, section 2.4.
Checksum Algorithm Example
The following example shows a possible header file for a library for checksum calculation.
/*
// checksum.h
// Header file for Checksum Algorithm
*/
#ifndef _CHECKSUM_H
#define _CHECKSUM_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef DllImport
#define DllImport __declspec( dllimport )
#endif
#ifndef DllExport
#define DllExport __declspec( dllexport )
#endif
#ifdef CHECKSUMAPI_IMPL // only defined by implementor of ChecksumApi
#define CHECKSUMAPI DllExport __cdecl
#else
#define CHECKSUMAPI DllImport __cdecl
#endif
struct TRange
{
char *pMem;
unsigned long lLen;
};
#ifdef __cplusplus
extern "C" {
#endif
BOOL CHECKSUMAPI CalcChecksum (struct TRange *ptr,
int nRanges,
BYTE *pnChecksum,
int *pnSignificant,
WORD nFlags);
#ifdef __cplusplus
}
#endif
#endif //_CHECKSUM_H