This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ27542-G1: Authentication验证算法的MCU端实现

Part Number: BQ27542-G1

The fuel gauge supports a SHA-1-based authentication protocol that allows a host to securely verify
battery pack authenticity. Sending a 160-bit random challenge initiates the authentication process wherein
the fuel gauge computes a response digest using a double SHA-1 transform. The transmitted challenge is
appended to a secret 128-bit authentication key and run through the transform. Afterwards, the resulting
hash is then re-appended to the same key and a second hash is computed, resulting in the final 160-bit
digest that is returned to the host. The host reproduces the same digest calculation on its side, using the
shared key, and compares to the one read from the fuel gauge. If they match, the authentication process
is successful.

以上是 Technical Reference Manual中提到的方法。我的理解是将20字节的原文添加到电量计中16个字节的Key后面得到36字节的数组进行一次SHA1运算,得出20字节值再次添加到16个字节的Key后面得到36字节的数组进行第二次SHA1运算,得出的20字节值即为最终的值。而我算出的值与从电量计中获取的值不一致。

我有几个疑问,首先在这里的SHA1指的是HMAC-SHA-1还是SHA1;其次我按字节读取的电量计中的可以为16进制表示的 0x0123456789ABCDEFFEDCBA9876543210,如果我MCU进行计算时,直接将其按字节顺序放入到16字节的数组中作为KEY进行计算,还是需要变换字节的顺序