fincrypt

package module
v0.0.0-...-722dc29 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 25 Imported by: 0

README

fincrypt

A go library which provides general purpose cryptography alongside solutions for payment industry specific requirements.

fincrypt offers simple drop in support, with robust error reporting, which is backed unit tests.

Operation support includes,

  • Authentication Codes (MACs)

    • HMAC (SHA-1/SHA-224/SHA-256/SHA-384/SHA-512/MD4/MD5)
    • Retail MAC (ISO-9797-1)
  • Cardholder Validation

    • CVVs (CVV/CVV2/iCVV)
    • PIN Blocks (ISO0/ISO1/ISO2/ISO3)
    • PIN Offset
    • PVV
  • Ciphers

    • AES (ECB/CBC)
    • TDES (ECB/CBC)
    • RSA (OAEP)
  • EMV 4.3

    • Tag Search
    • TLV Parsing
  • Hashes

    • MD4/5
    • SHA-1/SHA-224/SHA-256/SHA-384/SHA-512
  • Utilities

    • Base64
    • Luhn Check Digit
    • SafeNet Variants
    • XOR

Documentation

Index

Constants

View Source
const (
	PINBlockFormatISO0 PINBlockFormat = "ISO0"
	PINBlockFormatISO1                = "ISO1"
	PINBlockFormatISO2                = "ISO2"
	PINBlockFormatISO3                = "ISO3"
)

PINBlockFormat enum lists supports PIN block formats

View Source
const (
	RetailMACPaddingModeNone    RetailMACPaddingMode = "NONE"
	RetailMACPaddingModeMethod1                      = "M1"
	RetailMACPaddingModeMethod2                      = "M2"
)

RetailMAC padding modes

View Source
const (
	HashModeSHA1   HashMode = "SHA-1"
	HashModeSHA224          = "SHA-224"
	HashModeSHA256          = "SHA-256"
	HashModeSHA384          = "SHA-384"
	HashModeSHA512          = "SHA-512"
	HashModeMD4             = "MD4"
	HashModeMD5             = "MD5"
)

HashMode modes of of hash function

View Source
const (
	InputNameCVK             InputName = "CVK"
	InputNameData                      = "Data"
	InputNameInput                     = "Input"
	InputNameInput1                    = "Input 1"
	InputNameInput2                    = "Input 2"
	InputNameIV                        = "IV"
	InputNameKey                       = "Key"
	InputNameMasterKey                 = "Master Key"
	InputNameModulus                   = "Modulus"
	InputNamePPK                       = "PPK"
	InputNamePrivateExponent           = "Private Exponent"
	InputNamePublicExponent            = "Public Exponent"
	InputNamePVK                       = "PVK"
	InputNameTag                       = "Tag"
	InputNameVariant                   = "Variant"
)

InputName enum specifies input element names for error reporting

Variables

This section is empty.

Functions

func Expand

func Expand(input []byte) (string, error)

Expand returns the expanded representation of the provided packed hex bytes

func NumericOnly

func NumericOnly(s string) bool

NumericOnly examines the given string and returns true if all bytes are numeric characters

func Pack

func Pack(input string, name InputName) (string, error)

Pack returns the packed representation of an expanded hex string

func XOR

func XOR(i1, i2 []byte) []byte

XOR returns the XOR result of the two given byte slices, they are expected to have valid hexadecimal contents, equal lengths, and packed

Types

type AESOperation

type AESOperation struct {
	Direction Direction
	Mode      CipherMode
	Key       string
	Data      string
	IV        string
}

AESOperation struct to be populated by the caller

func (AESOperation) Calculate

func (op AESOperation) Calculate() (string, error)

Calculate performs a crypto operation as described in the AESOperation variable, which should be populated by the caller

type BERTLVParser

type BERTLVParser struct {
	Input string
}

BERTLVParser struct to be populated by the caller

func (BERTLVParser) Calculate

func (p BERTLVParser) Calculate() (string, error)

Calculate is given a string of BERTLV data and returns the parsed tags

type BERTLVTag

type BERTLVTag struct {
	Tag           string
	Length        int64
	MinLength     int64
	MaxLength     int64
	Value         string
	Name          string
	Format        string
	Valid         bool
	InvalidReason string
}

BERTLVTag struct represents an individual tag

func (BERTLVTag) Calculate

func (t BERTLVTag) Calculate() (string, error)

Calculate is given a single tag to lookup and returns the tag info

type Base64Operation

type Base64Operation struct {
	Direction Direction
	Input     string
}

Base64Operation struct to be populated and provided by the caller

func (Base64Operation) Calculate

func (op Base64Operation) Calculate() (string, error)

Calculate performs the coding operation as described in the Base64Operation variable, which should be populated by the caller

type CVVOperation

type CVVOperation struct {
	PAN         string
	Expiry      string
	ServiceCode string
	CVK         string
}

CVVOperation struct to be populated by the caller

func (CVVOperation) Calculate

func (op CVVOperation) Calculate() (string, error)

Calculate generates the CVVs using data prepared in the CVVOperation variable

type CVVResult

type CVVResult struct {
	CVV  string
	CVV2 string
	ICVV string
}

CVVResult contains the calculated CVV variants

type CipherMode

type CipherMode string

CipherMode specifies a cipher chaining mode

const (
	CipherModeECB CipherMode = "ECB"
	CipherModeCBC            = "CBC"
)

CipherMode specifies a cipher chaining mode

type DESOperation

type DESOperation struct {
	Direction Direction
	Mode      CipherMode
	Key       string
	Data      string
	IV        string
}

DESOperation struct to be populated by the caller

func (DESOperation) Calculate

func (op DESOperation) Calculate() (string, error)

Calculate performs a crypto operation as described in the DESOperation varible, which should be populated be the caller

type Direction

type Direction int

Direction specifies if an operation should encrypt or decrypt

const (
	DirectionEncrypt Direction = iota
	DirectionDecrypt
)

Direction enum specifies if an operation should encrypt or decrypt

type EMVDictionary

type EMVDictionary struct {
	Tags map[string]BERTLVTag
}

EMVDictionary is supported as a singleton which contains EMV tag info for lookups

func GetDictionary

func GetDictionary() *EMVDictionary

GetDictionary returns a populated EMVDictionary

type HMACOperation

type HMACOperation struct {
	Key      string
	Data     string
	HashMode HashMode
}

HMACOperation calculates a HMAC

func (HMACOperation) Calculate

func (op HMACOperation) Calculate() (string, error)

Calculate uses the HMACOperation variables to calculate a HMAC

type HashMode

type HashMode string

HashMode specifies the mode of a hash function

type HashOperation

type HashOperation struct {
	Input    string
	HashMode HashMode
}

HashOperation to be populated by the caller

func (HashOperation) Calculate

func (op HashOperation) Calculate() (string, error)

Calculate generates the hash of SHAOperation input string

type InputName

type InputName string

InputName specifies input element names for error reporting

type LuhnOperation

type LuhnOperation struct {
	Mode  Mode
	Input string
}

LuhnOperation struct to be populated by the caller

func (LuhnOperation) Calculate

func (op LuhnOperation) Calculate() (string, error)

Calculate performs an operation as described in the LuhnOperation variable, which should be populated by the caller

type Mode

type Mode int

Mode specifies if an operation should generate or validate

const (
	ModeGenerate Mode = iota
	ModeValidate
)

Mode enum specifies if an operation should generate or validate

type Operation

type Operation interface {
	Calculate() (string, error)
}

Operation interface is satisfied by all fincrypt tool structs

type PINBlockFormat

type PINBlockFormat string

PINBlockFormat specifies a PIN block format

type PINBlockOperation

type PINBlockOperation struct {
	PAN string
	PIN string
	PPK string
	PBF PINBlockFormat
}

PINBlockOperation used to calculate clear and encrypted PIN blocks

func (PINBlockOperation) Calculate

func (op PINBlockOperation) Calculate() (string, error)

Calculate returns a PINBlockResult containing the clear and encrypted PIN blocks

type PINBlockResult

type PINBlockResult struct {
	ClearPINBlock     string
	EncryptedPINBlock string
}

PINBlockResult contains the clear and encrypted PIN blocks

type PINOffsetOperation

type PINOffsetOperation struct {
	PAN string
	PIN string
	PVK string
	DT  string
}

PINOffsetOperation struct to be populated be the caller

func (PINOffsetOperation) Calculate

func (op PINOffsetOperation) Calculate() (string, error)

Calculate generates a natural PIN and PIN offset from data populated in a PINOffsetOperation variable

type PINOffsetResult

type PINOffsetResult struct {
	NaturalPIN string
	PINOffset  string
}

PINOffsetResult contains the natural PIN and PIN offset

type PVVOperation

type PVVOperation struct {
	PAN  string
	PVKI string
	PIN  string
	PVK  string
}

PVVOperation struct to be populated by the caller

func (PVVOperation) Calculate

func (op PVVOperation) Calculate() (string, error)

Calculate generates a PVV using input data populated in the PVVOperation variable

type RSAOperation

type RSAOperation struct {
	Input           string
	PublicExponent  string
	PrivateExponent string
	Modulus         string
	Label           string
	HashMode        HashMode
	Direction       Direction
}

RSAOperation to be instantiated and populated by the caller

func (RSAOperation) Calculate

func (op RSAOperation) Calculate() (string, error)

Calculate the result of an RSA operation, as described by an instance of RSAOperation

type RetailMACOperation

type RetailMACOperation struct {
	Key     string
	Data    string
	Padding RetailMACPaddingMode
}

RetailMACOperation struct to be populated by the caller

func (RetailMACOperation) Calculate

func (op RetailMACOperation) Calculate() (string, error)

Calculate results in the creation of a Retail MAC

type RetailMACPaddingMode

type RetailMACPaddingMode string

RetailMACPaddingMode specifies the type of padding applied to the data

type SafeNetVariantOperation

type SafeNetVariantOperation struct {
	MK        string
	Variant   string
	Key       string
	Direction Direction
}

SafeNetVariantOperation instance to be instantiated and populated by the caller

func (SafeNetVariantOperation) Calculate

func (op SafeNetVariantOperation) Calculate() (string, error)

Calculate uses a Master Key variant to result in a clear key from an encrypted key or an encrypted key from a clear key

type XOROperation

type XOROperation struct {
	Input1 string
	Input2 string
}

XOROperation struct to be populated and provided by the caller

func (XOROperation) Calculate

func (op XOROperation) Calculate() (string, error)

Calculate that from tiny acorns do mighty oaks grow

Jump to

Keyboard shortcuts

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