decoder

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const KEY_NONE = -1

Variables

This section is empty.

Functions

func AESMAC

func AESMAC(key []byte, data []byte) []byte

func DecryptAES

func DecryptAES(key []byte, data []byte) []byte

func DecryptLRP

func DecryptLRP(key []byte, keynum int, counterBytes []byte, data []byte) []byte

func DiversifyKey

func DiversifyKey(masterKey []byte, application []byte, identifier []byte) []byte

func LRPMAC

func LRPMAC(key []byte, keyNum int, msg []byte) []byte

LRPMAC performs the MAC function using LRP.

func ShortAESMAC

func ShortAESMAC(key []byte, data []byte) []byte

Types

type EncryptionMode

type EncryptionMode int
const (
	UNKNOWN EncryptionMode = iota
	AES     EncryptionMode = iota
	LRP     EncryptionMode = iota
)

type Key

type Key struct {
	// KeyData is the bytes of the key (master key if using diversified keys).
	KeyData []byte
	// Diversified tells whether this is a straight key or a diversified key.
	Diversified bool
	// Application tells the "application data" to use during diversification on diversified keys.
	Application []byte
}

Key is the type used to hold basic key information and generate diversified keys.

func (*Key) GenerateKeyBytes

func (key *Key) GenerateKeyBytes(uidBytes []byte) []byte

Generates a key. Diversifies the key if it is set to be a diversified key. If it is not a diversified key, uidBytes can be nil.

type Keyset

type Keyset struct {
	Mode              EncryptionMode
	Keys              []Key
	MetaReadKey       int
	FileReadKey       int
	AuthenticationKey int
}

Keyset maintains information about a set of keys on a chip. DNA chips can support 5 keys. This does not require that the key structure be mimicked, but allows for it.

func (*Keyset) DecodeEncryptedMeta

func (keyset *Keyset) DecodeEncryptedMeta(data []byte) (meta Meta)

func (*Keyset) DecodeEncryptedMetaString

func (keyset *Keyset) DecodeEncryptedMetaString(dataStr string) (meta Meta)

DecodeEncryptedMetaString decodes encrypted metadata

func (*Keyset) DecodeEncryptedMetaStringWithAuthenticator

func (keyset *Keyset) DecodeEncryptedMetaStringWithAuthenticator(dataStr string, authenticatorStr string) (meta Meta, validated bool)

DecodeEncryptedMetaStringWithAuthenticator is a convenience function for decoding meta-only messages with meta-only MACs.

type Meta

type Meta struct {
	Uid         int64
	ReadCounter int32
	Keyset      *Keyset
}

Meta is the chip metadata (called the PICCData in the docs). UID is an integer representation of the chips ID (convertible to a byte string by calling UidBytes(). ReadCounter is the number of times the chip has been scanned.

func DecodeUnencryptedBytes

func DecodeUnencryptedBytes(data []byte) Meta

func DecryptMetaAES

func DecryptMetaAES(key []byte, data []byte) Meta

func DecryptMetaAESString

func DecryptMetaAESString(key []byte, data string) Meta

DecryptMetaAESString decrypts metadata from the given string, assuming the string is encoded in hexadecimal.

func DecryptMetaLRP

func DecryptMetaLRP(key []byte, data []byte) Meta

DecryptMetaLRP decrypts the data for LRP.

func DecryptMetaLRPString

func DecryptMetaLRPString(key []byte, data string) Meta

DecryptMetaLRPString decrypts metadata from the given string, assuming the string is encoded in hexadecimal.

func Deserialize

func Deserialize(data []byte) Meta

func (*Meta) DecryptFileData

func (meta *Meta) DecryptFileData(data []byte) []byte

func (*Meta) GenerateAESSessionMACKey

func (meta *Meta) GenerateAESSessionMACKey(originalKey []byte) []byte

GenerateAESSessionMACKey generates a session MAC key for AES encryption.

func (*Meta) GenerateLRPSessionMACKey

func (meta *Meta) GenerateLRPSessionMACKey(macKey []byte) []byte

GenerateLRPSessionMACKey takes the MAC key and generates a session key for MAC-ing using the LRP algorithm.

func (*Meta) GenerateValidationCode

func (meta *Meta) GenerateValidationCode(data []byte) []byte

func (*Meta) ReadCounterBytes

func (meta *Meta) ReadCounterBytes() []byte

ReadCounterBytes retrieves the ReadCounter as a byte array (the way it is stored on the chip)

func (*Meta) UidBytes

func (meta *Meta) UidBytes() []byte

UidBytes decodes the UID into a byte string.

func (*Meta) UidHex

func (meta *Meta) UidHex() string

UidHex decodes the UID into a hex string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL