Skip to content

Handles variable-length nonce - #125

Closed
masihyeganeh wants to merge 3 commits into
RustCrypto:masterfrom
masihyeganeh:patch-1
Closed

Handles variable-length nonce#125
masihyeganeh wants to merge 3 commits into
RustCrypto:masterfrom
masihyeganeh:patch-1

Conversation

@masihyeganeh

Copy link
Copy Markdown
Contributor

I'm trying to fix#62, but I'm not sure I'm on the right track.
I read source code of other implementations of variable-length nonce GCM. They do it like this:

  • if nonce is 12 bytes, copy the nonce in counter and add 1 to the last bit
  • else copy GHASH of nonce to counter

I did that here. Maybe it's wrong. I'm not sure.
This will be a breaking change but as mentioned in here, it is time to introduce breaking changes.

Comment threadaes-gcm/src/lib.rs
fn encrypt_in_place_detached(
&self,
nonce: &GenericArray<u8, Self::NonceSize>,
nonce: &[u8],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would require a change in the Aead trait. See RustCrypto/traits#65

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah. I did that too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aah, apologies!

@tarcieri

Copy link
Copy Markdown
Member

@masihyeganeh so there's another option which preserves type safety for all nonce sizes and avoids making changes to the underlying trait... that would be making the AES implementation generic around different nonce sizes much in the same way it's already generic around B::ParBlocks.

I think that's probably the best way to go in general, actually. If you'd like I can adapt your PR to do do that, as generic-array and typenum are a bit mindbending.

@masihyeganeh

Copy link
Copy Markdown
ContributorAuthor

@tarcieri That would be great. let me know if I can help with that

@tarcieri

Copy link
Copy Markdown
Member

I've open a PR based on this one which makes AesGcm generic around the nonce size: #126

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GCM: Allow nonces of any length

3 participants

@masihyeganeh@tarcieri@XinGOfCloude18