joyent/node — pull request #6317 by KiNgMaR (2013-10-07 17:43:13+00:00)
Title: node_crypto: Add supported for AES-GCM modes

This adds support for the authenticated encryption mode **GCM** to node-crypto.

**Before**: using aes-128-gcm, aes-192-gcm aes-256-gcm with `createCipheriv` would work, however decryption with `createDecipheriv` would always throw in `final`.

**With patch**: aforementioned modes are now supported. Users have to use `buf = getAuthTag()` after `Final`, transmit the tag with the ciphertext, then use `setAuthTag(buf)` when decrypting. If the data has been tampered with or if no tag is provided during decryption, `final` will throw.

The exception thrown from `final` is currently generic. I can make it more verbose/clear if wanted.

**Limitations**: it's not possible to add any AAD (additional authenticated data) into the mix (or verify it). This could be achieved by adding another method to `Cipheriv`, e.g. `setAdditionalAuthenticatedData(buf)`.

**Other AEAD modes:** The AES-CCM mode cannot be used with the current API because it does not support streaming (the *total* length of the plain / cipher text has to be known when the first `update` call is made). Unless limiting users to 1 call of `update` was ok, of course.
Composite ciphers such as AES-128-CBC-HMAC-SHA1 use a different OpenSSL API, which is rather poorly documented (and only used in OpenSSL's TLS implementation as far as I can tell), so supporting these is not currently in scope of this pull request either.

Thanks for considering.