Skip to content

Conversation

@sumeruchat
Copy link
Collaborator

Fix Variable IV Length Issue

@sumeruchat sumeruchat requested a review from evantk91 January 2, 2025 16:02
Copy link
Contributor

@evantk91 evantk91 left a comment

Choose a reason for hiding this comment

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

Added some clarifications

combined[0] = if (encryptedData.isModernEncryption) 1 else 0
System.arraycopy(encryptedData.iv, 0, combined, 1, encryptedData.iv.size)
System.arraycopy(encryptedData.data, 0, combined, 1 + encryptedData.iv.size, encryptedData.data.size)
combined[1] = encryptedData.iv.size.toByte() // Store IV length
Copy link
Contributor

Choose a reason for hiding this comment

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

I see IV length is pulled from data instead of being hardcoded.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right so we have variable iv lenghts and we encode it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and then when we decode it we know what the iv length was

val cipher = Cipher.getInstance(TRANSFORMATION_MODERN)
val iv = generateIV()
val spec = GCMParameterSpec(GCM_TAG_LENGTH, iv)
cipher.init(Cipher.ENCRYPT_MODE, getKey(), spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is generateIV removed here? Seems like it should follow encrypt legacy but with modern set to true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in modern we dont generate instead we let android generate it

@sumeruchat sumeruchat merged commit 897fd9e into master Jan 2, 2025
3 of 4 checks passed
@sumeruchat sumeruchat deleted the feature/MOB-9235-fix-iv-length-issue branch January 2, 2025 18:52
Sign up for free to 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.

3 participants