Skip to main content

Overview

The impacket.krb5.crypto module provides cryptographic primitives for Kerberos v5, implementing encryption/decryption, key derivation, checksum operations, and string-to-key functions for multiple cipher suites.

Module Location

Source: impacket/krb5/crypto.py

Supported Encryption Types

Enctype Class

Encryption type identifiers:

Cksumtype Class

Checksum type identifiers:

Key Class

Represents a Kerberos encryption key.
Attributes:
  • enctype: Encryption type identifier
  • contents: Raw key bytes
Example:
Key Sizes:
  • DES: 8 bytes
  • DES3: 24 bytes
  • AES128: 16 bytes
  • AES256: 32 bytes
  • RC4: 16 bytes

String-to-Key Operations

string_to_key Function

Derive key from password and salt.
Parameters:
  • enctype: Encryption type (int)
  • string: Password (str or bytes)
  • salt: Salt value (str or bytes)
  • params: Optional algorithm parameters
Returns: Key object Example:

Salt Generation

Standard Kerberos salt formats:

Algorithm-Specific Details

AES String-to-Key (PBKDF2)

Process:
  1. PBKDF2-HMAC-SHA1(password, salt, iterations, keysize)
  2. Derive using “kerberos” constant

RC4 String-to-Key

Process: MD4(UTF-16LE(password))

DES3 String-to-Key

Process:
  1. n-fold(password + salt, 21)
  2. Random-to-key with parity bits
  3. Derive with “kerberos” constant

Encryption Operations

encrypt Function

Encrypt plaintext with key.
Parameters:
  • key: Key object
  • keyusage: Key usage number (int)
  • plaintext: Data to encrypt (bytes)
  • confounder: Optional confounder (None = random)
Returns: Ciphertext bytes Example:

decrypt Function

Decrypt ciphertext with key.
Parameters:
  • key: Key object
  • keyusage: Key usage number (int)
  • ciphertext: Encrypted data (bytes)
Returns: Plaintext bytes Raises: InvalidChecksum if integrity check fails Example:

Key Usage Numbers

Standard key usage values from RFC 4120:
Example Usage:

Checksum Operations

make_checksum Function

Compute keyed checksum.
Parameters:
  • cksumtype: Checksum type (int)
  • key: Key object
  • keyusage: Key usage number (int)
  • text: Data to checksum (bytes)
Returns: Checksum bytes Example:

verify_checksum Function

Verify keyed checksum.
Parameters:
  • cksumtype: Checksum type (int)
  • key: Key object
  • keyusage: Key usage number (int)
  • text: Data that was checksummed (bytes)
  • cksum: Checksum to verify (bytes)
Raises: InvalidChecksum if verification fails Example:

Advanced Key Operations

random_to_key Function

Convert random bytes to key.
Parameters:
  • enctype: Encryption type (int)
  • seed: Random seed bytes (seedsize length)
Returns: Key object Example:
Seed Sizes:
  • DES: 8 bytes
  • DES3: 21 bytes
  • AES128: 16 bytes
  • AES256: 32 bytes
  • RC4: 16 bytes

prf Function

Pseudo-Random Function for key derivation.
Parameters:
  • key: Key object
  • string: Input string (bytes)
Returns: Output bytes Example:

cf2 Function

Combine two keys (RFC 6113 KRB-FX-CF2).
Parameters:
  • enctype: Target encryption type
  • key1: First Key object
  • key2: Second Key object
  • pepper1: First pepper (bytes)
  • pepper2: Second pepper (bytes)
Returns: Combined Key object Example:
Use Case: FAST armor key generation

Cipher Suite Details

AES Encryption (Simplified Profile)

AES128 and AES256 use RFC 3961 simplified profile: Encryption Process:
  1. Derive Ki = DK(key, usage | 0x55)
  2. Derive Ke = DK(key, usage | 0xAA)
  3. Generate random confounder (16 bytes)
  4. Plaintext’ = confounder + plaintext (zero-padded)
  5. HMAC = HMAC-SHA1(Ki, plaintext’)
  6. Ciphertext = E(Ke, plaintext’) + HMAC[0:12]
Decryption Process:
  1. Derive Ki and Ke
  2. Split ciphertext and MAC
  3. Decrypt: plaintext’ = D(Ke, ciphertext)
  4. Verify: HMAC-SHA1(Ki, plaintext’)[0:12] == MAC
  5. Remove confounder: plaintext = plaintext’[16:]
Example:

RC4 Encryption

RC4-HMAC (also known as ARCFOUR-HMAC-MD5): Encryption Process:
  1. Ki = HMAC-MD5(key, usage)
  2. Checksum = HMAC-MD5(Ki, confounder + plaintext)
  3. Ke = HMAC-MD5(Ki, checksum)
  4. Ciphertext = checksum + RC4(Ke, confounder + plaintext)
Example:

DES3 Encryption

Triple DES with CBC mode: Encryption Process:
  1. Derive Ki = DK(key, usage | 0x55)
  2. Derive Ke = DK(key, usage | 0xAA)
  3. Generate random confounder (8 bytes)
  4. Plaintext’ = confounder + plaintext (zero-padded to 8-byte boundary)
  5. HMAC = HMAC-SHA1(Ki, plaintext’)
  6. Ciphertext = E-DES3-CBC(Ke, plaintext’) + HMAC
Example:

Key Derivation

DK Function (Key Derivation)

Internal function for deriving keys:
Constants:
  • usage | 0x55: Integrity key (Ki)
  • usage | 0xAA: Encryption key (Ke)
  • usage | 0x99: Checksum key (Kc)
  • b'kerberos': Base key derivation
Example (using public API):

Practical Examples

Generate Kerberos Keys

Encrypt/Decrypt Timestamp

Decrypt AS-REP

Compute Authenticator Checksum

Generate Keys from Hash

Security Considerations

Weak Encryption Types

Avoid deprecated algorithms:

Key Storage

Protect cryptographic keys:

Random Number Generation

Use cryptographically secure RNG:

Error Handling

InvalidChecksum Exception

ValueError Exceptions

Performance Considerations

Cipher Selection

Relative Performance (fastest to slowest):
  1. RC4 - Very fast but deprecated
  2. AES128 - Fast and secure
  3. AES256 - Secure, slightly slower
  4. DES3 - Slow, avoid

Key Derivation

Caching Keys

Cache derived keys to avoid repeated computation:

See Also