1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-12 22:11:29 +02:00

indent: Re-indent g10/cipher.c

--
This commit is contained in:
Werner Koch 2017-12-13 11:56:28 +01:00
parent 9f641430dc
commit 067e62fe55
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -1,6 +1,6 @@
/* cipher.c - En-/De-ciphering filter /* cipher.c - En-/De-ciphering filter
* Copyright (C) 1998, 1999, 2000, 2001, 2003, * Copyright (C) 1998-2003, 2006, 2009 Free Software Foundation, Inc.
* 2006, 2009 Free Software Foundation, Inc. * Copyright (C) 1998-2003, 2006, 2009, 2017 Werner koch
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -16,6 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>. * along with this program; if not, see <https://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-3.0+
*/ */
#include <config.h> #include <config.h>
@ -39,7 +40,7 @@
static void static void
write_header( cipher_filter_context_t *cfx, IOBUF a ) write_header (cipher_filter_context_t *cfx, iobuf_t a)
{ {
gcry_error_t err; gcry_error_t err;
PACKET pkt; PACKET pkt;
@ -56,7 +57,8 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
ed.len = cfx->datalen; ed.len = cfx->datalen;
ed.extralen = blocksize + 2; ed.extralen = blocksize + 2;
ed.new_ctb = !ed.len; ed.new_ctb = !ed.len;
if( cfx->dek->use_mdc ) { if (cfx->dek->use_mdc)
{
ed.mdc_method = DIGEST_ALGO_SHA1; ed.mdc_method = DIGEST_ALGO_SHA1;
gcry_md_open (&cfx->mdc_hash, DIGEST_ALGO_SHA1, 0); gcry_md_open (&cfx->mdc_hash, DIGEST_ALGO_SHA1, 0);
if (DBG_HASHING) if (DBG_HASHING)
@ -66,7 +68,7 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
{ {
char buf[20]; char buf[20];
sprintf (buf, "%d %d", ed.mdc_method, cfx->dek->algo); snprintf (buf, sizeof buf, "%d %d", ed.mdc_method, cfx->dek->algo);
write_status_text (STATUS_BEGIN_ENCRYPTION, buf); write_status_text (STATUS_BEGIN_ENCRYPTION, buf);
} }
@ -86,7 +88,8 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
(GCRY_CIPHER_SECURE (GCRY_CIPHER_SECURE
| ((cfx->dek->use_mdc || cfx->dek->algo >= 100)? | ((cfx->dek->use_mdc || cfx->dek->algo >= 100)?
0 : GCRY_CIPHER_ENABLE_SYNC))); 0 : GCRY_CIPHER_ENABLE_SYNC)));
if (err) { if (err)
{
/* We should never get an error here cause we already checked, /* We should never get an error here cause we already checked,
* that the algorithm is available. */ * that the algorithm is available. */
BUG(); BUG();
@ -106,36 +109,36 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
} }
/*
/**************** * This filter is used to en/de-cipher data with a symmetric algorithm
* This filter is used to en/de-cipher data with a conventional algorithm
*/ */
int int
cipher_filter( void *opaque, int control, cipher_filter (void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len)
IOBUF a, byte *buf, size_t *ret_len)
{ {
size_t size = *ret_len;
cipher_filter_context_t *cfx = opaque; cipher_filter_context_t *cfx = opaque;
size_t size = *ret_len;
int rc = 0; int rc = 0;
if( control == IOBUFCTRL_UNDERFLOW ) { /* decrypt */ if (control == IOBUFCTRL_UNDERFLOW) /* decrypt */
{
rc = -1; /* not yet used */ rc = -1; /* not yet used */
} }
else if( control == IOBUFCTRL_FLUSH ) { /* encrypt */ else if (control == IOBUFCTRL_FLUSH) /* encrypt */
{
log_assert (a); log_assert (a);
if( !cfx->header ) { if (!cfx->header)
write_header (cfx, a); write_header (cfx, a);
}
if (cfx->mdc_hash) if (cfx->mdc_hash)
gcry_md_write (cfx->mdc_hash, buf, size); gcry_md_write (cfx->mdc_hash, buf, size);
gcry_cipher_encrypt (cfx->cipher_hd, buf, size, NULL, 0); gcry_cipher_encrypt (cfx->cipher_hd, buf, size, NULL, 0);
rc = iobuf_write (a, buf, size); rc = iobuf_write (a, buf, size);
} }
else if( control == IOBUFCTRL_FREE ) { else if (control == IOBUFCTRL_FREE)
if( cfx->mdc_hash ) { {
if (cfx->mdc_hash)
{
byte *hash; byte *hash;
int hashlen = gcry_md_get_algo_dlen (gcry_md_get_algo int hashlen = gcry_md_get_algo_dlen (gcry_md_get_algo(cfx->mdc_hash));
(cfx->mdc_hash));
byte temp[22]; byte temp[22];
log_assert (hashlen == 20); log_assert (hashlen == 20);
@ -153,10 +156,13 @@ cipher_filter( void *opaque, int control,
if (iobuf_write( a, temp, 22)) if (iobuf_write( a, temp, 22))
log_error ("writing MDC packet failed\n"); log_error ("writing MDC packet failed\n");
} }
gcry_cipher_close (cfx->cipher_hd); gcry_cipher_close (cfx->cipher_hd);
} }
else if( control == IOBUFCTRL_DESC ) { else if (control == IOBUFCTRL_DESC)
{
mem2str (buf, "cipher_filter", *ret_len); mem2str (buf, "cipher_filter", *ret_len);
} }
return rc; return rc;
} }