Skip to content

Conversation

@Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Jan 23, 2023

AES.GCM.SealedBox is expensive to construct from parts, in part because it's not inlinable. We can construct the combined representation directly and improve performance substantially by replacing 8 allocations with 3.

AES.GCM.SealedBox is expensive to construct from parts, in part because
it's not inlinable. We can construct the combined representation
directly and improve performance substantially by replacing 8
allocations with 3.
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jan 23, 2023
// As a workaround for a Swift Crypto inefficiency, we create the combined representation
// directly.
var combined: [UInt8] = []
combined.reserveCapacity(12 + ciphertext.count + tag.count)
Copy link
Member

Choose a reason for hiding this comment

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

can we add a comment that 12 is the size of nonce or can we make it a static property on SSHAESGCMNonce?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Lukasa Lukasa enabled auto-merge (squash) January 23, 2023 15:48
@Lukasa Lukasa merged commit baa05dc into apple:main Jan 23, 2023
@Lukasa Lukasa deleted the cb-improve-sealed-box-construction branch January 23, 2023 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants