Skip to main content

Module hctr2fp

Module hctr2fp 

Source
Expand description

HCTR2+FP (Format-Preserving) variant of HCTR2.

While standard HCTR2 operates on arbitrary bytes, HCTR2+FP ensures that ciphertext consists only of digits in a specified radix (e.g., decimal digits 0-9 for radix-10).

Use cases:

  • Encrypting credit card numbers (decimal)
  • Encrypting alphanumeric identifiers (hexadecimal or custom radix)
  • Systems requiring format-preserving encryption

Security properties:

  • Ciphertext length equals plaintext length
  • All ciphertext digits are in range [0, radix)
  • Requires unique (key, tweak) pairs for security
  • No authentication - consider AEAD if integrity protection is needed
  • Minimum message length depends on radix (e.g., 39 digits for decimal)

Structs§

Hctr2Fp
Generic HCTR2+FP cipher.

Functions§

bits_per_digit
Compute bits per digit for power-of-2 radix.
decode_base_radix
Decode base-radix digits (little-endian) to a 128-bit value.
encode_base_radix
Encode a 128-bit value as base-radix digits (little-endian).
first_block_length
Compute the minimum number of base-radix digits needed to represent 128 bits. This is: ceil(128 / log2(radix)) = smallest k where radix^k >= 2^128
is_power_of_two
Check if a number is a power of two.

Type Aliases§

Hctr2FpErrorDeprecated
Hctr2Fp_128_Base64
HCTR2+FP with AES-128 and base-64 (radix-64) format preservation.
Hctr2Fp_128_Decimal
HCTR2+FP with AES-128 and decimal (radix-10) format preservation.
Hctr2Fp_128_Hex
HCTR2+FP with AES-128 and hexadecimal (radix-16) format preservation.
Hctr2Fp_256_Base64
HCTR2+FP with AES-256 and base-64 (radix-64) format preservation.
Hctr2Fp_256_Decimal
HCTR2+FP with AES-256 and decimal (radix-10) format preservation.
Hctr2Fp_256_Hex
HCTR2+FP with AES-256 and hexadecimal (radix-16) format preservation.