diff options
author | Werner Koch <wk@gnupg.org> | 2018-01-10 17:33:50 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2018-01-10 17:33:50 +0100 |
commit | 81d71818d054a5faa9153fd52a4b79bbbb71e9d5 (patch) | |
tree | cd62338a213ae45861d4db23be7bee638aed85ed | |
parent | gpg: New option --force-aead (diff) | |
download | gnupg2-81d71818d054a5faa9153fd52a4b79bbbb71e9d5.tar.xz gnupg2-81d71818d054a5faa9153fd52a4b79bbbb71e9d5.zip |
gpg: Add stub function for encrypting AEAD.
* g10/cipher.c (cipher_filter): Rename to cipher_filter_cfb.
* g10/cipher-aead.c: New. Right now only with a stub function.
* g10/Makefile.am (gpg_sources): Add file.
* g10/encrypt.c (encrypt_simple): Push either cipher_filter_cfb or
cipher_filter_aead.
(encrypt_crypt): Ditto.
(encrypt_filter): Ditto.
* g10/sign.c (sign_symencrypt_file): Ditto.
Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r-- | g10/Makefile.am | 1 | ||||
-rw-r--r-- | g10/cipher-aead.c | 67 | ||||
-rw-r--r-- | g10/cipher.c | 7 | ||||
-rw-r--r-- | g10/encrypt.c | 15 | ||||
-rw-r--r-- | g10/filter.h | 8 | ||||
-rw-r--r-- | g10/gpgcompose.c | 2 | ||||
-rw-r--r-- | g10/sign.c | 5 |
7 files changed, 95 insertions, 10 deletions
diff --git a/g10/Makefile.am b/g10/Makefile.am index cc4ef5cb6..cba65b22a 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -132,6 +132,7 @@ gpg_sources = server.c \ decrypt.c \ decrypt-data.c \ cipher.c \ + cipher-aead.c \ encrypt.c \ sign.c \ verify.c \ diff --git a/g10/cipher-aead.c b/g10/cipher-aead.c new file mode 100644 index 000000000..bf0afcfcb --- /dev/null +++ b/g10/cipher-aead.c @@ -0,0 +1,67 @@ +/* cipher-aead.c - Enciphering filter for AEAD modes + * Copyright (C) 2018 Werner koch + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses/>. + * SPDX-License-Identifier: GPL-3.0+ + */ + +#include <config.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "gpg.h" +#include "../common/status.h" +#include "../common/iobuf.h" +#include "../common/util.h" +#include "filter.h" +#include "packet.h" +#include "options.h" +#include "main.h" + + +/* + * This filter is used to encipher data with an AEAD algorithm + */ +int +cipher_filter_aead (void *opaque, int control, + iobuf_t a, byte *buf, size_t *ret_len) +{ + cipher_filter_context_t *cfx = opaque; + size_t size = *ret_len; + int rc = 0; + + if (control == IOBUFCTRL_UNDERFLOW) /* decrypt */ + { + rc = -1; /* not yet used */ + } + else if (control == IOBUFCTRL_FLUSH) /* encrypt */ + { + log_assert (a); + rc = GPG_ERR_NOT_IMPLEMENTED; + } + else if (control == IOBUFCTRL_FREE) + { + gcry_cipher_close (cfx->cipher_hd); + } + else if (control == IOBUFCTRL_DESC) + { + mem2str (buf, "cipher_filter_aead", *ret_len); + } + + return rc; +} diff --git a/g10/cipher.c b/g10/cipher.c index b950d0c3f..ad7399dec 100644 --- a/g10/cipher.c +++ b/g10/cipher.c @@ -1,4 +1,4 @@ -/* cipher.c - En-/De-ciphering filter +/* cipher.c - Enciphering filter for the old CFB mode. * Copyright (C) 1998-2003, 2006, 2009 Free Software Foundation, Inc. * Copyright (C) 1998-2003, 2006, 2009, 2017 Werner koch * @@ -117,7 +117,8 @@ write_header (cipher_filter_context_t *cfx, iobuf_t a) * This filter is used to en/de-cipher data with a symmetric algorithm */ int -cipher_filter (void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len) +cipher_filter_cfb (void *opaque, int control, + iobuf_t a, byte *buf, size_t *ret_len) { cipher_filter_context_t *cfx = opaque; size_t size = *ret_len; @@ -177,7 +178,7 @@ cipher_filter (void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len) } else if (control == IOBUFCTRL_DESC) { - mem2str (buf, "cipher_filter", *ret_len); + mem2str (buf, "cipher_filter_cfb", *ret_len); } return rc; diff --git a/g10/encrypt.c b/g10/encrypt.c index 2951a45ff..01feb4a7d 100644 --- a/g10/encrypt.c +++ b/g10/encrypt.c @@ -409,7 +409,10 @@ encrypt_simple (const char *filename, int mode, int use_seskey) /* Register the cipher filter. */ if (mode) - iobuf_push_filter ( out, cipher_filter, &cfx ); + iobuf_push_filter (out, + cfx.dek->use_aead? cipher_filter_aead + /**/ : cipher_filter_cfb, + &cfx ); /* Register the compress filter. */ if ( do_compress ) @@ -800,7 +803,10 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename, cfx.datalen = filesize && !do_compress ? filesize : 0; /* Register the cipher filter. */ - iobuf_push_filter (out, cipher_filter, &cfx); + iobuf_push_filter (out, + cfx.dek->use_aead? cipher_filter_aead + /**/ : cipher_filter_cfb, + &cfx); /* Register the compress filter. */ if (do_compress) @@ -959,7 +965,10 @@ encrypt_filter (void *opaque, int control, return rc; } - iobuf_push_filter (a, cipher_filter, &efx->cfx); + iobuf_push_filter (a, + efx->cfx.dek->use_aead? cipher_filter_aead + /**/ : cipher_filter_cfb, + &efx->cfx); efx->header_okay = 1; } diff --git a/g10/filter.h b/g10/filter.h index 9e4b1e538..29243556e 100644 --- a/g10/filter.h +++ b/g10/filter.h @@ -145,8 +145,12 @@ void push_compress_filter2(iobuf_t out,compress_filter_context_t *zfx, int algo,int rel); /*-- cipher.c --*/ -int cipher_filter( void *opaque, int control, - iobuf_t chain, byte *buf, size_t *ret_len); +int cipher_filter_cfb (void *opaque, int control, + iobuf_t chain, byte *buf, size_t *ret_len); + +/*-- cipher-aead.c --*/ +int cipher_filter_aead (void *opaque, int control, + iobuf_t chain, byte *buf, size_t *ret_len); /*-- textfilter.c --*/ int text_filter( void *opaque, int control, diff --git a/g10/gpgcompose.c b/g10/gpgcompose.c index 8c156d279..f87983802 100644 --- a/g10/gpgcompose.c +++ b/g10/gpgcompose.c @@ -2573,7 +2573,7 @@ encrypted (const char *option, int argc, char *argv[], void *cookie) cfx->datalen = 0; - filter_push (out, cipher_filter, cfx, PKT_ENCRYPTED, cfx->datalen == 0); + filter_push (out, cipher_filter_cfb, cfx, PKT_ENCRYPTED, cfx->datalen == 0); debug ("Wrote encrypted packet:\n"); diff --git a/g10/sign.c b/g10/sign.c index f8a1241a6..051ab594d 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -1379,7 +1379,10 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr) } /* Push the encryption filter */ - iobuf_push_filter( out, cipher_filter, &cfx ); + iobuf_push_filter (out, + cfx.dek->use_aead? cipher_filter_aead + /**/ : cipher_filter_cfb, + &cfx); /* Push the compress filter */ if (default_compress_algo()) |