Skip to content

required fix for circuit python 8.2.x ATECC crypto module #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DJDevon3
Copy link

@DJDevon3 DJDevon3 commented Mar 10, 2024

Wake frequency 100000 causes CRC Mismatch failure. setting frequency to 75000 works. confirmed on rp2040 feather and esp32-s3 feather.

With default 100000 wake frequency

Traceback (most recent call last):
  File "code.py", line 16, in <module>
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 192, in __init__
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 266, in version
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 301, in info
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 625, in _get_response
RuntimeError: CRC Mismatch

With frequency at 75000 wake frequency (any value from 1 to 79999 works)

ATECC Serial:  0123xxxxobfuscated
Random Value:  obfuscated
ATECC Counter #1 Value:  bytearray(b'obfuscated')
Appending to the digest...
Appending to the digest...
SHA Digest:  bytearray(b'obfuscated')

Code done running.

The simpletest is broken on most if not all microcontrollers with the current stable 8.2.10 circuit python due to the default wake frequency being too high. I've added a code commented frequency if the default 100000 value doesn't work they'll have a code commented alternative to try.

wake frequency 100000 causes CRC Mismatch failure. setting frequency to 75000 works. confirmed on rp2040 feather and esp32-s3 feather.
@DJDevon3
Copy link
Author

DJDevon3 commented Mar 11, 2024

Scratch that. This is not a fix. There are much more complicated issues happening here where the crypto module will get locked. Found an indication in a datasheet that it might happen after the first 128 uses which tracks with my use. I lost count around 113 and then it just stopped working.

According to page 19 of the Atmel CryptoAuthLib Datasheet there needs to be a release but I'm not seeing a function for that in the library. I suspect the chip is being locked after 128 uses with no function to release/unlock it.

Will continue to work on this. This commit is not ready for merging.

@DJDevon3
Copy link
Author

DJDevon3 commented Mar 12, 2024

I think it was just a coincidence that it was around 128 iterations until I attempted to use the CSR script and flipped the lock to =True. That's what configures the eeprom and then locks eeprom permanently. After being locked the device hides itself from normal I2C scans. It will only communicate when a wakeup ping of the correct I2C bus frequency and I2C address are sent to it.

There are many issues with the current library. It's concerning that a warning of the danger of permanently locking the device is not documented on the Adafruit product page, in the learn guide, repo, or code commented in the CSR example.

I will be submitting a new commit with a code comment warning of the severity of choosing lock=True. The simpletest fix does work but then people will immediately turn straight to the CSR example and likely end up locking their chip when they run into the CRC Mismatch error.

@DJDevon3
Copy link
Author

The reason this should be added is because different MCU's can have different clock frequencies. The default frequency might not work for some boards while it might for others. By providing a way to set the frequency in the simpletest that should alleviate any clock disparities between boards and allow the user to figure out the best frequency to use with their board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant