crypto

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Supported DES key lengths in bits.
	KeyLength64  = 64  // Single length DES key (8 bytes)
	KeyLength128 = 128 // Double length DES key (16 bytes)
	KeyLength192 = 192 // Triple length DES key (24 bytes)

	// Number of bytes in key check value.
	KCVLength = 3
)

Constants for key handling.

Variables

View Source
var (
	ErrInvalidKeyLength      = errors.New("invalid key length")
	ErrInvalidHexString      = errors.New("invalid hex string")
	ErrInvalidKeyFormat      = errors.New("invalid key format")
	ErrInvalidComponentCount = errors.New("invalid component count")
)

Common errors.

Functions

func CalculateKCV

func CalculateKCV(keyBytes []byte) []byte

CalculateKCV calculates a 3-byte Key Check Value for a key using DES. For single length key (8 bytes) - uses single DES. For double length key (16 bytes) - uses triple DES (EDE) with K1,K2,K1. For triple length key (24 bytes) - uses triple DES (EDE). If DES encryption fails, it falls back to using the first 3 bytes of the key.

func CombineComponents

func CombineComponents(components []string) (string, error)

CombineComponents combines multiple key components to reconstruct the original key. Components must be provided as hex strings. Returns the reconstructed key as a hex string.

func GenerateKey

func GenerateKey(lengthBits int, enforceOddParity bool) (string, string, error)

GenerateKey generates a random cryptographic key of the specified length in bits. Returns the key as a hex string and its KCV, or an error if the length is invalid. If enforceOddParity is true, each byte in the key will have odd parity.

func SplitKey

func SplitKey(keyHex string, numComponents int) ([]string, string, error)

SplitKey splits a key into the specified number of XOR components. The key must be provided as a hex string. Returns the components as hex strings and the KCV of the original key.

func ValidateComponentConsistency

func ValidateComponentConsistency(original string, components []string) bool

ValidateComponentConsistency checks if the components will XOR back to the original key. Returns true if the components are consistent, false otherwise.

func ValidateKeyParity

func ValidateKeyParity(key []byte) bool

ValidateKeyParity checks if all bytes in a DES key have odd parity.

Types

This section is empty.

Jump to

Keyboard shortcuts

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