summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2016-03-23 11:07:52 +0100
committerWerner Koch <wk@gnupg.org>2016-03-23 12:29:22 +0100
commit15785bc9fb1787554bf371945ecb191830c15bfd (patch)
treed70698a8b60ed761dec930a8dc8863eab7af61e2
parentd3d7bdf8215275b3b20690dfde3f43dbe25b6f85 (diff)
downloadlibgcrypt-15785bc9fb1787554bf371945ecb191830c15bfd.tar.gz
cipher: Check length of supplied tag in _gcry_cipher_gcm_check_tag.
* cipher/cipher-gcm.c (_gcry_cipher_gcm_tag): Check that the provided tag length matches the actual tag length. Avoid gratuitous return statements. -- Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r--cipher/cipher-gcm.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/cipher/cipher-gcm.c b/cipher/cipher-gcm.c
index cb81ea93..5e9dec48 100644
--- a/cipher/cipher-gcm.c
+++ b/cipher/cipher-gcm.c
@@ -803,13 +803,18 @@ _gcry_cipher_gcm_tag (gcry_cipher_hd_t c,
if (!check)
{
+ /* NB: We already checked that OUTBUF is large enough to hold
+ the result. */
memcpy (outbuf, c->u_mode.gcm.u_tag.tag, GCRY_GCM_BLOCK_LEN);
- return GPG_ERR_NO_ERROR;
}
else
{
- return buf_eq_const(outbuf, c->u_mode.gcm.u_tag.tag, GCRY_GCM_BLOCK_LEN) ?
- GPG_ERR_NO_ERROR : GPG_ERR_CHECKSUM;
+ /* OUTBUFLEN gives the length of the user supplied tag in OUTBUF
+ * and thus we need to compare its length first. */
+ if (outbuflen != GCRY_GCM_BLOCK_LEN
+ || !buf_eq_const (outbuf, c->u_mode.gcm.u_tag.tag,
+ GCRY_GCM_BLOCK_LEN))
+ return GPG_ERR_CHECKSUM;
}
return 0;