-
Notifications
You must be signed in to change notification settings - Fork 8
Cipher traits #69
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
Cipher traits #69
+1,944
−15
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
Add cipher traits for the OpenPRoT blocking HAL: - SymmetricCipher: Type definitions for keys, nonces, plaintext, ciphertext - CipherInit: Initialize cipher contexts with keys and modes - CipherOp: Encrypt/decrypt operations with error handling - CipherStatus: Hardware status monitoring (ready, idle, output available) - CipherMode markers: BlockCipherMode, AeadCipherMode, StreamCipherMode - SecureCipherOp: State cleanup and zeroization - BlockAligned: Container for block-aligned data - AeadCipherOp: Authenticated encryption with associated data Features: - Zero-copy serialization via zerocopy crate - Error mapping with ErrorKind enum - Support for software and hardware implementations Provides foundation for cipher implementations across OpenPRoT.
Add AES-256-CTR cipher implementation using RustCrypto as reference implementation of the HAL cipher traits. Implementation: - AES-256-CTR using aes v0.8.4 and ctr v0.9.2 crates - Single-use contexts for security - Test suite with NIST test vectors - no_std compatibility for embedded systems - Zero-copy operations Dependencies: - aes = "0.8.4" (AES block cipher) - ctr = "0.9.2" (CTR mode) - cipher = "0.4.4" (Cipher traits) - generic-array = "0.14.7" (Fixed arrays) Serves as both functional cipher and reference for implementing HAL cipher traits with other libraries or hardware accelerators.
Replace Vec<u8> suggestions with no_std alternatives like [u8; N] and custom containers. Removes heap allocation references from embedded systems documentation.
Replace problematic intra-doc links with code formatting to resolve rustdoc warnings in digest and i2c_device modules.
The buffer module provided FixedPlainText and FixedCipherText wrapper types but was not used by the current AES-CTR cipher implementation, which uses simple [u8; 256] arrays directly. Removing it simplifies the crate and follows YAGNI principles. - Remove buffer module declaration from lib.rs - Remove buffer type re-exports (BufferError, FixedCipherText, etc.) - Delete unused buffer.rs file All cipher tests continue to pass with this simplification.
Add #[allow(clippy::unwrap_used)] attribute to the cipher test module to permit unwrap() calls in test code while maintaining strict safety in production code. This follows Rust best practices where: - Production code remains panic-free (no unwrap/expect/panic) - Test code can use unwrap() for fail-fast behavior and cleaner assertions - Tests are meant to panic immediately when assumptions are violated All clippy warnings about unwrap usage are now resolved while preserving test readability and maintaining security guidelines for production code.
Replace all direct array indexing with safe .get() and .get_mut() methods in the BlockAligned container implementation to prevent potential panics and meet strict security requirements. **Production code fixes:** - from_slice_padded(): Use get_mut(i) instead of blocks[i] - push_block(): Use get_mut(block_count) instead of blocks[block_count] - get_block(): Use get(index) instead of &blocks[index] **Test code fixes:** - Replace blocks[0] and blocks[1] with safe .get() calls - Replace third_block[0] with safe .get() access **Security improvements:** - Zero panic risk: All array access now bounds-checked - Proper error handling: Failed access returns errors instead of panicking - Compliance: Follows security guidelines forbidding direct indexing All tests pass and clippy indexing warnings are eliminated while maintaining full functionality and performance.
9c965fe to
0451018
Compare
Add backticks around type references to prevent rustdoc from interpreting them as HTML tags: - `Option<u8>` instead of Option<u8> - `Option<enum>` instead of Option<enum> This eliminates the rustdoc warnings: - warning: unclosed HTML tag `u8` - warning: unclosed HTML tag `enum` The type references are now properly formatted as code in the generated documentation.
Address clippy warnings for safer and more idiomatic code: **get_first warnings:** - Replace `.get(0)` with `.first()` for accessing first array elements - More expressive and idiomatic Rust code **arithmetic_side_effects warnings:** - Replace `+=` with `.saturating_add()` for safe increment - Replace `*` with `.saturating_mul()` for safe multiplication - Prevents potential overflow in arithmetic operations **Security improvements:** - Arithmetic operations now cannot overflow/panic - Follows security guidelines for overflow-safe operations - All tests continue to pass with improved safety These changes align with the project's strict safety requirements while maintaining full functionality and performance.
Add #[allow(clippy::unwrap_used)] attribute to the RustCrypto cipher test module to permit unwrap() calls in test code while maintaining strict safety in production code. This matches the pattern established in the HAL cipher tests where: - Production code remains panic-free (no unwrap/expect/panic) - Test code can use unwrap() for fail-fast behavior and cleaner assertions - Tests are meant to panic immediately when assumptions are violated Resolves clippy warnings about unwrap usage in the comprehensive AES-CTR test suite while preserving test readability and maintaining security guidelines for production code.
Apply cargo fmt formatting to correct comment spacing from double space to single space after // in the clippy allow attribute: - `#[allow(clippy::unwrap_used)] // Allow unwrap...` + `#[allow(clippy::unwrap_used)] // Allow unwrap...` This ensures consistent formatting according to Rust style guidelines and passes `cargo fmt --check` validation.
FerralCoder
approved these changes
Oct 15, 2025
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.
Add Symmetric Cipher Support to OpenPRoT HAL
Summary
Introduces symmetric cipher capabilities with HAL traits and RustCrypto reference implementation.
Changes
HAL Cipher Traits
SymmetricCipher,CipherInit,CipherOp,CipherStatusAeadCipherOpfor authenticated encryptionBlockAlignedcontainer, cipher mode markersRustCrypto reference Implementation
no_stdcompatible