Open brentru opened 5 years ago
I'd suggest splitting this library into more modules so folks can import just the bits they need to use.
@tannewt I have some of this library split, but would like some advice on what to split out further. Here's my start:
adafruit_atecc
: Driver moduleadafruit_atecc_random
: Wrapper for random methods commands, we could mock random
methods.adafruit_atecc_hashlib
: Wrapper similar to https://github.com/adafruit/Adafruit_CircuitPython_hashlib, but for hardware-accelerated SHA-256 I like the idea of having modules for random and hashlib! What functions are left in the regular atecc module?
Random would contain the following from the atecc module:
nonce
random
hashlib would contain:
sha_start
,sha_digest
, and sha_update
Which leave us with a few public, non-driver-specific methods like: ecdsa_sign
, sign
, write_config
, gen_key
.
These could be moved to a class within atecc_cert_util
since they're related to certificate generation and STORAGE. I feel adafruit_atecc_asn1
could be its own class, contained within cert_util
as well.
I like the hashlib idea and please ensure the API matches CPython's hashlib.
Looks like this would work to mimic for ECDSA: https://github.com/warner/python-ecdsa
Can you find similar analogs for sign and gen_key?
That lib is promising. I'd need to adapt sign
and gen_key
to work properly with .generate
and .sign
.
sk = SigningKey.generate(curve=NIST384p)
vk = sk.verifying_key
signature = sk.sign(b"message")```
atcab_write_pubkey
: Uses the write command to write a public key to a slot in the proper format.atcab_priv_write
: Executes PrivWrite command, to write externally generated ECC private keys into the device.uCryptoAuthLib Implementation for
pubkey
(priv_write
is not implemented): https://github.com/dmazzella/ucryptoauthlib/blob/master/cryptoauthlib/basic.py#L852Discussion about these commands: https://github.com/MicrochipTech/cryptoauthlib/issues/44