Skip to main content

Crate opentdf_crypto

Crate opentdf_crypto 

Source
Expand description

OpenTDF Cryptographic Operations

This crate provides cryptographic operations for OpenTDF with security hardening:

  • Zeroizing key types that automatically clear memory
  • Constant-time HMAC verification
  • KEM abstractions for RSA, EC, and future post-quantum algorithms
  • Segment-based encryption for standard TDF
  • NanoTDF API structure (implementation pending)

§Security Features

  • Zeroization: All key material uses zeroize to clear memory on drop
  • Constant-time comparison: MAC verification uses subtle::ConstantTimeEq
  • Future-ready: Abstractions for post-quantum cryptography (ML-KEM)

§Example

use opentdf_crypto::tdf::TdfEncryption;

// Create encryption instance with generated keys
let tdf = TdfEncryption::new()?;

// Encrypt data
let data = b"sensitive information";
let encrypted = tdf.encrypt(data)?;

// Decrypt (legacy format)
let decrypted = TdfEncryption::decrypt_legacy(tdf.policy_key(), &encrypted)?;
assert_eq!(data, decrypted.as_slice());

Re-exports§

pub use helpers::CryptoError;
pub use helpers::create_aes_cipher;
pub use helpers::generate_key_32;
pub use helpers::generate_nonce;
pub use hmac::HmacError;
pub use hmac::calculate_hmac;
pub use hmac::calculate_policy_binding;
pub use hmac::calculate_root_signature;
pub use hmac::verify_root_signature;
pub use hmac::verify_segment_hash;
pub use kem::KemError;
pub use kem::KeyEncapsulation;
pub use tdf::EncryptedPayload;
pub use tdf::EncryptedSegment;
pub use tdf::SegmentInfo;
pub use tdf::SegmentedPayload;
pub use tdf::TdfEncryption;
pub use types::AesKey;
pub use types::KeyError;
pub use types::Nonce96;
pub use types::PayloadKey;
pub use types::PolicyKey;
pub use kem::pqc::HybridKem;
pub use kem::pqc::MlKemLevel;
pub use kem::pqc::MlKemWrapper;
pub use tdf::encryption::EncryptionError;

Modules§

helpers
Cryptographic helper functions
hmac
HMAC operations with constant-time verification
kem
Key Encapsulation Mechanisms (KEM)
tdf
TDF encryption implementations
types
Zeroizing cryptographic key types