//***************************************************************************** /// @file seedNKeyXcpWin.c /// @author Alex Lunkenheimer (ETAS/PAC-Lr) /// @responsible author /// @brief DLL-Main for Seed'n Key for XCP /// @history 2002-09-16,Lr: - draft /// 2003-02-07,Lr: - DLL-API using extern "C" /// - adapted privileges to XCP-Spec V1.0,Rev22 //***************************************************************************** //***************************************************************************** // includes //***************************************************************************** #include #include "seedNKeyDiag.h" //***************************************************************************** // variables //***************************************************************************** //***************************************************************************** // prototypes //***************************************************************************** //***************************************************************************** /// @fn DllMain ... Windows DLL entrance point //***************************************************************************** KEYGEN_API 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 char Key[4] = { 0,0,0,0 }; unsigned char Seed[4]; Seed[0] = ipSeedArray[0]; Seed[1] = ipSeedArray[1]; Seed[2] = ipSeedArray[2]; Seed[3] = ipSeedArray[3]; //begin calculate key from seed------------------------------------------------------------ switch (iSecurityLevel) { case 0x01://for security access with Services 0x27 01 ->0x27 02 break; case 0x03://for security access with Services 0x27 03 -> 0x27 04 break; case 0x05://for security access with Services 0x27 05 -> 0x27 06 break; case 0x09://for security access with Services 0x27 09 ->0x27 0A break; default:break; } //end calculate key from seed------------------------------------------------------------ //Copy key to the output buffer //Note: The first byte of the key array will be the first key byte of the bus message iopKeyArray[3] = Key[3]; iopKeyArray[2] = Key[2]; iopKeyArray[1] = Key[1]; iopKeyArray[0] = Key[0]; //setting length of key oActualKeyArraySize = 4; return KGRE_Ok; }