crypto: nx - fix GCM for zero length messages
authorMarcelo Cerri <mhcerri@linux.vnet.ibm.com>
Thu, 29 Aug 2013 14:36:39 +0000 (11:36 -0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 2 Sep 2013 10:32:55 +0000 (20:32 +1000)
commitdec0ed6c1b2c8c2aa37c04feccaf4784764c95f1
tree8d49a66edd8468c22598ae8aa13af9c6aae799f1
parent41e3173daf4e2d2f2dcc48ae7ffc8d0c4f3ecec9
crypto: nx - fix GCM for zero length messages

The NX CGM implementation doesn't support zero length messages and the
current implementation has two flaws:

 - When the input data length is zero, it ignores the associated data.
 - Even when both lengths are zero, it uses the Crypto API to encrypt a
   zeroed block using ctr(aes) and because of this it allocates a new
   transformation and sets the key for this new tfm. Both operations are
   intended to be used only in user context, while the cryptographic
   operations can be called in both user and softirq contexts.

This patch replaces the nested Crypto API use and adds two special
cases:

 - When input data and associated data lengths are zero: it uses NX ECB
   mode to emulate the encryption of a zeroed block using ctr(aes).
 - When input data is zero and associated data is available: it uses NX
   GMAC mode to calculate the associated data MAC.

Reviewed-by: Joy Latten <jmlatten@linux.vnet.ibm.com>
Signed-off-by: Marcelo Cerri <mhcerri@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/nx/nx-aes-gcm.c