diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2019-01-27 11:19:56 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2019-01-27 11:19:56 +0200 |
commit | c15409c49993166ab1325d45360b3a8fe72a5556 (patch) | |
tree | 4a912786ed9f3163ad33edd1d14b2a0c3c3d95e3 /cipher/cipher.c | |
parent | 08e0650c21984bb9ddf5a1dabb1cc890fabf63ab (diff) | |
download | libgcrypt-c15409c49993166ab1325d45360b3a8fe72a5556.tar.gz |
Calculate OCB L-tables when setting key instead of when setting nonce
* cipher/cipher-internal.h (gcry_cipher_handle): Mark areas of
u_mode.ocb that are and are not cleared by gcry_cipher_reset.
(_gcry_cipher_ocb_setkey): New.
* cipher/cipher-ocb.c (_gcry_cipher_ocb_set_nonce): Split
L-table generation to ...
(_gcry_cipher_ocb_setkey): ... this new function.
* cipher/cipher.c (cipher_setkey): Add handling for OCB mode.
(cipher_reset): Do not clear L-values for OCB mode.
--
OCB L-tables do not depend on nonce value, but only on cipher key.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/cipher.c')
-rw-r--r-- | cipher/cipher.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/cipher/cipher.c b/cipher/cipher.c index 55b991c3..ab3e4240 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -816,6 +816,10 @@ cipher_setkey (gcry_cipher_hd_t c, byte *key, size_t keylen) _gcry_cipher_gcm_setkey (c); break; + case GCRY_CIPHER_MODE_OCB: + _gcry_cipher_ocb_setkey (c); + break; + case GCRY_CIPHER_MODE_POLY1305: _gcry_cipher_poly1305_setkey (c); break; @@ -931,9 +935,18 @@ cipher_reset (gcry_cipher_hd_t c) break; case GCRY_CIPHER_MODE_OCB: - memset (&c->u_mode.ocb, 0, sizeof c->u_mode.ocb); - /* Setup default taglen. */ - c->u_mode.ocb.taglen = 16; + /* Do not clear precalculated L-values */ + { + byte *u_mode_head_pos = (void *)&c->u_mode.ocb; + byte *u_mode_tail_pos = (void *)&c->u_mode.ocb.tag; + size_t u_mode_head_length = u_mode_tail_pos - u_mode_head_pos; + size_t u_mode_tail_length = sizeof(c->u_mode.ocb) - u_mode_head_length; + + memset (u_mode_tail_pos, 0, u_mode_tail_length); + + /* Setup default taglen. */ + c->u_mode.ocb.taglen = 16; + } break; case GCRY_CIPHER_MODE_XTS: |