cryptoutils

package
v0.0.0-...-1733d6c Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cryptoutils provides cryptographic utility functions.

Index

Constants

View Source
const DES_BLOCK_SIZE_BYTES = 8

Variables

This section is empty.

Functions

func CryptCBC

func CryptCBC(blockCipher cipher.Block, iv []byte, data []byte, encrypt bool) []byte

func CryptoHash

func CryptoHash(alg crypto.Hash, data []byte) []byte

func CryptoHashByOid

func CryptoHashByOid(oid asn1.ObjectIdentifier, data []byte) []byte

hashes the data using the hash algorithm specified by oid panics if hash algorithm is not supported

func CryptoHashDigestSize

func CryptoHashDigestSize(alg crypto.Hash) int

func CryptoHashOidToAlg

func CryptoHashOidToAlg(oid asn1.ObjectIdentifier) crypto.Hash

panics if hash algorithm is not supported

func DesKeyAdjustParity

func DesKeyAdjustParity(key []byte) []byte

func EllipticP192

func EllipticP192() elliptic.Curve

support for P192 (secp-192r1) which is required by some countries but not supported by the go libraries

func EncodeX962EcPoint

func EncodeX962EcPoint(ec elliptic.Curve, point *EcPoint) []byte

func GetCipherForKey

func GetCipherForKey(alg BlockCipherAlg, key []byte) (cipher.Block, error)

NB supports 8/16/24 byte key lengths for DES

func ISO9797Method2Pad

func ISO9797Method2Pad(data []byte, blockSize int) []byte

func ISO9797Method2Unpad

func ISO9797Method2Unpad(data []byte) []byte

panics if data is not padded

func ISO9797RetailMacDes

func ISO9797RetailMacDes(key []byte, data []byte) (mac []byte, err error)

ISO-9797 Retail MAC (DES) key: 16 bytes (double) DES key error: if invalid key length (not 16 bytes) or data not aligned to block boundary (8 bytes)

func KDF

func KDF(k []byte, c KDFCounterType, alg BlockCipherAlg, keySizeBits int) []byte

NB expects keySizeBits=112 for TDES

func RandomBytes

func RandomBytes(length int) []byte

func RsaDecryptWithPublicKey

func RsaDecryptWithPublicKey(ciphertext []byte, publicKey RsaPublicKey) []byte

Types

type BlockCipherAlg

type BlockCipherAlg int
const (
	DES BlockCipherAlg = iota
	TDES
	AES
)

type ECCurve

type ECCurve struct {
	A    []byte
	B    []byte
	Seed asn1.BitString `asn1:"optional"`
}

type ECField

type ECField struct {
	FieldType  asn1.ObjectIdentifier
	Parameters asn1.RawValue
}

type EcKeypair

type EcKeypair struct {
	Pri []byte
	Pub *EcPoint
}

func KeyGeneratorEc

func KeyGeneratorEc(ec elliptic.Curve) EcKeypair

func (EcKeypair) String

func (ecKeypair EcKeypair) String() string

type EcPoint

type EcPoint struct {
	X *big.Int
	Y *big.Int
}

func DecodeX962EcPoint

func DecodeX962EcPoint(ec elliptic.Curve, data []byte) *EcPoint

func DoEcDh

func DoEcDh(localPrivate []byte, remotePublic *EcPoint, ec elliptic.Curve) *EcPoint

func (EcPoint) Equal

func (ec EcPoint) Equal(ec2 EcPoint) bool

func (EcPoint) String

func (ec EcPoint) String() string

type KDFCounterType

type KDFCounterType int
const (
	KDF_COUNTER_KSENC KDFCounterType = 1
	KDF_COUNTER_KSMAC KDFCounterType = 2
	KDF_COUNTER_PACE  KDFCounterType = 3
)

type KeyGeneratorEcFn

type KeyGeneratorEcFn func(ec elliptic.Curve) EcKeypair

type RandomBytesFn

type RandomBytesFn func(length int) []byte

type RsaPublicKey

type RsaPublicKey struct {
	N *big.Int
	E int
}

RFC 3279 (RSA Keys)

Jump to

Keyboard shortcuts

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