Zero temporary buffers that hold key material and reduce more allocations #493
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #493"
general
weight: 0.35
Lukasa
Motivation:
AES-KeyWrap unwrap, ML-KEM decapsulation, PBKDF2, and scrypt each write the key they return into a temporary buffer, copy it into a
SymmetricKey, and free the buffer without zeroing it. TheSymmetricKeystores its copy inSecureBytes, which zeroes the copy before freeing it. Nothing zeroes the original.AES-KeyWrap and ML-KEM can write the key directly into the
SymmetricKey, as X-Wing already does. That removes both the buffer and the copy. PBKDF2 and scrypt can't, because they are in CryptoExtras andSymmetricKey(unsafeUninitializedCapacity:initializingWith:)is internal to Crypto. They keep their buffer and zero it after the copy. Moving that buffer onto the stack made them twice as slow.Modifications:
SymmetricKeySymmetricKey. RegeneratingMLKEM_boring.swiftfrom its.gybalso drops five@availableattributes that were only ever in the generated file.Result:
AES.KeyWrap.unwrapmakes 2 allocations instead of 3 and is about 6% faster.MLKEM768.PrivateKey.decapsulatemakes 2 allocations instead of 4.KDF.Insecure.PBKDF2.deriveKeyandKDF.Scrypt.deriveKeymake the same number of allocations and take the same time as before.Benchmarks:
The tables come from
swift package benchmark --metric mallocCountTotal --metric wallClock.