summaryrefslogtreecommitdiff
path: root/cipher/twofish.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2015-10-24 12:41:23 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2015-10-28 20:08:45 +0200
commit16fd540f4d01eb6dc23d9509ae549353617c7a67 (patch)
tree042cee8e0c1c3d3dfbd5dedb44fa3ba0e0fb0848 /cipher/twofish.c
parentae40af427fd2a856b24ec2a41323ec8b80ffc9c0 (diff)
downloadlibgcrypt-16fd540f4d01eb6dc23d9509ae549353617c7a67.tar.gz
Fix OCB amd64 assembly implementations for x32
* cipher/camellia-glue.c (_gcry_camellia_aesni_avx_ocb_enc) (_gcry_camellia_aesni_avx_ocb_dec, _gcry_camellia_aesni_avx_ocb_auth) (_gcry_camellia_aesni_avx2_ocb_enc, _gcry_camellia_aesni_avx2_ocb_dec) (_gcry_camellia_aesni_avx2_ocb_auth, _gcry_camellia_ocb_crypt) (_gcry_camellia_ocb_auth): Change 'Ls' from pointer array to u64 array. * cipher/serpent.c (_gcry_serpent_sse2_ocb_enc) (_gcry_serpent_sse2_ocb_dec, _gcry_serpent_sse2_ocb_auth) (_gcry_serpent_avx2_ocb_enc, _gcry_serpent_avx2_ocb_dec) (_gcry_serpent_ocb_crypt, _gcry_serpent_ocb_auth): Ditto. * cipher/twofish.c (_gcry_twofish_amd64_ocb_enc) (_gcry_twofish_amd64_ocb_dec, _gcry_twofish_amd64_ocb_auth) (twofish_amd64_ocb_enc, twofish_amd64_ocb_dec, twofish_amd64_ocb_auth) (_gcry_twofish_ocb_crypt, _gcry_twofish_ocb_auth): Ditto. -- Pointers on x32 are 32-bit, but amd64 assembly implementations expect 64-bit pointers. Pass 'Ls' array to 64-bit integers so that input arrays has correct format for assembly functions. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/twofish.c')
-rw-r--r--cipher/twofish.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/cipher/twofish.c b/cipher/twofish.c
index 7f361c99..f6ecd672 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -734,15 +734,15 @@ extern void _gcry_twofish_amd64_cfb_dec(const TWOFISH_context *c, byte *out,
extern void _gcry_twofish_amd64_ocb_enc(const TWOFISH_context *ctx, byte *out,
const byte *in, byte *offset,
- byte *checksum, const void *Ls[3]);
+ byte *checksum, const u64 Ls[3]);
extern void _gcry_twofish_amd64_ocb_dec(const TWOFISH_context *ctx, byte *out,
const byte *in, byte *offset,
- byte *checksum, const void *Ls[3]);
+ byte *checksum, const u64 Ls[3]);
extern void _gcry_twofish_amd64_ocb_auth(const TWOFISH_context *ctx,
const byte *abuf, byte *offset,
- byte *checksum, const void *Ls[3]);
+ byte *checksum, const u64 Ls[3]);
#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
static inline void
@@ -854,7 +854,7 @@ twofish_amd64_cfb_dec(const TWOFISH_context *c, byte *out, const byte *in,
static inline void
twofish_amd64_ocb_enc(const TWOFISH_context *ctx, byte *out, const byte *in,
- byte *offset, byte *checksum, const void *Ls[3])
+ byte *offset, byte *checksum, const u64 Ls[3])
{
#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
call_sysv_fn6(_gcry_twofish_amd64_ocb_enc, ctx, out, in, offset, checksum, Ls);
@@ -865,7 +865,7 @@ twofish_amd64_ocb_enc(const TWOFISH_context *ctx, byte *out, const byte *in,
static inline void
twofish_amd64_ocb_dec(const TWOFISH_context *ctx, byte *out, const byte *in,
- byte *offset, byte *checksum, const void *Ls[3])
+ byte *offset, byte *checksum, const u64 Ls[3])
{
#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
call_sysv_fn6(_gcry_twofish_amd64_ocb_dec, ctx, out, in, offset, checksum, Ls);
@@ -876,7 +876,7 @@ twofish_amd64_ocb_dec(const TWOFISH_context *ctx, byte *out, const byte *in,
static inline void
twofish_amd64_ocb_auth(const TWOFISH_context *ctx, const byte *abuf,
- byte *offset, byte *checksum, const void *Ls[3])
+ byte *offset, byte *checksum, const u64 Ls[3])
{
#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
call_sysv_fn5(_gcry_twofish_amd64_ocb_auth, ctx, abuf, offset, checksum, Ls);
@@ -1261,15 +1261,17 @@ _gcry_twofish_ocb_crypt (gcry_cipher_hd_t c, void *outbuf_arg,
u64 blkn = c->u_mode.ocb.data_nblocks;
{
- const void *Ls[3];
+ /* Use u64 to store pointers for x32 support (assembly function
+ * assumes 64-bit pointers). */
+ u64 Ls[3];
/* Process data in 3 block chunks. */
while (nblocks >= 3)
{
/* l_tmp will be used only every 65536-th block. */
- Ls[0] = ocb_get_l(c, l_tmp, blkn + 1);
- Ls[1] = ocb_get_l(c, l_tmp, blkn + 2);
- Ls[2] = ocb_get_l(c, l_tmp, blkn + 3);
+ Ls[0] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 1);
+ Ls[1] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 2);
+ Ls[2] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 3);
blkn += 3;
if (encrypt)
@@ -1320,15 +1322,17 @@ _gcry_twofish_ocb_auth (gcry_cipher_hd_t c, const void *abuf_arg,
u64 blkn = c->u_mode.ocb.aad_nblocks;
{
- const void *Ls[3];
+ /* Use u64 to store pointers for x32 support (assembly function
+ * assumes 64-bit pointers). */
+ u64 Ls[3];
/* Process data in 3 block chunks. */
while (nblocks >= 3)
{
/* l_tmp will be used only every 65536-th block. */
- Ls[0] = ocb_get_l(c, l_tmp, blkn + 1);
- Ls[1] = ocb_get_l(c, l_tmp, blkn + 2);
- Ls[2] = ocb_get_l(c, l_tmp, blkn + 3);
+ Ls[0] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 1);
+ Ls[1] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 2);
+ Ls[2] = (uintptr_t)(const void *)ocb_get_l(c, l_tmp, blkn + 3);
blkn += 3;
twofish_amd64_ocb_auth(ctx, abuf, c->u_mode.ocb.aad_offset,