Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateKCV(keyBytes []byte) []byte
- func CombineComponents(components []string) (string, error)
- func GenerateKey(lengthBits int, enforceOddParity bool) (string, string, error)
- func SplitKey(keyHex string, numComponents int) ([]string, string, error)
- func ValidateComponentConsistency(original string, components []string) bool
- func ValidateKeyParity(key []byte) bool
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ValidateComponentConsistency checks if the components will XOR back to the original key. Returns true if the components are consistent, false otherwise.
func ValidateKeyParity ¶
ValidateKeyParity checks if all bytes in a DES key have odd parity.
Types ¶
This section is empty.