-
Notifications
You must be signed in to change notification settings - Fork 1
NanoTDF #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
NanoTDF #49
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implement Phase 1 of NanoTDF v1 specification support: ## Binary Serialization (crates/protocol/src/binary/) - Big-endian integer operations (u8, u16, u24, u32) - BinaryRead/BinaryWrite traits for serialization - Full test coverage with roundtrip validation ## NanoTDF Protocol Types (crates/protocol/src/nanotdf/) - Resource Locator: Compact URL references (HTTP/HTTPS/SharedDir) - Protocol enum with identifier support (0/2/8/32 bytes) - URL parsing and serialization - Header structures: - Magic number validation (L1L = 0x4C314C) - ECC modes: secp256r1, secp384r1, secp521r1, secp256k1 - Binding modes: ECDSA vs GMAC - Symmetric ciphers: AES-256-GCM (64-128 bit tags) - Complete header with all bitfields - Policy types: - Remote (Resource Locator reference) - Embedded plaintext - Embedded encrypted (with optional key access) - Cryptographic binding support ## Constants - HKDF salt from spec: SHA256(magic + version) - Reserved policy IV: 0x000000 - Size limits and validation ## Testing - 19 passing unit tests - All clippy checks pass - Zero compiler warnings Related to #32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implement full ECDH + HKDF-SHA256 key derivation supporting all 4 curves: ## Elliptic Curve Support - **P-256** (secp256r1): Primary curve for NanoTDF - **P-384** (secp384r1): Enhanced security level - **P-521** (secp521r1): Maximum security level - **secp256k1**: Bitcoin curve support ## Implementation - ECDH key agreement with ephemeral key pairs - HKDF-SHA256 key derivation per NanoTDF spec - Salt: SHA256(MAGIC_NUMBER + VERSION) = 0x3de3ca... - Empty info parameter (spec compliant) - Derives 32-byte AES keys for encryption ## Key Features - Zeroizing types for shared secrets - Compressed public key format (SEC1) - Support for both DER formats (SEC1 and PKCS#8) - Separate encrypt/decrypt flows: - `derive_key_with_ephemeral()`: Encryption (generates ephemeral pair) - `derive_key_with_private()`: Decryption (uses recipient private key) ## Dependencies Added to Cargo.toml (kas feature): - p384: NIST P-384 curve - p521: NIST P-521 curve - k256: secp256k1 (Bitcoin curve) ## Testing - Round-trip key derivation for P-256 - HKDF salt verification against spec - All 4 curves tested for successful derivation - Compressed key size validation ## Error Handling Added to KemError: - InvalidPublicKey - InvalidPrivateKey - KeyDerivationFailed Related to #32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implement NanoTDF-specific cryptographic operations: ## AES-256-GCM with 3-byte IV - 3-byte IV support (padded to 12 bytes for GCM) - Reserved IV (0x000000) for encrypted policy - 128-bit tag support (currently limited by aes-gcm crate) - Clean encrypt/decrypt API ## GMAC Policy Binding - GMAC tag generation (GCM with empty plaintext) - 64-bit GMAC tags for policy binding - Constant-time verification ## Tag Size Support - TagSize enum (64/96/104/112/120/128 bits) - Currently only 128-bit tags fully supported - Tagged for future enhancement with variable tag library - Documented limitation clearly ## Implementation Notes - The aes-gcm crate only supports 128-bit tags - Variable tag sizes (64-120 bits) from NanoTDF spec require different crypto implementation (e.g., RustCrypto AES-GCM low-level) - For MVP, using 128-bit tags is acceptable and secure ## Testing - 7/7 tests passing - IV conversion and padding - Encrypt/decrypt round-trips - GMAC generation and verification - Tag size validation - Reserved policy IV Related to #32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit contains the foundation for NanoTDF v1 support: ## Completed ✅ - Binary serialization infrastructure (protocol crate) - NanoTDF header structures with all bitfields - Resource Locator, Policy types (Remote, Embedded, Encrypted) - ECDH key exchange for all 4 curves (P-256, P-384, P-521, secp256k1) - HKDF-SHA256 key derivation with NanoTDF salt - AES-256-GCM with variable tag sizes (96-128 bit) - GMAC policy binding (96-bit tags) - Platform integration test infrastructure - Complete NanoTDF payload structure - Full encode/decode API skeleton ## In Progress 🚧 - NanoTDF implementation has compilation errors: - Need to use correct Header constructor (ecc_and_binding_mode, symmetric_and_payload_config) - Need to use EC KEM methods: derive_key_with_ephemeral/derive_key_with_private - Need to fix ResourceLocator constructor calls - Need to convert ephemeral_public_key slice to Vec ## Testing Status ✅ - Platform connectivity: PASSING - Authentication (client_credentials): PASSING - KAS public key retrieval: PASSING - 7 integration tests created and ready ## Known Limitations - 64-bit GCM tags: Mbed TLS scaffolded but not complete (RustCrypto only supports 96-128 bit) - ECDH policy binding: Not yet implemented (GMAC working) - ECDSA signatures: Not yet implemented - Cross-platform tests: Pending completion of encode/decode ## Next Steps 1. Fix Header API usage in nanotdf.rs 2. Fix EC KEM method calls 3. Build and test basic roundtrip 4. Verify otdfctl NanoTDF support 5. Cross-platform compatibility testing Related: #32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Comprehensive guide for next session including: - All compilation errors to fix with exact corrections - Test implementation examples - Cross-platform testing approach - Architecture summary - Important implementation notes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fix critical bug preventing cross-platform compatibility with otdfctl/Go SDK. The payload length field was being misinterpreted - it includes the IV, not just ciphertext+tag. This caused parse failures when reading otdfctl-created files and prevented otdfctl from decrypting Rust files. Changes: - Fixed BinaryRead for NanoTdfPayload to read length as total bytes including IV, then extract IV from first 3 bytes - Fixed payload creation to set length = 3 + ciphertext_and_tag.len() - Updated policy binding to use SHA-256 last 8 bytes (L1L v12 spec) - Fixed IV padding to use prefix format: [9 zeros][3-byte IV] - Added support for KAS resource locator with key ID - Fixed clippy warnings (clone_on_copy, expect_fun_call, io_other_error) Testing: ✅ Rust → Rust roundtrip works ✅ Rust → otdfctl decrypt succeeds ✅ otdfctl → Rust parsing succeeds ✅ Full cross-platform compatibility achieved Fixes #32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace deprecated `GenericArray::from_slice()` calls with direct nonce conversion using `.into()` to fix CI warnings in lint and wasm jobs. Changes: - Remove `generic_array::GenericArray` import from aes-gcm - Use `(&nonce_bytes).into()` instead of `GenericArray::from_slice()` - Fix test_iv_conversion test to match correct IV padding (suffix format) - Add missing `header` field to KeyAccessObject in WASM KAS client The aes-gcm 0.10.3 crate deprecated direct GenericArray usage in favor of the modern API. This fix eliminates all 34 deprecation warnings that were causing CI failures with `-D warnings` flag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The previous commit only fixed Nonce usage but missed Key::from_slice calls which also use deprecated GenericArray. This completes the fix. Changes: - Replace `Key::<Type>::from_slice()` with `.into()` in all cipher creation - Remove unused `Key` import - Now all 11 GenericArray deprecation warnings are eliminated 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Bump workspace version from 0.5.0 to 0.6.0 to reflect the substantial new NanoTDF L1L v12 feature addition. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Move all documentation files to docs/ directory for better organization: - Moved existing docs (BENCHMARKS, INTEROPERABILITY, etc.) to docs/ - Consolidated NanoTDF documentation into docs/NANOTDF.md - Added all NANOTDF_*.md reference documents - Added NanoTDF example programs This improves project structure and makes documentation easier to find. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Closes #32
Implements complete NanoTDF L1L v12 support with full cross-platform compatibility with otdfctl and the OpenTDF Go SDK.
This PR includes:
Implementation Details
Core Components (~4,300 lines)
Protocol Layer (
crates/protocol/src/)Cryptography (
crates/crypto/src/)KAS Integration (
src/kas.rs)Key Technical Decisions
[9 zero bytes][3-byte random IV]- matches otdfctlSHA256("L1L")=3de3ca1e...(spec constant)Bug Fix (Most Recent Commit)
Critical payload length interpretation bug preventing cross-platform compatibility:
Testing
Unit & Integration Tests
Includes tests for:
Cross-Platform Verification
✅ Rust → otdfctl Decryption
$ cargo run --example nanotdf_with_kas_key Created: /tmp/test-with-kas-key.nanotdf (204 bytes) $ otdfctl decrypt /tmp/test-with-kas-key.nanotdf \ --host http://localhost:8080 --tls-no-verify \ --with-client-creds '{"clientId":"opentdf","clientSecret":"secret"}' Hello from Rust using real KAS key!✅ otdfctl → Rust Parsing
Compatibility Matrix
Examples Included
examples/nanotdf_with_kas_key.rs- Creates NanoTDF with real KAS EC public keyexamples/decrypt_otdfctl_nanotdf.rs- Parses otdfctl-created filesFiles Changed
New Files
crates/protocol/src/binary/- Binary I/O framework (168 lines)crates/protocol/src/nanotdf/- NanoTDF protocol types (1,181 lines)header.rs- Header structures with bitfield encodingpolicy.rs- Policy types and serializationresource_locator.rs- URL encoding with key identifiercrates/crypto/src/tdf/nanotdf.rs- Main NanoTDF implementation (623 lines)crates/crypto/src/tdf/nanotdf_crypto.rs- AES-GCM with RustCrypto (439 lines)crates/crypto/src/tdf/nanotdf_crypto_mbedtls.rs- Mbed TLS backend (376 lines)crates/crypto/src/kem/ec.rs- ECDH+HKDF implementation (449 lines)tests/nanotdf_integration.rs- Integration test suite (267 lines)tests/platform_integration.rs- Platform tests (169 lines)NANOTDF_PAYLOAD_LENGTH_BUG_FIX.md- Bug fix documentationModified Files
crates/crypto/Cargo.toml- Added EC curve dependencies (p256, p384, p521, k256)crates/protocol/src/kas.rs- Addedheaderfield for NanoTDF rewrapsrc/kas.rs- Addedrewrap_nanotdf()methodDependencies Added
Breaking Changes
None - This is a new feature addition.
Future Work
Related Issues
Fixes #32
Checklist
cargo fmt --all)Review Notes
This is a substantial feature addition (~4,300 lines) implementing the complete NanoTDF specification. The implementation has been verified to work with otdfctl and the OpenTDF platform.
Key areas for review:
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com