diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-11-20 15:44:27 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-11-21 11:58:09 +0200 |
commit | dbfa651618693da7ea73b4d2d00d4efd411bfb46 (patch) | |
tree | 64bfe4135eb663dacc8459af97fef7ad1e4b5142 /cipher/cipher-internal.h | |
parent | fb1e52e3fe231671de546eacd6becd31c26c4f7b (diff) | |
download | libgcrypt-dbfa651618693da7ea73b4d2d00d4efd411bfb46.tar.gz |
GCM: Move gcm_table initialization to setkey
* cipher/cipher-gcm.c: Change all 'c->u_iv.iv' to
'c->u_mode.gcm.u_ghash_key.key'.
(_gcry_cipher_gcm_setkey): New.
(_gcry_cipher_gcm_initiv): Move ghash initialization to function above.
* cipher/cipher-internal.h (gcry_cipher_handle): Add
'u_mode.gcm.u_ghash_key'; Reorder 'u_mode.gcm' members for partial
clearing in gcry_cipher_reset.
(_gcry_cipher_gcm_setkey): New prototype.
* cipher/cipher.c (cipher_setkey): Add GCM setkey.
(cipher_reset): Clear 'u_mode' only partially for GCM.
--
GHASH tables can be generated at setkey time. No need to regenerate
for every new IV.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/cipher-internal.h')
-rw-r--r-- | cipher/cipher-internal.h | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/cipher/cipher-internal.h b/cipher/cipher-internal.h index ede6f757..6fb3bace 100644 --- a/cipher/cipher-internal.h +++ b/cipher/cipher-internal.h @@ -179,6 +179,25 @@ struct gcry_cipher_handle /* encrypted tag counter */ unsigned char tagiv[MAX_BLOCKSIZE]; + unsigned int ghash_data_finalized:1; + unsigned int ghash_aad_finalized:1; + + unsigned int datalen_over_limits:1; + unsigned int disallow_encryption_because_of_setiv_in_fips_mode:1; + + /* --- Following members are not cleared in gcry_cipher_reset --- */ + + /* GHASH multiplier from key. */ + union { + cipher_context_alignment_t iv_align; + unsigned char key[MAX_BLOCKSIZE]; + } u_ghash_key; + +#ifdef GCM_USE_INTEL_PCLMUL + /* Use Intel PCLMUL instructions for accelerated GHASH. */ + unsigned int use_intel_pclmul:1; +#endif + /* Pre-calculated table for GCM. */ #ifdef GCM_USE_TABLES #if defined(HAVE_U64_TYPEDEF) && (SIZEOF_UNSIGNED_LONG == 8 \ @@ -190,15 +209,6 @@ struct gcry_cipher_handle u32 gcm_table[4 * 16]; #endif #endif - - unsigned int ghash_data_finalized:1; - unsigned int ghash_aad_finalized:1; - - unsigned int datalen_over_limits:1; - unsigned int disallow_encryption_because_of_setiv_in_fips_mode:1; -#ifdef GCM_USE_INTEL_PCLMUL - unsigned int use_intel_pclmul:1; -#endif } gcm; } u_mode; @@ -302,6 +312,8 @@ gcry_err_code_t _gcry_cipher_gcm_get_tag gcry_err_code_t _gcry_cipher_gcm_check_tag /* */ (gcry_cipher_hd_t c, const unsigned char *intag, size_t taglen); +void _gcry_cipher_gcm_setkey +/* */ (gcry_cipher_hd_t c); #endif /*G10_CIPHER_INTERNAL_H*/ |