crypto: support GCM authenticated encryption mode.

This adds two new member functions getAuthTag and setAuthTag that
are useful for AES-GCM encryption modes. Use getAuthTag after
Cipheriv.final, transmit the tag along with the data and use
Decipheriv.setAuthTag to have the encrypted data verified.
This commit is contained in:
Ingmar Runge authored and Fedor Indutny committed 2013-12-08 00:00:02 +04:00
1 parent f9f9239fa2
commit e0d31ea2db
5 files changed
+260 -1

No files matched your search

+16
View File
@@ -218,6 +218,13 @@ multiple of the cipher's block size or `final` will fail. Useful for
non-standard padding, e.g. using `0x0` instead of PKCS padding. You
must call this before `cipher.final`.
### cipher.getAuthTag()
For authenticated encryption modes (currently supported: GCM), this
method returns a `Buffer` that represents the _authentication tag_ that
has been computed from the given data. Should be called after
encryption has been completed using the `final` method!
## crypto.createDecipher(algorithm, password)
@@ -268,6 +275,15 @@ removing it. Can only work if the input data's length is a multiple of
the ciphers block size. You must call this before streaming data to
`decipher.update`.
### decipher.setAuthTag(buffer)
For authenticated encryption modes (currently supported: GCM), this
method must be used to pass in the received _authentication tag_.
If no tag is provided or if the ciphertext has been tampered with,
`final` will throw, thus indicating that the ciphertext should
be discarded due to failed authentication.
## crypto.createSign(algorithm)
Creates and returns a signing object, with the given algorithm. On