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.

BQ40Z50-R2: Fuel gauge authentication using encryption key

Part Number: BQ40Z50-R2
Other Parts Discussed in Thread: BQKEYPACKAGER, BQKEYPROGRAMMER, BQSTUDIO, BQ40Z50

Dear team,

We were using TI bqKey Packager Software to generate the encryption key, but we did not know what to enter our 128-bit encryption key into the SHA1 Authentication Key F and SHA1 Authentication Key C fields. We noticed that these fields only support for 20 bytes, our encryption key has only 16 bytes.

We have noticed that there was a similar question asked before, but we did not see the update for it. Are there any updated solutions for our problem? Thank you!

Best regards,

Eric

  • Hello Eric,

    The FAQ page is active and outlines the steps needed to program the keys.

    https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1106884/faq-bq40z50-faqs

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    From the procedure to program the SHA-1 secure key, I challenged with all zeros and turned out the response was not a blank-key, which is expected since I changed the gauge authentication key. What confuses me is the verification part: Which block should I write through cmd AuthWriteKeyF() to get the response?

    Thank you,

    Eric

  • Hello Eric,

    I'm not sure I understand your question, you do not send the challenge to AuthWriteKeyF(), you will need to send it to AuthKeyChallenge() then read the response. The table at the bottom of the FAQ gives the commands which can be used to send a challenge and receive response.

    Sincerely,

    Wyatt Keller

  • Hi Wyatt,

    Sorry I am new to this. I tried to check my response by challenging all zeros through cmd AuthKeyChallenge() as figure below but there was an error occurred.
    Did I enter the wrong block?

    Thanks,
    Eric

  • Dear Wyatt

    Thanks for above Link. Its very helpful. However, I do not understand the bqKey Packager Input.

    Lets say my Key is (32char=128bit) : 00112233445566778899AABBCCDDEEFF

    How do I feed this key now into Key F and Key C field in the bqKey Packager:

    Thank you

    Regards Daniel

  • Hello Daniel and Eric,

    The commands are for ROM mode, you have to enter ROM mode by sending command 0x000F to 0x44.

    You cannot program starting with the key, you get the final key following the steps outlined in the FAQ. You won't easily be able to back calculate it.

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    After getting into ROM mode, I challenged with all zeros and the response was not a blank-key response, so I continued to verify the keys with the steps in FAQ. In the example: If 2309BDC0A9F86B69111CA850B530339111000C47 (little endian) is sent for KeyF through cmd AuthWriteKeyF(). How do we get the input(2309...0C47) to find keyF, as well as keyC? For the input to find keyF, is it the response of the challenge with all zeros? 

    For the SHA-1 hash input for all 0's challenge(KeyF + KeyC + Challenge), it is over 20 bytes, how do we get the response for it?

    Also, In bqKeyPackager, are Key F and Key C field be the two KeyF + KeyC + Challenge responses? Or are they the SHA-1 hash outputs for finding KeyF and KeyC, which are the outputs you highlighted in red?

    Thank you so much.

    Best regards,
    Eric

  • TI USA observes a holiday today so responses will be delayed (until Monday).

  • Hello Eric,

    Has this gauge ever been programmer before or have you modified any of the keys before testing? The keys are essentially one time programable, once you program them and power cycle the device they cannot be changed.

    You choose the byte string to use for the AuthKeyWriteF(), it is most likely just a randomly generated string.

    I'm not sure I understand your question for SHA-1 hash with (KeyF + KeyC + Challenge), this is for your host to do to verify the gauge calculation is correct, the whole string is never sent to the gauge, only the challenge is sent. Both the host and gauge perform the hash, then host reads response from the gauge to verify they match.

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    I only changed the gauge authentication key in SHA Authentication interface. So if I programmed the keys in bqKeyProgrammer once, keyF and keyC can not be changed but the gauge authentication key is always changeable?

    I am still not sure about what I should enter the 20-byte keys in bqKeyPackager.

    Are these two fields we enter be the highlighted part in the following figure?


    Thank you.

    Best regards,
    Eric

  • Hello Eric,

    I'm not sure I understand what you're referencing, the gauge has 2 different methods for SHA-1 authentication, one is secure memory which it looks like you're trying to do, and what the BQKeyProgrammer does. There's also a method to do SHA-1 authentication with the key stored in flash and the key can be changed and is part of the SREC, it is good for testing and can be done in the SHA-1 BQStudio tab.

    Once you program the secure keys and the gauge goes through a POR you will never be able to change the keys again, they are locked. If you don't shutdown the gauge you can change them again if needed.

    You must upload the 20 bytes for key F and key C, the final key is the last 8 bytes of each after it is hashed then they are appended, this is in the FAQ under the verify section:

    The NIST database is also helpful for a better understanding of the SHA-1 hashing and the sizes needed for keys, responses and challenges: https://csrc.nist.gov/publications/detail/fips/180/4/final

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    If I chose to use SHA-1 authentication with key stored in flash, am I able to use the other method as well? Will it cause conflict?

    And for the secure memory methods, can you point out which step or the data is incorrect?
    For the hash input for keyF and keyC, I am using the examples from FAQ.

    1. AuthWriteKeyF() 0x1b with input: 470C0011913330B550A81C11696BF8A9C0BD0923
    2. Challenge 0x1d with input: 470C0011913330B550A81C11696BF8A9C0BD0923
    3. Read response 0x21: 0290A8E024851DA496C34DFF6E4167AD5A46202F     (6E4167AD5A46202F = keyF)
    4. AuthWriteKeyC() 0x1c with input: 1306BDC7A9F86B69101DA850B530359114000C33
    5. Challenge 0x1d with input: 1306BDC7A9F86B69101DA850B530359114000C33
    6. Read response 0x21: 02907456915115ED85C9B20324ADCFB1AA4B1B08     (24ADCFB1AA4B1B08 = keyC)
    7. Open bqKeyPackager
      1. Enter SHA-1 Authentication Key F: 0290A8E024851DA496C34DFF6E4167AD5A46202F
      2. Enter SHA-1 Authentication Key C: 02907456915115ED85C9B20324ADCFB1AA4B1B08
      3. Create .bqk file
    8. Open bqKeyProgrammer
      1. Load the .bqk file and start programming and verifying the key

    Thank you.

    Best regards,
    Eric

  • Hello Eric,

    The FAQ mentions you can select each method by toggling the selection bit in the Auth Config register.

    I'm not following the steps you outlined, they are not the same steps shown in our example. The final key is the last 8 bytes of each SHA1 hash of Key C and Key F appended to the other, it looks like you're trying to get the hash by sending a challenge which will not work. You need to use a SHA-1 calculator in order to do the hash on the 20 byte key C and key F inputs to find the last 8 bytes of each.

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    Thank you for helping me out with the procedure, I think I had better understandings of it. But I am still not sure about what I should enter in the bqKeyPackager for keyF and keyC. Are they the hash outputs of the keys after SHA-1 calculation, or are they the two responses of the final key with different challenges?

    Thank you.

    Best regards,
    Eric

  • Hello Eric,

    Key F and Key C are the same for both the packager and the FAQ example, you can use the same procedure to get the final key for both. You will need to use an online tool to do the SHA-1 hash on the Key F and Key C 20 byte inputs. After you do the hash with the online tool, append the last 8 bytes from each together as described in the FAQ to get the final key.

    Here is an example of a tool you can use: https://emn178.github.io/online-tools/sha1.html

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

    I used the same input for Key F and Key C, and after doing the hash with online tool, I tried to create the .bqk file in bqKeyPackager and also tried to program and verify the key in bqKeyProgrammer. However, I kept failing with the error messages.

    I have not programmed the device before, so I think there must be the wrong input I entered in the packager. Can you point out which step I did wrong?

    1. AuthWriteKeyF() cmd with input: 2309BDC0A9F86B69111CA850B530339111000C47 (little endian)
    2. Use the online tool to do SHA-1 hash:
      1. Input: 470C0011913330B550A81C11696BF8A9C0BD0923 (big endian)
      2. Get the hash output: F4EE025E15C06FB17521FF39CE0B198608D0916
      3. The last 8 bytes are key F (9CE0B198608D0916)
    3. AuthWriteKeyC() cmd with same input: 2309BDC0A9F86B69111CA850B530339111000C47 (little endian)
    4. In bqKeyPackager:
      1. Enter both SHA Authentication Key F and Key C same input from the hash output: F4EE025E15C06FB17521FF39CE0B198608D0916
      2. Create .bqk file
    5. In bqKeyProgrammer:
      1. Load and program the key => Error message

    Thank you so much.

    Best regards,

    Eric

  • Hi Eric,

    Get the hash output: F4EE025E15C06FB17521FF39CE0B198608D0916

    One error here

    The correct hash output is : F4EE025E15C06FB17521FF39CE0B1986085D0916

    correct last 8 bytes are key F : CE0B1986085D0916

    If you are following the example, little endian for KeyC should be : 330C0014913530B550A81D10696BF8A9C7BD0613

  • Hi Kipp,

    I've corrected my error for the key F hash output and I tried it again with bqKeyPackager and bqKeyProgrammer.
    However, I still get the error message telling me the challenge does not match the response.
    I'm using the data from the example and here's what I did:

    In bqStudio:

    • AuthWriteKeyF() 0x1b: 2309BDC0A9F86B69111CA850B530339111000C47
    • AuthWriteKeyC() 0x1c: 330C0014913530B550A81D10696BF8A9C7BD0613

    In bqKeyPackager:

    • SHA1 Authentication Key F: F4EE025E15C06FB17521FF39CE0B1986085D0916
    • SHA1 Authentication Key C: EBE744F8B027943CB91DCBC300DB5A0A67084C16

    Thank you.

    Best regards,
    Eric

  • Hi Eric,

    Please follow the directions in this drafted app note attached

    SLUAAQ0=1=TI PDF=en-us (9).pdf

    KeyF value:F4EE025E15C06FB17521FF39CE0B1986085D0916

    KeyC value: EBE744F8B027943CB91DCBC300DB5A0A67084C16

    If it is still failing, please try with a new BQ40z50 IC/EVM if possible.