Skip to content

Replace hard-coded GCM tag length with named constant #13162

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Oblivionsage
Copy link

  • Add GCM_STANDARD_TAG_SIZE constant (16 bytes) with NIST SP 800-38D reference
  • Replace magic numbers in tag allocation and validation logic
  • Update error message to use constant value for consistency
  • Improves code maintainability and follows crypto best practices

Tested: GCM functionality preserved, no regressions Resolves TODO comments about hard-coded GCM tag length values

- Add GCM_STANDARD_TAG_SIZE constant (16 bytes) with NIST SP 800-38D reference
- Replace magic numbers in tag allocation and validation logic
- Update error message to use constant value for consistency
- Improves code maintainability and follows crypto best practices

Tested: GCM functionality preserved, no regressions
Resolves TODO comments about hard-coded GCM tag length values
- Add GCM_STANDARD_TAG_SIZE constant (16 bytes) with NIST SP 800-38D reference
- Replace magic numbers in tag allocation and validation logic
- Update error message with defensive handling comment
- Apply Rust formatting and linting standards

Tested: GCM functionality preserved, no regressions
Resolves TODO comments about hard-coded GCM tag length values
@Oblivionsage Oblivionsage force-pushed the fix-gcm-tag-length-constants branch from 29a2cc3 to 1a10ce0 Compare July 10, 2025 10:38
Comment on lines -361 to +368
// XXX: do not hard code 16
let tag = pyo3::types::PyBytes::new_with(py, 16, |t| {
// Allocate buffer for GCM tag
let tag = pyo3::types::PyBytes::new_with(py, GCM_STANDARD_TAG_SIZE, |t| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this isn't actually addressing the comment: the comment is saying that the PyAEADEncryptionContext should work for other tag sizes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex Thanks for the feedback I focused too much on eliminating the hard-coded value and overlooked the broader intent of supporting variable tag sizes

I'm happy to work on a more comprehensive solution, but I'd love some guidance on the approach you'd prefer should I:

  • Research the tag size requirements for different AEAD algorithms(ChaCha20-Poly1305, AES-OCB, etc.) and make the allocation dynamic?
  • Or would it be better to revert this and tackle the broader architectural change in a separate discussion first?

This is a great learning experience for me thanks for pointing me in the right direction

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants