Support reading OpenSSH private keys with AEAD encryption #352
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
OpenSSH supports three AEAD algorithms for encrypting private keys: aes128-gcm, aes256-gcm, and chacha20-poly1305. For these encryptions the file format is a bit special: the MAC is just dumped after the encrypted private key data. OpenSSH uses no AAD for these encryptions, and for chacha20-poly1305, the IV is all zeroes (and not generated by the bcrypt KDF).
See also [1] and [2].
Adapt the code to handle both AES-GCM and ChaCha20-Poly1305, clean up a little, and add tests.
[1] https://bugzilla.mindrot.org/show_bug.cgi?id=2366
[2] https://bugzilla.mindrot.org/show_bug.cgi?id=3553