paysec-keyblock
TR-31 key-block support for payment-security applications.
The crate provides functionality for wrapping and unwrapping cryptographic keys using the TR-31 key-block format.
Supported functionality
The current implementation focuses on TR-31 Version D and includes:
- TR-31 key-block header handling
- optional blocks
- AES-CMAC-based KBEK and KBAK derivation
- authenticated key wrapping
- key-block unwrapping and authentication
- masked key lengths and payload padding
- structural and header validation
- zeroizing secret key material
Cryptographic operations are delegated to a paysec-crypto provider.
Installation
[]
= "0.4"
= "0.2.1"
= "0.2.1"
= "0.2.1"
Example
The following example wraps and unwraps a key using TR-31 Version D with the RustCrypto provider:
use AesKeySize;
use RustCryptoProvider;
use ;
let provider = new;
let header = new_with_values
.unwrap;
let key = decode
.unwrap;
let random_seed = decode
.unwrap;
let kbpk = decode
.unwrap;
let key_block = tr31_wrap
.unwrap;
let = tr31_unwrap
.unwrap;
assert_eq!;
assert_eq!;
Secret key material
Plaintext key material returned by TR-31 unwrapping is represented by
SecretKey.
SecretKey:
- redacts its contents from
Debug - zeroizes owned key material when dropped
- requires explicit access through
expose_secret()
The software cryptographic providers operate on raw key material in process memory. Applications requiring stronger isolation remain responsible for selecting an appropriate provider and key-management environment.
Randomness
TR-31 wrapping requires caller-supplied random data.
The crate deliberately does not choose a random-number generator internally. This enables deterministic standards testing and leaves entropy generation under application or provider control.
Production applications are responsible for providing randomness appropriate for their security requirements.
Security
Using this crate does not by itself establish compliance with PCI, ANSI, or other payment-security requirements.
Applications remain responsible for secure key storage, access control, key lifecycle management, and deployment controls appropriate to their environment.
For the complete project overview, see the
paysec repository.