0

adafruit_atecc with bytearray.fromhex
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

adafruit_atecc with bytearray.fromhex

by brunoSyd on Sat Jul 24, 2021 1:56 am

Hi, Trinkey 2040 + ATECC608.

The sample code in the learn module (https://learn.adafruit.com/adafruit-atecc608-breakout?view=all) failed to load the atecc library due to a missing function fromhex used with bytearray. Am I missing something?

Thanks all

To reproduce just try to load the module like
import board
import busio
import struct

from adafruit_atecc.adafruit_ import ATECC, _WAKE_CLK_FREQ

code.py output:
Traceback (most recent call last):
File "code.py", line 5, in <module>
File "adafruit_atecc/adafruit_atecc.py", line 123, in <module>
AttributeError: 'type' object has no attribute 'fromhex'


Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 6.3.0 on 2021-06-01; Adafruit QT2040 Trinkey with rp2040

brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

Re: adafruit_atecc with bytearray.fromhex

by dastels on Sat Jul 24, 2021 1:35 pm

Making sure everything is up to date is the first step.

Make sure you have the latest CircuitPython for the board (either 6.3.0 or 7.0.0 alpha 5 as I write this). Then grab the latest matching library bundle. Delete everything in CIRCUITPY/lib, and empty trash as appropriate for your OS. Then copy files/directories from the bundle to CIRCUITPY/lib as required.


Dave

dastels
 
Posts: 7223
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_atecc with bytearray.fromhex

by brunoSyd on Sun Jul 25, 2021 4:34 am

I also did the test with the adafruit-circuitpython-adafruit_qt2040_trinkey-en_US-7.0.0-alpha.5 . So with 6.3 or 7.0.0 alpha the result is the same having of course load the correct bundle lib in the /lib which the boot is testing and will complain in case of discrepencies.
So if someone can just see what the three lines is giving assuming in /lib you have all the dir adafruit_atecc/ , adafruit_bus_device , and the file adafruit_binascii.mpy
Thanks
code.py:
import board
import busio
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ


Output

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 4, in <module>
File "adafruit_atecc/adafruit_atecc.py", line 123, in <module>
AttributeError: type object 'bytearray' has no attribute 'fromhex'


Code done running.

brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

Re: adafruit_atecc with bytearray.fromhex

by dastels on Sun Jul 25, 2021 9:35 am

As far as I can tell from some time digging through both CircuitPython and the ATECC codebases:
- CircuitPython bytearray.fromhex() doesn't exist
- The only place in the library bundle that it's used is the ATECC module
- The ATECC module was originally written by Arduino.
- cpython bytearray is much richer than the CircuitPython version and does include a fromhex function.

You might be the first person to actually try using this on CircuitPython (as opposed to cpython+blinka)... I see no mention of the problem in the repo so I've added an issue regarding it.

Dave

dastels
 
Posts: 7223
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_atecc with bytearray.fromhex

by brunoSyd on Sun Jul 25, 2021 1:11 pm

Thanks Mate, Yes i agree. I don't know yet how to forge a .mpy so far and will give it a try as i believe a binascii.unhexlify would to the job instead of bytearray.fromhex but may this is a workaround and the way to go is to implement fromhex. I think unfortunately i can park my ATECC for a while. the TrustM module is also not on CircuitPython leaving CircuitPython and Trinkey2040 to no option for crypto? Can you send the link to the issue if it is public i will also follow?. thanks

brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

Re: adafruit_atecc with bytearray.fromhex

by dastels on Sun Jul 25, 2021 6:34 pm

mpy-cross is the bytecode compiler for MicroPython/CircuitPython.
See https://learn.adafruit.com/building-circuitpython/build-circuitpython for more information.

Dave

dastels
 
Posts: 7223
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.