mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
gpg: First take on PKT_ENCRYPTED_AEAD.
* common/openpgpdefs.h (PKT_ENCRYPTED_AEAD): New const. * g10/dek.h (DEK): Increase size of use_aead to 4 bits. * g10/filter.h (cipher_filter_context_t): Add new fields for AEAD. * g10/packet.h (PKT_encrypted): Add fields aead_algo, cipher_algo, and chunkbyte. * g10/build-packet.c (do_encrypted_aead): New. (build_packet): Call it. * g10/parse-packet.c (dump_sig_subpkt): Handle SIGSUBPKT_PREF_AEAD. (parse_one_sig_subpkt, can_handle_critical): Ditto. (parse_encrypted): Clear new PKT_ENCRYPTED fields. (parse_encrypted_aead): New. (parse): Call it. * g10/gpg.c (main): Take care of --rfc4880bis option when checking compliance. * g10/cipher-aead.c: Replace the stub by real code. * g10/decrypt-data.c (decode_filter_ctx_t): Add fields for use with AEAD. (aead_set_nonce): New. (aead_set_ad): New. (decrypt_data): Support AEAD. (aead_underflow): New. (aead_decode_filter): New. * g10/encrypt.c (use_aead): Make that new fucntion work. (encrypt_simple): Use default_aead_algo() instead of EAX. * g10/mainproc.c (proc_encrypted): Support AEAD. (do_proc_packets): Support PKT_ENCRYPTED_AEAD. -- This code has seen only a very few manual tests. Encrypting always uses a 64k chunks and decryption has not been tested with larger chunks. Those small chunks make debugging much faster. Tests can be done using: gpg --rfc4880bis --pinentry-mode=loopback --passphrase abc \ --force-aead --aead-algo ocb --s2k-mode 0 --cipher AES \ -v -z 0 --status-fd 2 -c <INFILE >OUTFILE and gpg --rfc4880bis --pinentry-mode=loopback --passphrase=abc \ --status-fd 2 -v -d <INFILE >OUTFILE Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
81d71818d0
commit
3f4ca85cb0
12 changed files with 1235 additions and 138 deletions
|
@ -1,7 +1,6 @@
|
|||
/* parse-packet.c - read packets
|
||||
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
* 2007, 2009, 2010 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2014 Werner Koch
|
||||
* Copyright (C) 1998-2007, 2009-2010 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2014, 2018 Werner Koch
|
||||
* Copyright (C) 2015 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
|
@ -18,6 +17,7 @@
|
|||
*
|
||||
* 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>
|
||||
|
@ -82,6 +82,9 @@ static int parse_compressed (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||
PACKET * packet, int new_ctb);
|
||||
static int parse_encrypted (IOBUF inp, int pkttype, unsigned long pktlen,
|
||||
PACKET * packet, int new_ctb, int partial);
|
||||
static gpg_error_t parse_encrypted_aead (IOBUF inp, int pkttype,
|
||||
unsigned long pktlen, PACKET *packet,
|
||||
int partial);
|
||||
static int parse_mdc (IOBUF inp, int pkttype, unsigned long pktlen,
|
||||
PACKET * packet, int new_ctb);
|
||||
static int parse_gpg_control (IOBUF inp, int pkttype, unsigned long pktlen,
|
||||
|
@ -636,6 +639,7 @@ parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts, off_t * retpos,
|
|||
case PKT_PLAINTEXT:
|
||||
case PKT_ENCRYPTED:
|
||||
case PKT_ENCRYPTED_MDC:
|
||||
case PKT_ENCRYPTED_AEAD:
|
||||
case PKT_COMPRESSED:
|
||||
iobuf_set_partial_body_length_mode (inp, c & 0xff);
|
||||
pktlen = 0; /* To indicate partial length. */
|
||||
|
@ -823,6 +827,9 @@ parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts, off_t * retpos,
|
|||
case PKT_MDC:
|
||||
rc = parse_mdc (inp, pkttype, pktlen, pkt, new_ctb);
|
||||
break;
|
||||
case PKT_ENCRYPTED_AEAD:
|
||||
rc = parse_encrypted_aead (inp, pkttype, pktlen, pkt, partial);
|
||||
break;
|
||||
case PKT_GPG_CONTROL:
|
||||
rc = parse_gpg_control (inp, pkttype, pktlen, pkt, partial);
|
||||
break;
|
||||
|
@ -1392,6 +1399,11 @@ dump_sig_subpkt (int hashed, int type, int critical,
|
|||
for (i = 0; i < length; i++)
|
||||
es_fprintf (listfp, " %d", buffer[i]);
|
||||
break;
|
||||
case SIGSUBPKT_PREF_AEAD:
|
||||
es_fputs ("pref-aead-algos:", listfp);
|
||||
for (i = 0; i < length; i++)
|
||||
es_fprintf (listfp, " %d", buffer[i]);
|
||||
break;
|
||||
case SIGSUBPKT_REV_KEY:
|
||||
es_fputs ("revocation key: ", listfp);
|
||||
if (length < 22)
|
||||
|
@ -1554,6 +1566,7 @@ parse_one_sig_subpkt (const byte * buffer, size_t n, int type)
|
|||
case SIGSUBPKT_KEY_FLAGS:
|
||||
case SIGSUBPKT_KS_FLAGS:
|
||||
case SIGSUBPKT_PREF_SYM:
|
||||
case SIGSUBPKT_PREF_AEAD:
|
||||
case SIGSUBPKT_PREF_HASH:
|
||||
case SIGSUBPKT_PREF_COMPR:
|
||||
case SIGSUBPKT_POLICY:
|
||||
|
@ -1636,6 +1649,7 @@ can_handle_critical (const byte * buffer, size_t n, int type)
|
|||
case SIGSUBPKT_ISSUER: /* issuer key ID */
|
||||
case SIGSUBPKT_ISSUER_FPR: /* issuer fingerprint */
|
||||
case SIGSUBPKT_PREF_SYM:
|
||||
case SIGSUBPKT_PREF_AEAD:
|
||||
case SIGSUBPKT_PREF_HASH:
|
||||
case SIGSUBPKT_PREF_COMPR:
|
||||
case SIGSUBPKT_KEY_FLAGS:
|
||||
|
@ -3161,6 +3175,9 @@ parse_encrypted (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||
ed->buf = NULL;
|
||||
ed->new_ctb = new_ctb;
|
||||
ed->is_partial = partial;
|
||||
ed->aead_algo = 0;
|
||||
ed->cipher_algo = 0; /* Only used with AEAD. */
|
||||
ed->chunkbyte = 0; /* Only used with AEAD. */
|
||||
if (pkttype == PKT_ENCRYPTED_MDC)
|
||||
{
|
||||
/* Fixme: add some pktlen sanity checks. */
|
||||
|
@ -3252,6 +3269,81 @@ parse_mdc (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||
}
|
||||
|
||||
|
||||
static gpg_error_t
|
||||
parse_encrypted_aead (iobuf_t inp, int pkttype, unsigned long pktlen,
|
||||
PACKET *pkt, int partial)
|
||||
{
|
||||
int rc = 0;
|
||||
PKT_encrypted *ed;
|
||||
unsigned long orig_pktlen = pktlen;
|
||||
int version;
|
||||
|
||||
ed = pkt->pkt.encrypted = xtrymalloc (sizeof *pkt->pkt.encrypted);
|
||||
if (!ed)
|
||||
return gpg_error_from_syserror ();
|
||||
ed->len = 0;
|
||||
ed->extralen = 0; /* (only used in build_packet.) */
|
||||
ed->buf = NULL;
|
||||
ed->new_ctb = 1; /* (packet number requires a new CTB anyway.) */
|
||||
ed->is_partial = partial;
|
||||
ed->mdc_method = 0;
|
||||
/* A basic sanity check. We need one version byte, one algo byte,
|
||||
* one aead algo byte, one chunkbyte, at least 15 byte IV. */
|
||||
if (orig_pktlen && pktlen < 19)
|
||||
{
|
||||
log_error ("packet(%d) too short\n", pkttype);
|
||||
if (list_mode)
|
||||
es_fputs (":aead encrypted packet: [too short]\n", listfp);
|
||||
rc = gpg_error (GPG_ERR_INV_PACKET);
|
||||
iobuf_skip_rest (inp, pktlen, partial);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
version = iobuf_get_noeof (inp);
|
||||
if (orig_pktlen)
|
||||
pktlen--;
|
||||
if (version != 1)
|
||||
{
|
||||
log_error ("aead encrypted packet with unknown version %d\n",
|
||||
version);
|
||||
if (list_mode)
|
||||
es_fputs (":aead encrypted packet: [unknown version]\n", listfp);
|
||||
/*skip_rest(inp, pktlen); should we really do this? */
|
||||
rc = gpg_error (GPG_ERR_INV_PACKET);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
ed->cipher_algo = iobuf_get_noeof (inp);
|
||||
if (orig_pktlen)
|
||||
pktlen--;
|
||||
ed->aead_algo = iobuf_get_noeof (inp);
|
||||
if (orig_pktlen)
|
||||
pktlen--;
|
||||
ed->chunkbyte = iobuf_get_noeof (inp);
|
||||
if (orig_pktlen)
|
||||
pktlen--;
|
||||
|
||||
/* Store the remaining length of the encrypted data. We read the
|
||||
* rest during decryption. */
|
||||
ed->len = pktlen;
|
||||
|
||||
if (list_mode)
|
||||
{
|
||||
es_fprintf (listfp, ":aead encrypted packet: cipher=%u aead=%u cb=%u\n",
|
||||
ed->cipher_algo, ed->aead_algo, ed->chunkbyte);
|
||||
if (orig_pktlen)
|
||||
es_fprintf (listfp, "\tlength: %lu\n", orig_pktlen);
|
||||
else
|
||||
es_fprintf (listfp, "\tlength: unknown\n");
|
||||
}
|
||||
|
||||
ed->buf = inp;
|
||||
|
||||
leave:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This packet is internally generated by us (in armor.c) to transfer
|
||||
* some information to the lower layer. To make sure that this packet
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue