• SecurityAccess 之 KeyGenDll_GenerateKeyEx


      在使用诊断功能时,会涉及SecurityAccess,KeyGenDll_GenerateKeyEx是一种根据seed计算SecurityAccess key的方法,在Vector CANoe提供的Sample Configurations中就有Demo。默认安装位置: C:UsersPublicDocumentsVectorCANoeSample Configurations 11.0.42CANDiagnosticsUDSSystemSecurityAccessSourcesKeyGenDll_GenerateKeyEx

      每个项目都具有独特性,这里根据我的项目实际情况,分享一下KeyGenDll_GenerateKeyEx使用方法:

    代码:

    // KeyGeneration.cpp : Defines the entry point for the DLL application.
    //
    
    #include <windows.h>
    #include "KeyGenAlgoInterfaceEx.h"
    
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
                         )
    {
        return TRUE;
    }
    
    
    
    KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
          const unsigned char*  iSeedArray,     /* 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*           iVariant,       /* Name of the active variant [in] */
          unsigned char*        ioKeyArray,     /* Array for the key [in, out] */
          unsigned int          iKeyArraySize,  /* Maximum length of the array for the key [in] */
          unsigned int&         oSize           /* Length of the key [out] */
          )
    {
        //Copy seed from parameter to a integer
        //Note:The byte order in the seed array is equal to the byte order in the bus message
        unsigned int seed = 0;
        unsigned int key = 0;
        
        seed = seed | ( iSeedArray[3] << 0 );
        seed = seed | ( iSeedArray[2] << 8 );
        seed = seed | ( iSeedArray[1] << 16 );
        seed = seed | ( iSeedArray[0] << 24 );
    
        //begin calculate key form seed 
        if( 0x01 == iSecurityLevel )
        {
            //for security access with Services 0x27 01 -> 0x27 02
            printf("iSecurityLevel is %02X",iSecurityLevel);
            
            //Security algorithm has been deleted
            key = seed;
            
            printf("key is %02X",key);
        }
        else
        {
            key = 0xFFFFFFFF;
            printf("- - - Error ! - - -");
        }
        //end calculate key form 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
        ioKeyArray[3] = key & 0xff;
        ioKeyArray[2] = ( key >> 8) & 0xff;
        ioKeyArray[1] = ( key >> 16) & 0xff;
        ioKeyArray[0] = ( key >> 24) & 0xff;
        printf("ioKeyArray is %02X",ioKeyArray);
          
        oSize=iSeedArraySize;
        
      return KGRE_Ok;
    }
  • 相关阅读:
    【模板】Bellman—Fort 单源最短路径算法
    【模板 && 拓扑】 Dijkstra 单源最短路径算法
    字符序列
    装载问题【回溯法】
    工作分配问题【回溯法】
    『模板』 子集生成
    [Codeforces]852A
    [Codeforces]852I
    [UOJ]#36. 【清华集训2014】玛里苟斯
    [Codeforces]848C
  • 原文地址:https://www.cnblogs.com/zinthewind/p/14173939.html
Copyright © 2020-2023  润新知