mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 01:13:40 +00:00
68d4991da1
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>
50 lines
829 B
Go
50 lines
829 B
Go
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)
|
|
}
|
|
}
|