Documentation
¶
Overview ¶
Package atecc is a driver for the MicrochipTech ATECC608 device in Go.
It supports communication using I²C and USB.
This code is based on MicrochipTech's Cryptoauthlib code, thus its original copyright is retained for this code.
Copyright (c) 2022 Northvolt AB and the atecc authors. Copyright (c) 2015-2022 Microchip Technology Inc. and its subsidiaries.
Datasheets ¶
Find all datasheets in the Trust Platform Design Suite git repository. https://github.com/MicrochipTech/cryptoauth_trustplatform_designsuite/
Index ¶
- Variables
- type Dev
- func (d *Dev) GenerateKey(ctx context.Context, slot uint8) (crypto.PublicKey, error)
- func (d *Dev) IsConfigZoneLocked(ctx context.Context) (bool, error)
- func (d *Dev) IsDataZoneLocked(ctx context.Context) (bool, error)
- func (d *Dev) IsLocked(ctx context.Context, zone Zone) (bool, error)
- func (d *Dev) LockConfigZone(ctx context.Context) error
- func (d *Dev) LockDataSlot(ctx context.Context, slot uint8) error
- func (d *Dev) LockDataZone(ctx context.Context) error
- func (d *Dev) PrivateKey(ctx context.Context, key uint8) (crypto.PrivateKey, error)
- func (d *Dev) PublicKey(ctx context.Context, slot uint8) (crypto.PublicKey, error)
- func (d *Dev) Random(ctx context.Context) io.Reader
- func (d *Dev) ReadConfigZone(ctx context.Context) ([]byte, error)
- func (d *Dev) ReadZone(ctx context.Context, zone Zone, slot uint16, block uint8, offset uint8, ...) (int, error)
- func (d *Dev) Revision(ctx context.Context) ([]byte, error)
- func (d *Dev) SerialNumber(ctx context.Context) ([]byte, error)
- func (d *Dev) Sign(ctx context.Context, key int, msg []byte) ([]byte, error)
- func (d *Dev) VerifyExtern(ctx context.Context, msg, sig []byte, pub crypto.PublicKey) (bool, error)
- func (d *Dev) WriteBytesZone(ctx context.Context, zone Zone, slot uint16, offset uint8, data []byte) error
- func (d *Dev) WriteConfigZone(ctx context.Context, data []byte) error
- type DeviceType
- type HAL
- type HIDConfig
- type I2CConfig
- type IfaceConfig
- type IfaceType
- type KitType
- type Logger
- type Zone
Constants ¶
This section is empty.
Variables ¶
var ErrUSBNotSupported = errors.New("atecc: usb support is missing")
ErrUSBNotSupported is returned when the USB support is missing.
When building, CGO is required for USB support. If CGO is not enabled, the HID interface will not be available.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
func NewI2CDev ¶
func NewI2CDev(ctx context.Context, cfg IfaceConfig) (*Dev, error)
NewI2CDev returns an object that communicates over I²C to ATECC608A.
NOTE: the address passed in here is the actual target address. In upstream MicrochipTech cryptoauthlib, the address used is shifted.
func (*Dev) GenerateKey ¶
GenerateKey generates a new random private key in slot/handle.
func (*Dev) IsConfigZoneLocked ¶
IsConfigZoneLocked returns true if the configuration zone is locked.
This is the same as calling IsLocked(ctx, ZoneConfig).
func (*Dev) IsDataZoneLocked ¶
IsDataZoneLocked returns true if the data zone is locked.
This is the same as calling IsLocked(ctx, ZoneData).
func (*Dev) PrivateKey ¶
func (*Dev) Random ¶
Random returns a random reader.
The underlying reader reads 32 byte random data from the device at a time.
Use io.ReadFull to fill a buffer.
func (*Dev) ReadConfigZone ¶
ReadConfigZone reads the complete device configuration zone.
func (*Dev) Revision ¶
Revision gets the device revision.
This information is hard coded into the device. Use it to determine the version of the device.
func (*Dev) SerialNumber ¶
SerialNumber returns the serial number of the device.
The returned serial number will be 9 bytes.
func (*Dev) Sign ¶
Sign signs the message using the private key in the specified slot.
This function executes the sign command to sign a 32-byte external message using the private key in the specified slot. It returns the ASN.1 encoded signature.
func (*Dev) VerifyExtern ¶
func (d *Dev) VerifyExtern(ctx context.Context, msg, sig []byte, pub crypto.PublicKey) (bool, error)
VerifyExtern verifies a signature using external input.
The signature provided is expected to be in ASN.1 format.
func (*Dev) WriteBytesZone ¶
func (d *Dev) WriteBytesZone(ctx context.Context, zone Zone, slot uint16, offset uint8, data []byte) error
WriteBytesZone writes the data into the config, OTP or data zone.
If ZoneConfig is unlocked, it may be written to. If ZoneData is unlocked, 32-byte writes are allowed to slots and OTP.
Offset and length must be multiples of 32 or the write will fail.
func (*Dev) WriteConfigZone ¶
WriteConfigZone writes the data into the config zone.
This method works similar to how WriteBytesZone work except that it also writes the UserExtraData if all other data was written successfully.
Warning: if UserExtraData or UserExtraDataAdd is not 0x55 ('U'), these values will be permanent and the corresponding zones will be locked. If so, this is irreversible!
type DeviceType ¶
type DeviceType int
DeviceType represents a physical device type.
const (
DeviceATECC608 DeviceType = iota
)
func DeviceTypeFromInfo ¶
func DeviceTypeFromInfo(revision []byte) (DeviceType, error)
DeviceTypeFromInfo returns the device type based on the info byte array.
func (DeviceType) String ¶
func (dt DeviceType) String() string
type HIDConfig ¶
type HIDConfig struct { // DevIndex is the HID enumeration index to use unless DevIdentity is set. DevIndex int // KitType indicates the underlying interface to use. // // This is known as dev_interface in cryptoauthlib. KitType KitType // DevIdentity is the identity of the device. // // For I²C, this is the I²C target address. For the SWI interface, this is // the bus number. DevIdentity uint8 // VendorID of the kit. VendorID uint16 // ProductID of the kit. ProductID uint16 // PacketSize is the size of the USB packet. PacketSize int }
type IfaceConfig ¶
type IfaceConfig struct { // IfaceType affects how communication with the device is done. IfaceType IfaceType // DeviceType affects how communication with the device is done. DeviceType DeviceType // I2C contains I²C specific configuration. I2C I2CConfig // HID contains HID specific configuration. HID HIDConfig // WakeDelay defines the time to wait for the device before waking up. // // This represents the tWHI + tWLO and is configured based on device type. WakeDelay time.Duration // RxRetries is the number of retries to attempt when receiving data. RxRetries int // Debug is used for debug output. Debug Logger }
IfaceConfig is the configuration object for a device.
Logical device configurations describe the device type and logical interface.
func ConfigATECCX08A_I2CDefault ¶
func ConfigATECCX08A_I2CDefault(bus i2c.Bus) IfaceConfig
ConfigATECCX08A_I2CDefault returns a default config for an ECCx08A device.
TODO: re-think where we put bus, who owns it (who closes, do we have Close?)
func ConfigATECCX08A_KitHIDDefault ¶
func ConfigATECCX08A_KitHIDDefault() IfaceConfig
ConfigATECCX08A_KitHIDDefault returns a configuration for the Kit protocol.