一文了解TSMaster中Seed和key的两种处理方法

在uds诊断过程中,会涉及到安全访问的问题,也就是常说的seed&key。tsmaster中提供了两种 seed&key 的处理方法:第一种是直接加载dll文件;第二种是直接在tsmaster的编译器中直接添加安全算法。

加载外部 seed&key dll
tsmaster 诊断模块支持通过 dll 载入 seed&key 算法,该算法 dll 跟主流工具的计算接口兼容,接口定义如下图所示:
dll 加载界面如下图所示:
【1】 加载 dll
【2】 删除 dll
【3】 dll 校验器,通过此按钮,用户可以判断自己加载的 dll 接口是否正确,算法是否符合设计要求。如下图所示:
如上图所示界面,用户选择 seed 的 level 过后,输入 demo seed 值,点击 genkey 进行判断。如果该 dll 接口跟模板定义接口统一,则会输出提示信息:generate key success,然后用户根据 key 值跟目标值对比,进一步确认dll 中的算法是否符合设计要求。
【4】 打开 tsmaster 安装目录下 seed&key 接口工程所在的路径。用户可以拷贝该工程添加自己的 seed&key 算法。

默认seedkey函数接口
目前,要想被 tsmaster 的诊断模块直接加载,该 dll 必须实现如下三种函数接口中的一种:
【1】 接口 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] */
【2】 接口 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】 接口 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] */
用户的 dll 只要实现了上述任意一种函数接口,即可直接加载到 tp 层模块中。如果出现加载失败,主要检查如下情况:
1. 是否用 release 模式发布,如果是 debug 模式,常常会有以上失败的情况出现。
2. 是否采用 x86 平台发布,目前 tsmaster 为支持 x86 的版本,用来调试的 dll 也必须为x86 模式。

如何兼容其他函数接口
日常使用中,经常出现用户已经开发好了 dll,如果该 dll的接口不是上述三种中的任何一种,就无法直接加载到 tsmaster 的诊断模块中。对于这种情况,推荐采用如下方案来解决此问题:
下面以一个实际的实例来讲解如何兼容用户现有的 dll 文件。
1. 用户现有的 dll,名称为 userseedkey.dll。该函数内部的 api 函数有:
➢ seed 等级为 1 的时候,调用函数 void getkeyfromseed01(byte* aseed, byte* akey);
➢ seed 等级为 3 的时候,调用函数 void getkeyfromseed03(byte* aseed, byte* akey);
➢ seed 等级为 11 的时候,调用函数 void getkeyfromseed11(byte* aseed, byte* akey);
该 dll 不支持上述默认加载接口,无法直接加载到 tsmaster 中使用。因此,需要把这些 dll 再包装一层,才能载入到 tsmaster 的诊断模块中。
2. 选择 tsmaster 安装目录中提供的 generatekeyex 的模板工程,在该工程中调用上述 dll的函数接口。基本思路是:
➢ 采用 loadlibrary 动态用户现有的 dll。
➢ 根据传入的 level 参数,采用 getprocaddress 函数动态获取实际的用于计算 key 的函数指针。
➢ 如果获取函数指针成功,则使用该函数指针传输 seed 值,并计算对应的 key 值。
详细调用示例函数如下图所示:
3. 该 generatekeyex 工程开发结束后,tsmaster 直接加载 generatekeyex 所在的 dll。需要注意的是,用户需要把现有的userseedkey.dll 拷贝到tsmaster 根目录或者generatekeyex.dll 所在的目录。如果不拷贝过去,generatekeyex.dll 执行的时候会出现找不到对应依赖 dll 的情况,解锁失败。
总结: 
在 tsmaster 安装目录中,提供了封装 seed&key 算法的模板工程。如 generatekeyex,generatekeyexopt asap1a_ccp_computekeyfromseed,用户基于此模板工程开发即可得到能够直接加载的 dll 函数。
同时,也提供了二次封装的 dll 的工程,比如 generatekeyex_wrapper_demo,该工程演示了如何基于已经存在的 seedkey 算法库进行包装,生成可以直接加载到 tsmaster 诊断模块中的 dll 的过程。

采用内置的算法编辑器
基本步骤如下所示:
注意事项:
【1】 算法函数的接口,tsmaster 目前提供了最常用的接口形式,如果用户有自己特殊的接口形式,无法覆盖住,请联系上海同星把此接口增加到选项中。
【2】 所有的接口函数都定义了返回值 s32。增加此约束,主要是增加函数的严谨性。返回值为 0 表示成功,为其他值则有对应的错误码。用户在编辑代码的时候,最后一行一定不要忘了输入返回值,否则系统执行函数过后,会认为算法执行失败,不予往后面执行。如下所示:
【3】 添加算法过后,点击 ok 退出。tsmaster 内置编译器会自动解释该算法,并准备好在执行诊断的过程中使用。
以上就是seed&key 的两种处理方法,如有任何问题可与同星联系。

部分商品修理更换退货责任规定的条文释义
多晶硅太阳能电池结构的优点详细介绍
Vishay推出采用带有4脚连接器的电池分流电阻---WSBM8518
仿真时为什么顶层不例化
紫光展锐推出虎贲T7520处理器,最高支持120Hz的刷新率
一文了解TSMaster中Seed和key的两种处理方法
三星推出新款无线充电器,快充速度得到进一步加强
IDC发布2020全球智能终端预测,云游戏付费玩家用户不会超过1000万
三分频喇叭用什么功放?先给你解析功放喇叭保护电路图
一名程序员的四年真实经历
关于Commvault推出的产品组合介绍和作用分析
力成携手华邦电,推进先进封装业务,切入AI市场
晶圓處理製程介紹
华为“丢掉”的份额将被三星和苹果瓜分,中国台湾和韩厂商将受益
极睿科技获红杉领投亿元级A轮融资 用人工智能改变万亿服装业的“人货场”
谷歌眼镜再“被PK” 可吞咽计算设备高调来袭
SMT贴片中的回流焊接工艺
人工智能AI在供应链中的优化
苹果Mac Pro和Pro Display XDR显示器即将开售最高支持1.5TB的内存
信号隔离器在锅炉控制系统中的应用方案