mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 02:43:42 +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>
33 lines
545 B
Go
33 lines
545 B
Go
// from https://github.com/usbarmory/armoryctl/blob/master/atecc608/atecc608.go#L104
|
|
// thank you!
|
|
package ateccx08
|
|
|
|
const (
|
|
CRC16Poly uint16 = 0x8005
|
|
)
|
|
|
|
func crc16(data []byte) []byte {
|
|
var crc uint16
|
|
|
|
for i := 0; i < len(data); i++ {
|
|
for shift := uint8(0x01); shift > 0x00; shift <<= 1 {
|
|
// data and crc bits
|
|
var d uint8
|
|
var c uint8
|
|
|
|
if uint8(data[i])&uint8(shift) != 0 {
|
|
d = 1
|
|
}
|
|
|
|
c = uint8(crc >> 15)
|
|
crc <<= 1
|
|
|
|
if d != c {
|
|
crc ^= CRC16Poly
|
|
}
|
|
}
|
|
}
|
|
|
|
return []byte{byte(crc & 0xff), byte(crc >> 8)}
|
|
}
|