diff options
author | Werner Koch <wk@gnupg.org> | 2016-03-23 15:24:40 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2016-03-23 15:24:40 +0100 |
commit | fea5971488e049f902d7912df22a945bc755ad6d (patch) | |
tree | 7a701f928b4684f9b66771acff1889b793ee93c7 /cipher | |
parent | e709d86fe596a4bcf235799468947c13ae657d78 (diff) | |
download | libgcrypt-fea5971488e049f902d7912df22a945bc755ad6d.tar.gz |
Add new control GCRYCTL_GET_TAGLEN for use with gcry_cipher_info.
* src/gcrypt.h.in (GCRYCTL_GET_TAGLEN): New.
* cipher/cipher.c (_gcry_cipher_info): Add GCRYCTL_GET_TAGLEN feature.
* tests/basic.c (_check_gcm_cipher): Check that new feature.
(_check_poly1305_cipher): Ditto.
(check_ccm_cipher): Ditto.
(do_check_ocb_cipher): Ditto.
(check_ctr_cipher): Add negative test for new feature.
--
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/cipher.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/cipher/cipher.c b/cipher/cipher.c index 3a8597f5..bdcbfbd7 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -1361,24 +1361,55 @@ _gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen) /* Return information about the cipher handle H. CMD is the kind of - information requested. BUFFER and NBYTES are reserved for now. - - There are no values for CMD yet defined. - - The function always returns GPG_ERR_INV_OP. - + * information requested. + * + * CMD may be one of: + * + * GCRYCTL_GET_TAGLEN: + * Return the length of the tag for an AE algorithm mode. An + * error is returned for modes which do not support a tag. + * BUFFER must be given as NULL. On success the result is stored + * at NBYTES. The taglen is returned in bytes. + * + * The function returns 0 on success or an error code. */ gcry_err_code_t _gcry_cipher_info (gcry_cipher_hd_t h, int cmd, void *buffer, size_t *nbytes) { gcry_err_code_t rc = 0; - (void)h; - (void)buffer; - (void)nbytes; - switch (cmd) { + case GCRYCTL_GET_TAGLEN: + if (!h || buffer || !nbytes) + rc = GPG_ERR_INV_ARG; + else + { + switch (h->mode) + { + case GCRY_CIPHER_MODE_OCB: + *nbytes = h->u_mode.ocb.taglen; + break; + + case GCRY_CIPHER_MODE_CCM: + *nbytes = h->u_mode.ccm.authlen; + break; + + case GCRY_CIPHER_MODE_GCM: + *nbytes = GCRY_GCM_BLOCK_LEN; + break; + + case GCRY_CIPHER_MODE_POLY1305: + *nbytes = POLY1305_TAGLEN; + break; + + default: + rc = GPG_ERR_INV_CIPHER_MODE; + break; + } + } + break; + default: rc = GPG_ERR_INV_OP; } |