#include "g10lib.h"
#include "cipher.h"
-#include "ath.h"
#include "bufhelp.h"
#include "./cipher-internal.h"
blocksize 128. */
gcry_err_code_t
_gcry_cipher_aeswrap_encrypt (gcry_cipher_hd_t c,
- byte *outbuf, unsigned int outbuflen,
- const byte *inbuf, unsigned int inbuflen )
+ byte *outbuf, size_t outbuflen,
+ const byte *inbuf, size_t inbuflen )
{
int j, x;
- unsigned int n, i;
+ size_t n, i;
unsigned char *r, *a, *b;
unsigned char t[8];
+ unsigned int burn, nburn;
#if MAX_BLOCKSIZE < 8
#error Invalid block size
#endif
/* We require a cipher with a 128 bit block length. */
- if (c->cipher->blocksize != 16)
+ if (c->spec->blocksize != 16)
return GPG_ERR_INV_LENGTH;
/* The output buffer must be able to hold the input data plus one
if (n < 2)
return GPG_ERR_INV_ARG;
+ burn = 0;
+
r = outbuf;
a = outbuf; /* We store A directly in OUTBUF. */
b = c->u_ctr.ctr; /* B is also used to concatenate stuff. */
/* B := AES_k( A | R[i] ) */
memcpy (b, a, 8);
memcpy (b+8, r+i*8, 8);
- c->cipher->encrypt (&c->context.c, b, b);
+ nburn = c->spec->encrypt (&c->context.c, b, b);
+ burn = nburn > burn ? nburn : burn;
/* t := t + 1 */
for (x = 7; x >= 0; x--)
{
}
}
+ if (burn > 0)
+ _gcry_burn_stack (burn + 4 * sizeof(void *));
+
return 0;
}
blocksize 128. */
gcry_err_code_t
_gcry_cipher_aeswrap_decrypt (gcry_cipher_hd_t c,
- byte *outbuf, unsigned int outbuflen,
- const byte *inbuf, unsigned int inbuflen)
+ byte *outbuf, size_t outbuflen,
+ const byte *inbuf, size_t inbuflen)
{
int j, x;
- unsigned int n, i;
+ size_t n, i;
unsigned char *r, *a, *b;
unsigned char t[8];
+ unsigned int burn, nburn;
#if MAX_BLOCKSIZE < 8
#error Invalid block size
#endif
/* We require a cipher with a 128 bit block length. */
- if (c->cipher->blocksize != 16)
+ if (c->spec->blocksize != 16)
return GPG_ERR_INV_LENGTH;
/* The output buffer must be able to hold the input data minus one
if (n < 3)
return GPG_ERR_INV_ARG;
+ burn = 0;
+
r = outbuf;
a = c->lastiv; /* We use c->LASTIV as buffer for A. */
b = c->u_ctr.ctr; /* B is also used to concatenate stuff. */
/* B := AES_k^1( (A ^ t)| R[i] ) */
buf_xor(b, a, t, 8);
memcpy (b+8, r+(i-1)*8, 8);
- c->cipher->decrypt (&c->context.c, b, b);
+ nburn = c->spec->decrypt (&c->context.c, b, b);
+ burn = nburn > burn ? nburn : burn;
/* t := t - 1 */
for (x = 7; x >= 0; x--)
{
break;
}
}
+
+ if (burn > 0)
+ _gcry_burn_stack (burn + 4 * sizeof(void *));
+
return j? GPG_ERR_CHECKSUM : 0;
}