mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 03:43:42 +00:00
ateccx08: inttial implementation for ATECCx08
This working implementation for the ATECCx08 family of cryptgraphic processors has random number generation and other needed supporting functions. It also includes a sample of how to connect it to the Go crypto/rand package. More cryptographic functions await a future interation. Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/ateccx08"
|
||||
)
|
||||
|
||||
func main() {
|
||||
time.Sleep(5 * time.Second)
|
||||
println("Looking for ATECCx08...")
|
||||
|
||||
machine.I2C0.Configure(machine.I2CConfig{})
|
||||
|
||||
atecc := ateccx08.New(machine.I2C0)
|
||||
atecc.Configure()
|
||||
|
||||
if !atecc.Connected() {
|
||||
for {
|
||||
println("could not connect to ATECCx08")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
version, _ := atecc.Version()
|
||||
|
||||
println(version.String(), "started")
|
||||
|
||||
if !atecc.IsLocked() {
|
||||
for i := 10; i > 0; i-- {
|
||||
println(version.String(), "is not locked. Locking in", i, "seconds...")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
// locks the Configuration zone... PERMANENTLY!
|
||||
atecc.Lock(0)
|
||||
}
|
||||
|
||||
println(version.String(), "locked.")
|
||||
|
||||
for {
|
||||
data, err := atecc.Random()
|
||||
if err != nil {
|
||||
println(err)
|
||||
}
|
||||
|
||||
println(hex.EncodeToString(data[:]))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user