krypton

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: AGPL-3.0 Imports: 15 Imported by: 2

README

krypton

Temporary Logo

A Go library for cryptographic operations.

Also a CLI frontend for some of the functions.

This library is under development and is still unstable. Use at your own risk!

Documentation

Index

Constants

View Source
const ErrInvalidArguments stringError = "invalid arguments"

Variables

This section is empty.

Functions

func BytesToHex added in v0.0.2

func BytesToHex(data []byte) string

func BytesToNibbles

func BytesToNibbles(byts []byte) []byte

func CoalesceBytes added in v0.0.2

func CoalesceBytes(a []byte, others ...[]byte) []byte

func CoalesceString added in v0.0.2

func CoalesceString(a string, others ...string) string

func ComputeKCV

func ComputeKCV(key []byte) ([]byte, error)

func Crypt

func Crypt(c cipher.BlockMode, data []byte) []byte

func DecodePINBlock0

func DecodePINBlock0(pan string, pinblock []byte) (pin string, err error)

func Decrypt3DES_CBC

func Decrypt3DES_CBC(key, iv, data []byte) ([]byte, error)

func Decrypt3DES_ECB

func Decrypt3DES_ECB(key, data []byte) ([]byte, error)

func DecryptAES_CBC

func DecryptAES_CBC(key, iv, data []byte) ([]byte, error)

func DecryptAES_ECB

func DecryptAES_ECB(key, data []byte) ([]byte, error)

func DecryptCBC

func DecryptCBC(c cipher.Block, iv, data []byte) ([]byte, error)

func DecryptDES_CBC

func DecryptDES_CBC(key, iv, data []byte) ([]byte, error)

func DecryptDES_ECB

func DecryptDES_ECB(key, data []byte) ([]byte, error)

func DecryptECB

func DecryptECB(c cipher.Block, data []byte) ([]byte, error)

func DecryptPINBlock0

func DecryptPINBlock0(key []byte, pan string, encryptedPinblock []byte) (pin string, err error)

func EncodePINBlock0

func EncodePINBlock0(pan, pin string) ([]byte, error)

func Encrypt3DES_CBC

func Encrypt3DES_CBC(key, iv, data []byte) ([]byte, error)

func Encrypt3DES_ECB

func Encrypt3DES_ECB(key, data []byte) ([]byte, error)

func EncryptAES_CBC

func EncryptAES_CBC(key, iv, data []byte) ([]byte, error)

func EncryptAES_ECB

func EncryptAES_ECB(key, data []byte) ([]byte, error)

func EncryptCBC

func EncryptCBC(c cipher.Block, iv, data []byte) ([]byte, error)

func EncryptDES_CBC

func EncryptDES_CBC(key, iv, data []byte) ([]byte, error)

func EncryptDES_ECB

func EncryptDES_ECB(key, data []byte) ([]byte, error)

func EncryptECB

func EncryptECB(c cipher.Block, data []byte) ([]byte, error)

func EncryptPINBlock0

func EncryptPINBlock0(key []byte, pan, pin string) ([]byte, error)

func GenerateCVV added in v0.0.4

func GenerateCVV(cvk []byte, pan string, expirationDate, serviceCode string) (string, error)

func IndentString added in v0.0.3

func IndentString(text, indent string) string

func InvertBits

func InvertBits(data []byte) []byte

func NewECBDecrypter

func NewECBDecrypter(c cipher.Block) cipher.BlockMode

func NewECBEncrypter

func NewECBEncrypter(c cipher.Block) cipher.BlockMode

func NewTripleDESCipher

func NewTripleDESCipher(key []byte) (cipher.Block, error)

func NewValidationError

func NewValidationError(errs ...error) error

func NibblesToBytes

func NibblesToBytes(nibbles []byte) []byte

func NibblesToHex

func NibblesToHex(nibbles []byte) string

func Pad80

func Pad80(data []byte, skipIfExact bool) []byte

Pad80 pads the data with byte 0x80 and then 0x00s until the data is an exact multiple of the block size.

`skipIfExact` controls if an entire block should be added when the data is an exact multiple of the block size or if the padding should be skipped entirely.

func PadLeft

func PadLeft(data []byte, padbyte byte, totalLength int) []byte

func PadRight

func PadRight(data []byte, padbyte byte, totalLength int) []byte

func ParseHexNibbles

func ParseHexNibbles(src string) ([]byte, error)

func RandomBytes

func RandomBytes(numberOfBytes int) ([]byte, error)

func SetNibble

func SetNibble(slice []byte, index int, nibble uint8)

func SetParityEven

func SetParityEven(data []byte)

func SetParityOdd

func SetParityOdd(data []byte)

func SliceOfDigits added in v0.0.3

func SliceOfDigits(n uint64) []int

func ToBCD added in v0.0.2

func ToBCD(n uint) []byte

func TruncateLeft

func TruncateLeft(data []byte, totalLength int) []byte

TruncateLeft discards bytes at the left until the length is equal the specified. If the length of the data is already equal to or shorter than `totalLength`, the data will be returned unchanged.

func TruncateRight

func TruncateRight(data []byte, totalLength int) []byte

TruncateRight discards bytes at the right until the length is equal the specified. If the length of the data is already equal to or shorter than `totalLength`, the data will be returned unchanged.

func XOR

func XOR(a []byte, others ...[]byte) []byte

XOR performs an Exclusive Or operation on the data and returns a slice with the results. This function does not mutate the slices fed into it.

If the length of `other` is smaller than the length of `a`, it will be padded to the left, adding zeroes to the left of b. If the length of `other` is greater than the length of `a`, it will be truncated to the left, removing the most significant bits.

func XORInPlace

func XORInPlace(data, other []byte)

XORInPlace performs an Exclusive Or operation on the data mutating it.

If the length of `other` is smaller than the length of `data`, it will be truncated to the left, removing the most significant bits. If the length of `other` is greater than the length of `data`, it will be padded to the left, adding zeroes to the left.

Types

type KeyType

type KeyType string
const (
	KeyZMK           KeyType = "ZMK"
	KeyAS2805_KCA    KeyType = "AS2805-KCA"
	KeyAS2805_KEKr   KeyType = "AS2805-KEKr"
	KeyAS2805_KEKs   KeyType = "AS2805-KEKs"
	KeyAS2805_KI     KeyType = "AS2805-KI"
	KeyAS2805_KIA    KeyType = "AS2805-KIA"
	KeyAS2805_KMA    KeyType = "AS2805-KMA"
	KeyAS2805_KT     KeyType = "AS2805-KT"
	KeyAS2805_PEK    KeyType = "AS2805-PEK"
	KeyAS2805_TAKr   KeyType = "AS2805-TAKr"
	KeyAS2805_TAKs   KeyType = "AS2805-TAKs"
	KeyAS2805_TEK    KeyType = "AS2805-TEK"
	KeyAS2805_TEKr   KeyType = "AS2805-TEKr"
	KeyAS2805_TEKs   KeyType = "AS2805-TEKs"
	KeyAS2805_TK     KeyType = "AS2805-TK"
	KeyAS2805_TMK1   KeyType = "AS2805-TMK1"
	KeyAS2805_TMK2   KeyType = "AS2805-TMK2"
	KeyAS2805_ZAKr   KeyType = "AS2805-ZAKr"
	KeyAS2805_ZAKs   KeyType = "AS2805-ZAKs"
	KeyAS2805_ZEKr   KeyType = "AS2805-ZEKr"
	KeyAS2805_ZEKs   KeyType = "AS2805-ZEKs"
	KeyBDK_1         KeyType = "BDK-1"
	KeyBDK_2         KeyType = "BDK-2"
	KeyBDK_3         KeyType = "BDK-3"
	KeyBDK_4         KeyType = "BDK-4"
	KeyCK_DEK        KeyType = "CK-DEK"
	KeyCK_ENK        KeyType = "CK-ENK"
	KeyCK_MAC        KeyType = "CK-MAC"
	KeyCSCK          KeyType = "CSCK"
	KeyCVK           KeyType = "CVK"
	KeyDEK           KeyType = "DEK"
	KeyHMAC          KeyType = "HMAC"
	KeyIKEY          KeyType = "IKEY"
	KeyIPEK          KeyType = "IPEK"
	KeyKD_PERSO      KeyType = "KD-PERSO"
	KeyKEK           KeyType = "KEK"
	KeyKMC           KeyType = "KMC"
	KeyKML           KeyType = "KML"
	KeyMK_AC         KeyType = "MK-AC"
	KeyMK_AS         KeyType = "MK-AS"
	KeyMK_CVC3       KeyType = "MK-CVC3"
	KeyMK_DAC        KeyType = "MK-DAC"
	KeyMK_DN         KeyType = "MK-DN"
	KeyMK_KE         KeyType = "MK-KE"
	KeyMK_SMC        KeyType = "MK-SMC"
	KeyMK_SMI        KeyType = "MK-SMI"
	KeyMK            KeyType = "MK"
	KeyOBKM_BKAM     KeyType = "OBKM-BKAM"
	KeyOBKM_BKEM     KeyType = "OBKM-BKEM"
	KeyOBKM_KI_S5    KeyType = "OBKM-KIS.5"
	KeyOBKM_KM3L     KeyType = "OBKM-KM3L"
	KeyOBKM_KM3LISS  KeyType = "OBKM-KM3LISS"
	KeyOBKM_KM3X     KeyType = "OBKM-KM3X"
	KeyOBKM_KM3XISS  KeyType = "OBKM-KM3XISS"
	KeyOBKM_KMACACQ  KeyType = "OBKM-KMACACQ"
	KeyOBKM_KMACACX  KeyType = "OBKM-KMACACX"
	KeyOBKM_KMACCI   KeyType = "OBKM-KMACCI"
	KeyOBKM_KMACISS  KeyType = "OBKM-KMACISS"
	KeyOBKM_KMACMA   KeyType = "OBKM-KMACMA"
	KeyOBKM_KMACS4   KeyType = "OBKM-KMACS4"
	KeyOBKM_KMACS5   KeyType = "OBKM-KMACS5"
	KeyOBKM_KMACUPD  KeyType = "OBKM-KMACUPD"
	KeyOBKM_KML      KeyType = "OBKM-KML"
	KeyOBKM_KMLISS   KeyType = "OBKM-KMLISS"
	KeyOBKM_KMP      KeyType = "OBKM-KMP"
	KeyOBKM_KMPISS   KeyType = "OBKM-KMPISS"
	KeyOBKM_KMSCISS  KeyType = "OBKM-KMSCISS"
	KeyOBKM_KMX      KeyType = "OBKM-KMX"
	KeyOBKM_KMXISS   KeyType = "OBKM-KMXISS"
	KeyOBKM_PVVK     KeyType = "OBKM-PVVK"
	KeyPEK           KeyType = "PEK"
	KeyPVK           KeyType = "PVK"
	KeyRSA_PK        KeyType = "RSA-PK"
	KeyRSA_SK        KeyType = "RSA-SK"
	KeySK_DEK        KeyType = "SK-DEK"
	KeySK_ENC        KeyType = "SK-ENC"
	KeySK_MAC        KeyType = "SK-MAC"
	KeyTAK           KeyType = "TAK"
	KeyTEK           KeyType = "TEK"
	KeyTKR           KeyType = "TKR"
	KeyTMK           KeyType = "TMK"
	KeyTPK           KeyType = "TPK"
	KeyWWK           KeyType = "WWK"
	KeyZAK           KeyType = "ZAK"
	KeyZEK           KeyType = "ZEK"
	KeyZMK_Component KeyType = "ZMK-Component"
	KeyZPK           KeyType = "ZPK"
)

func KeyTypeByName

func KeyTypeByName(name string) (KeyType, error)

func (KeyType) Code

func (kt KeyType) Code(keySeparation bool) string

func (KeyType) Description

func (kt KeyType) Description() string

func (KeyType) Name

func (kt KeyType) Name() string

func (KeyType) Validate

func (kt KeyType) Validate() error

type RawTrack1Data

type RawTrack1Data struct {
	FormatCode        string
	CardNumber        string
	CountryCode       string
	CardholderName    string
	ExpirationDate    string
	ServiceCode       string
	DiscretionaryData string
}

func RawParseTrack1

func RawParseTrack1(track string) (RawTrack1Data, error)

type RawTrack2Data

type RawTrack2Data struct {
	CardNumber        string
	ExpirationDate    string
	ServiceCode       string
	DiscretionaryData string
}

func RawParseTrack2

func RawParseTrack2(track string) (RawTrack2Data, error)

func RawParseTrack2EquivalentData

func RawParseTrack2EquivalentData(track []byte) (RawTrack2Data, error)

Directories

Path Synopsis
hex
tlv
internal
primitives

Jump to

Keyboard shortcuts

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