mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 04:43:25 +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,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/ateccx08"
|
||||
)
|
||||
|
||||
var atecc *ateccx08.Device
|
||||
|
||||
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 {
|
||||
println(version.String(), "is not locked. Random numbers will not actually be random.")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
var result [13]byte
|
||||
for {
|
||||
rand.Read(result[:])
|
||||
encodedString := hex.EncodeToString(result[:])
|
||||
println(encodedString)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user