summaryrefslogtreecommitdiff
path: root/cipher/cipher-cbc.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-10-01 22:00:50 +0200
committerWerner Koch <wk@gnupg.org>2013-10-01 22:00:50 +0200
commit3ca180b25e8df252fc16f802cfdc27496e307830 (patch)
tree1399c7891aa6f4bf4bf994adaa078dadd3510091 /cipher/cipher-cbc.c
parent4153fa859816e799e506055321a22e6450aacdcc (diff)
downloadlibgcrypt-3ca180b25e8df252fc16f802cfdc27496e307830.tar.gz
cipher: Simplify the cipher dispatcher cipher.c.
* src/gcrypt-module.h (gcry_cipher_spec_t): Move to ... * src/cipher-proto.h (gcry_cipher_spec_t): here. Merge with cipher_extra_spec_t. Add fields ALGO and FLAGS. Set these fields in all cipher modules. * cipher/cipher.c: Change most code to replace the former module system by a simpler system to gain information about the algorithms. (disable_pubkey_algo): Simplified. Not anymore thread-safe, though. * cipher/md.c (_gcry_md_selftest): Use correct structure. Not a real problem because both define the same function as their first field. * cipher/pubkey.c (_gcry_pk_selftest): Take care of the disabled flag. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'cipher/cipher-cbc.c')
-rw-r--r--cipher/cipher-cbc.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/cipher/cipher-cbc.c b/cipher/cipher-cbc.c
index 55a1c74a..523f5a69 100644
--- a/cipher/cipher-cbc.c
+++ b/cipher/cipher-cbc.c
@@ -40,15 +40,15 @@ _gcry_cipher_cbc_encrypt (gcry_cipher_hd_t c,
unsigned int n;
unsigned char *ivp;
int i;
- size_t blocksize = c->cipher->blocksize;
+ size_t blocksize = c->spec->blocksize;
unsigned nblocks = inbuflen / blocksize;
unsigned int burn, nburn;
if (outbuflen < ((c->flags & GCRY_CIPHER_CBC_MAC)? blocksize : inbuflen))
return GPG_ERR_BUFFER_TOO_SHORT;
- if ((inbuflen % c->cipher->blocksize)
- && !(inbuflen > c->cipher->blocksize
+ if ((inbuflen % c->spec->blocksize)
+ && !(inbuflen > c->spec->blocksize
&& (c->flags & GCRY_CIPHER_CBC_CTS)))
return GPG_ERR_INV_LENGTH;
@@ -73,7 +73,7 @@ _gcry_cipher_cbc_encrypt (gcry_cipher_hd_t c,
for (n=0; n < nblocks; n++ )
{
buf_xor(outbuf, inbuf, c->u_iv.iv, blocksize);
- nburn = c->cipher->encrypt ( &c->context.c, outbuf, outbuf );
+ nburn = c->spec->encrypt ( &c->context.c, outbuf, outbuf );
burn = nburn > burn ? nburn : burn;
memcpy (c->u_iv.iv, outbuf, blocksize );
inbuf += blocksize;
@@ -104,7 +104,7 @@ _gcry_cipher_cbc_encrypt (gcry_cipher_hd_t c,
for (; i < blocksize; i++)
outbuf[i] = 0 ^ *ivp++;
- nburn = c->cipher->encrypt (&c->context.c, outbuf, outbuf);
+ nburn = c->spec->encrypt (&c->context.c, outbuf, outbuf);
burn = nburn > burn ? nburn : burn;
memcpy (c->u_iv.iv, outbuf, blocksize);
}
@@ -123,15 +123,15 @@ _gcry_cipher_cbc_decrypt (gcry_cipher_hd_t c,
{
unsigned int n;
int i;
- size_t blocksize = c->cipher->blocksize;
+ size_t blocksize = c->spec->blocksize;
unsigned int nblocks = inbuflen / blocksize;
unsigned int burn, nburn;
if (outbuflen < inbuflen)
return GPG_ERR_BUFFER_TOO_SHORT;
- if ((inbuflen % c->cipher->blocksize)
- && !(inbuflen > c->cipher->blocksize
+ if ((inbuflen % c->spec->blocksize)
+ && !(inbuflen > c->spec->blocksize
&& (c->flags & GCRY_CIPHER_CBC_CTS)))
return GPG_ERR_INV_LENGTH;
@@ -159,12 +159,12 @@ _gcry_cipher_cbc_decrypt (gcry_cipher_hd_t c,
* save the original ciphertext block. We use LASTIV for
* this here because it is not used otherwise. */
memcpy (c->lastiv, inbuf, blocksize);
- nburn = c->cipher->decrypt ( &c->context.c, outbuf, inbuf );
+ nburn = c->spec->decrypt ( &c->context.c, outbuf, inbuf );
burn = nburn > burn ? nburn : burn;
buf_xor(outbuf, outbuf, c->u_iv.iv, blocksize);
memcpy(c->u_iv.iv, c->lastiv, blocksize );
- inbuf += c->cipher->blocksize;
- outbuf += c->cipher->blocksize;
+ inbuf += c->spec->blocksize;
+ outbuf += c->spec->blocksize;
}
}
@@ -180,14 +180,14 @@ _gcry_cipher_cbc_decrypt (gcry_cipher_hd_t c,
memcpy (c->lastiv, c->u_iv.iv, blocksize ); /* Save Cn-2. */
memcpy (c->u_iv.iv, inbuf + blocksize, restbytes ); /* Save Cn. */
- nburn = c->cipher->decrypt ( &c->context.c, outbuf, inbuf );
+ nburn = c->spec->decrypt ( &c->context.c, outbuf, inbuf );
burn = nburn > burn ? nburn : burn;
buf_xor(outbuf, outbuf, c->u_iv.iv, restbytes);
memcpy(outbuf + blocksize, outbuf, restbytes);
for(i=restbytes; i < blocksize; i++)
c->u_iv.iv[i] = outbuf[i];
- nburn = c->cipher->decrypt (&c->context.c, outbuf, c->u_iv.iv);
+ nburn = c->spec->decrypt (&c->context.c, outbuf, c->u_iv.iv);
burn = nburn > burn ? nburn : burn;
buf_xor(outbuf, outbuf, c->lastiv, blocksize);
/* c->lastiv is now really lastlastiv, does this matter? */