samav2

package
v0.0.0-...-89eb2bc Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApduActivateOfflineKey

func ApduActivateOfflineKey(keyNo, keyVer int, divInput []byte,
) []byte

ApduActivateOfflineKey create apdu for SAM_ActiveOfflineKey command

func ApduChangeKeyEntryFullMode

func ApduChangeKeyEntryFullMode(keyNbr, proMax, cmdCtr int,
	keyVA, keyVB, keyVC []byte,
	dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
	dfAid, set, kex, ke, km []byte,
) ([]byte, error)

ApduChangeKeyEntryFullMode create APDU to SAM_ApduChangeKeyEntry

func ApduChangeKeyEntryMacMode

func ApduChangeKeyEntryMacMode(keyNbr, proMax, cmdCtr int,
	keyVA, keyVB, keyVC []byte,
	dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
	dfAid, set, km []byte,
) ([]byte, error)

ApduChangeKeyEntryMacMode create APDU to SAM_ApduChangeKeyEntry

func ApduChangeKeyEntryOffline

func ApduChangeKeyEntryOffline(keyNbr, proMax, changeCtr int,
	keyVA, keyVB, keyVC []byte,
	dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
	dfAid, set []byte,
	kc, samUID []byte,
) ([]byte, error)

ApduChangeKeyEntryOffline create APDU to SAM_ApduChangeKeyEntry

func ApduChangeKeyEntryPlainMode

func ApduChangeKeyEntryPlainMode(keyNbr, proMax int,
	keyVA, keyVB, keyVC []byte,
	dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
	dfAid, set []byte,
) ([]byte, error)

ApduChangeKeyEntryPlainMode create APDU to SAM_ApduChangeKeyEntry

func ApduDecipherOffline_Data

func ApduDecipherOffline_Data(last bool, cipher []byte) []byte

ApduDecipherOffline_Data

func ApduDecipher_Data

func ApduDecipher_Data(last bool, mifare int, cipher []byte) []byte

ApduDecipher_Data

func ApduDumpSecretKey

func ApduDumpSecretKey(keyNo, keyVer int, divInput []byte) []byte

ApduDumpSecretKey SAM_DumpSecretKey (allows dumping any of PICC keys or OfflineCrypto keys)

func ApduDumpSessionKey

func ApduDumpSessionKey() []byte

ApduDumpSessionKey SAM_DumpSessionKey (session key of an established authentication with a DESFire or MIFARE Plus PICC)

func ApduEncipherOffline_Data

func ApduEncipherOffline_Data(last bool, dataPlain []byte) []byte

ApduEncipherOffline_Data SAM_EncipherOffile_Data command encrypts data received from any other system based on the given cipher text data andt the current valid cryptographic OfflineCrypto Key.

func ApduEncipher_Data

func ApduEncipher_Data(last bool, offset int, dataPlain []byte) []byte

ApduEncipher_Data SAM_EncipherOffile_Data command encrypts data received from any other system based on the given cipher text data andt the current valid cryptographic OfflineCrypto Key.

func ApduGenerateCmac_Data

func ApduGenerateCmac_Data(last bool, dataPlain []byte) []byte

ApduGenerateCmac_Data SAM_EncipherOffile_Data command encrypts data received from any other system based on the given cipher text data andt the current valid cryptographic OfflineCrypto Key.

func ApduGetVersion

func ApduGetVersion() []byte

ApduGetVersion SAM_GetVersion

func ApduLockUnlock

func ApduLockUnlock(keyNr, keyVr, unlockKeyNo, unlockKeyVer, p1 int, maxchainBlocks []byte) []byte

ApduLockUnlock Apdu LockUnlock

func ApduLockUnlockPart2

func ApduLockUnlockPart2(cmacb, rnd []byte) []byte

ApduLockUnlockPart2 APDU LockUnlock part2

func ApduNonXauthMFPf1

func ApduNonXauthMFPf1(first bool, sl, keyNo, keyVer int, data, dataDiv []byte) []byte

ApduNonXauthMFPf1 SAM_AuthenticationMFP (non-X-mode) first part

func ApduNonXauthMFPf2

func ApduNonXauthMFPf2(data []byte) []byte

ApduNonXauthMFPf2 SAM_AuthenticationMFP (non-X-mode) second part

func ApduPKIExportPublicKey

func ApduPKIExportPublicKey(pkiKeyNo int) []byte

func ApduPKIGenerateKeyPair

func ApduPKIGenerateKeyPair(pkiE []byte, pkiSET []byte,
	pkiKeyNo, pkiKeyNoCEK, pkikeVCEK, pkiRefNoKUC, pkiNLen int) [][]byte

func ApduPKIImportKey

func ApduPKIImportKey(pkiKeyNo, pkiKeyNoCEK, pkiKeyVCEK, pkiRefNoKUC int,
	pkiSET, pkie, pkiN, pkip, pkiq, pkidP, pkidQ, pkiipq []byte,
) [][]byte

func ApduPKIUpdateKeyEntries

func ApduPKIUpdateKeyEntries(hashing HashingAlgorithm, keyEntrysNo int,
	pkiKeyNoEnc, pkiKeyNoSign int, pkiEncKeyFrame, pkiSignature []byte) [][]byte

func ApduSAMCombinedReadMFP

func ApduSAMCombinedReadMFP(typeMFPdata TypeMFPdata, isLastFrame bool, data []byte,
) []byte

func ApduSAMCombinedWriteMFP

func ApduSAMCombinedWriteMFP(typeMFPdata TypeMFPdata, data []byte,
) []byte

func ApduSamKillAuthPICC

func ApduSamKillAuthPICC() []byte

ApduSamKillAuthPICC SAM_KillAuthentication invalidates any kind authentication PICC

func ExtSETConfigurationSettings

func ExtSETConfigurationSettings(keyClass KeyClass,
	allowDumpSecretKey bool, restrictToDiversifiedUse bool) byte

ExtSETConfigurationSettings keyClass: KeyClass Type, multiple types support (example: OfflineChange_KEY | PICC_KEY)

func SETConfigurationSettings

func SETConfigurationSettings(allowDumpSessionKey bool,
	keepIV bool, keyType KeyType, authKey bool, disableKeyEntry bool,
	lockKey bool, disableWritingKeyPICC bool, disableDecryption bool,
	disableEncryption bool, disableVerifyMAC bool, disableGenMAC bool) []byte

func SETConfigurationSettingsPKI

func SETConfigurationSettingsPKI(privKeyInclude bool,
	allowPrivKeyExport bool, disableKeyEntry bool,
	disableEncryptionHandl bool, disableSignatureHandl bool,
	enablePKIUpdateKeyentry bool, privKeyRepresentation int,
) []byte

Types

type CrytoAlgorithm

type CrytoAlgorithm int
const (
	AES_ALG CrytoAlgorithm = iota
	DES_ALG
)

type EntryKey

type EntryKey struct {
	KeyVA []byte
	KeyVB []byte
	KeyVC []byte

	Va       byte
	Vb       byte
	Vc       byte
	DfAID    []byte
	DfKeyNo  byte
	KeyNoCEK byte
	KeyVCEK  byte
	RefNoKUC byte
	Set      []byte
	ExtSet   byte
}

func NewEntryKey

func NewEntryKey(data []byte, alg KeyType) *EntryKey

func (*EntryKey) Bytes

func (ek *EntryKey) Bytes() []byte

type EntryKeyData

type EntryKeyData struct {
	Va       byte
	Vb       byte
	Vc       byte
	DfAID    []byte
	DfKeyNo  byte
	KeyNoCEK byte
	KeyVCEK  byte
	RefNoKUC byte
	Set      []byte
}

func NewEntryKeyData

func NewEntryKeyData(data []byte, alg KeyType) *EntryKeyData

type HashingAlgorithm

type HashingAlgorithm int
const (
	SHA1 HashingAlgorithm = iota
	SHA224
	RFU
	SHA256
)

type KeyClass

type KeyClass int
const (
	HOST_KEY          KeyClass = 0
	PICC_KEY          KeyClass = 1
	OfflineChange_KEY KeyClass = 2
	OfflineCrypto_KEY KeyClass = 4
)

func KeyClassByName

func KeyClassByName(v string) KeyClass

type KeyType

type KeyType int
const (
	TDEA_DESFire_4                 KeyType = 0
	TDEA_ISO_10116                 KeyType = 1
	MIFARE                         KeyType = 2
	TripleTDEA_ISO_10116           KeyType = 3
	AES_128                        KeyType = 4
	AES_192                        KeyType = 5
	TDEA_ISO_10116__32CRC_8byteMAC KeyType = 6
)

type PKIPubKey

type PKIPubKey struct {
	PKISet      []byte
	PKIKeyNoCEK int
	PKIKeyVCEK  int
	PKIRefNoKUC int
	PKINLen     int
	PKIeLen     int
	PKIN        *big.Int
	PKIe        int
}

func ParseResponseToPKIPubKey

func ParseResponseToPKIPubKey(data []byte) (*PKIPubKey, error)

type ProMasEntryKey

type ProMasEntryKey byte

func (ProMasEntryKey) UpdateAll

func (p ProMasEntryKey) UpdateAll() ProMasEntryKey

func (ProMasEntryKey) UpdateDFAidDFKey

func (p ProMasEntryKey) UpdateDFAidDFKey() ProMasEntryKey

func (ProMasEntryKey) UpdateKeyNoCEJKeyVCEK

func (p ProMasEntryKey) UpdateKeyNoCEJKeyVCEK() ProMasEntryKey

func (ProMasEntryKey) UpdateKeyVa

func (p ProMasEntryKey) UpdateKeyVa() ProMasEntryKey

func (ProMasEntryKey) UpdateKeyVb

func (p ProMasEntryKey) UpdateKeyVb() ProMasEntryKey

func (ProMasEntryKey) UpdateKeyVc

func (p ProMasEntryKey) UpdateKeyVc() ProMasEntryKey

func (ProMasEntryKey) UpdateKeyVerSentSep

func (p ProMasEntryKey) UpdateKeyVerSentSep() ProMasEntryKey

func (ProMasEntryKey) UpdateRefKUC

func (p ProMasEntryKey) UpdateRefKUC() ProMasEntryKey

func (ProMasEntryKey) UpdateSET

func (p ProMasEntryKey) UpdateSET() ProMasEntryKey

type SamAv2

type SamAv2 interface {
	smartcard.ICard
	GetVersion() ([]byte, error)
	/*AuthHostAV2 SAM_AuthenticationHost AV2 mode
	key, key to Authentication
	keyNo, key entry number in SAM key storage
	keyVr, key version used
	hostMode, hostMode (0: plain, 1: Mac, 2: Full)*/
	AuthHostAV2(key []byte, keyNo, keyVr, hostMode int) ([]byte, error)
	NonXauthMFPf1(first bool, sl, keyNo, keyVer int, data, dataDiv []byte) ([]byte, error)
	NonXauthMFPf2(data []byte) ([]byte, error)
	DumpSessionKey() ([]byte, error)
	DumpSecretKey(keyNo, keyVer int, divInput []byte) ([]byte, error)
	LockUnlock(key, maxchainBlocks []byte, keyNr, keyVr, unlockKeyNo, unlockKeyVer, p1 int) ([]byte, error)
	SwitchToAV2(key []byte, keyNr, keyVr int) ([]byte, error)
	AuthHostAV1(block cipher.Block, keyNo, keyVer, authMode int) ([]byte, error)
	ChangeKeyEntryAv1(keyNbr, proMax int,
		keyVA, keyVB, keyVC []byte,
		dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC byte,
		dfAid, set []byte,
	) ([]byte, error)
	ChangeKeyEntry(keyNbr, proMax int,
		keyVA, keyVB, keyVC []byte,
		dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
		dfAid, set []byte,
	) ([]byte, error)
	ChangeKeyEntryOffline(keyNbr, proMax, changeCtr int,
		keyVA, keyVB, keyVC []byte,
		dfKeyNr, ceKNo, ceKV, kuc, verA, verB, verC, extSet byte,
		dfAid, set []byte,
		kc, samUID []byte,
	) ([]byte, error)
	SAMGetKeyEntry(keyNo int) ([]byte, error)
	ActivateOfflineKey(keyNo, keyVer int,
		divInput []byte,
	) ([]byte, error)
	SAMCombinedWriteMFP(typeMFPdata TypeMFPdata, data []byte,
	) ([]byte, error)
	SAMCombinedReadMFP(typeMFPdata TypeMFPdata, isLastFrame bool, data []byte,
	) ([]byte, error)
	SAMEncipherData(alg CrytoAlgorithm, data []byte) ([]byte, error)
	SAMGenerateMAC(alg CrytoAlgorithm, data []byte) ([]byte, error)
	SAMEncipherOfflineData(alg CrytoAlgorithm, data []byte) ([]byte, error)
	SAMDecipherData(alg CrytoAlgorithm,
		data []byte) ([]byte, error)
	SAMDecipherOfflineData(alg CrytoAlgorithm, data []byte) ([]byte, error)
	PKIGenerateKeyPair(pkiE []byte, pkiSET []byte,
		pkiKeyNo, pkiKeyNoCEK, pkikeVCEK, pkiRefNoKUC, pkiNLen int) ([]byte, error)
	PKIExportPublicKey(pkiKeyNo int) ([]byte, error)
	PKIUpdateKeyEntries(hashing HashingAlgorithm, keyEntrysNo int,
		pkiKeyNoEnc, pkiKeyNoSign int, pkiEncKeyFrame, pkiSignature []byte) ([]byte, error)
	SAMLoadInitVector(alg CrytoAlgorithm, data []byte) ([]byte, error)
	PKIImportKey(pkiKeyNo, pkiKeyNoCEK, pkiKeyVCEK, pkiRefNoKUC int,
		pkiSET, pkie, pkiN, pkip, pkiq, pkidP, pkidQ, pkiipq []byte) ([]byte, error)
}

SamAv2 Interface

func ConnectSam

func ConnectSam(r smartcard.IReader) (SamAv2, error)

ConnectSam Create SamAv2 interface

func ConnectSamAv2

func ConnectSamAv2(r smartcard.IReader) (SamAv2, error)

ConnectSamAv2 Create SamAv2 interface

func SamAV2

func SamAV2(c smartcard.ICard) SamAv2

SamAV2 Create SAM from Card

type TypeMFPdata

type TypeMFPdata int
const (
	MFP_Command         TypeMFPdata = 0x00
	MFP_Response        TypeMFPdata = 0x01
	MFP_CommandResponse TypeMFPdata = 0x02
)

Jump to

Keyboard shortcuts

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