* Version 2.99.1 (unreleased)
** libgnutls: Added support for AES-NI if detected. Uses
-Intel AES-NI code.
+Andy Polyakov's AES-NI code.
** libgnutls-extra: Dropped support of LZO compression via liblzo.
dnl Checks for programs.
AC_PROG_CC
+AM_PROG_AS
AC_PROG_CXX
gl_EARLY
case $host_cpu in
i?86 | x86_64 | amd64)
GCC_FLAG_ADD([-maes -mpclmul],[X86])
- AC_CHECK_PROGS(YASM, yasm)
-
- if test "x$YASM" != "x";then
- if test "x$X86" = "xyes";then
- if test "$host_cpu" = "x86_64" -o "$host_cpu" = "amd64";then
- hw_accel="x86-64"
- else
- hw_accel="x86"
- fi
+
+ if test "x$X86" = "xyes";then
+ if test "$host_cpu" = "x86_64" -o "$host_cpu" = "amd64";then
+ hw_accel="x86-64"
+ else
+ hw_accel="x86"
fi
- else
- AC_MSG_WARN([[yasm assembler not found. Disabling AES-NI compilation.]])
fi
;;
*)
AM_CPPFLAGS += -I$(srcdir)/../../minitasn1
endif
-EXTRA_DIST = aes-x86.h README license.txt iaes_asm_interface.h iaesni.h \
- asm/x64_iaesx64.s asm/x86_iaesx86.s
+EXTRA_DIST = aes-x86.h README license.txt
noinst_LTLIBRARIES = libintel.la
libintel_la_SOURCES = aes-x86.c
libintel_la_LIBADD =
-YASM_OPTS = -D__linux__
-
-x64_iaesx64.o: asm/x64_iaesx64.s
- $(YASM) $(YASM_OPTS) -f elf64 $^ -o $@
-
-x86_iaesx86.o: asm/x86_iaesx86.s
- $(YASM) $(YASM_OPTS) -f elf32 $^ -o $@
-
if ASM_X86_64
-libintel_la_LIBADD += x64_iaesx64.o
+libintel_la_SOURCES += asm/appro-aes-x86-64.s
else
-libintel_la_LIBADD += x86_iaesx86.o
+libintel_la_SOURCES += asm/appro-aes-x86.s
endif
-The Intel AES library is not part of the GnuTLS library, but is used with
-GnuTLS. The license of Intel AES library is included in license.txt.
+The AES-NI implementation by Andy Polyakov is not part of the GnuTLS library, but is
+used with GnuTLS. Its license is included in license.txt.
#include <gnutls_errors.h>
#include <aes-x86.h>
#include <x86.h>
-#include "iaes_asm_interface.h"
#ifdef __GNUC__
-# define ALIGN16 __attribute__ ((aligned (16)))
+# define ALIGN16 __attribute__ ((aligned (16)))
#else
# define ALIGN16
#endif
-typedef void (*enc_func)(sAesData*);
-
-struct aes_ctx {
- uint8_t ALIGN16 expanded_key[16*16];
- uint8_t ALIGN16 expanded_key_dec[16*16];
- uint8_t iv[16];
- enc_func enc;
- enc_func dec;
- size_t keysize;
+#define AES_MAXNR 14
+typedef struct
+{
+ uint32_t ALIGN16 rd_key[4 * (AES_MAXNR + 1)];
+ int rounds;
+} AES_KEY;
+
+void aesni_cbc_encrypt (const unsigned char *in, unsigned char *out,
+ size_t len, const AES_KEY * key,
+ unsigned char *ivec, const int enc);
+int aesni_set_decrypt_key (const unsigned char *userKey, const int bits,
+ AES_KEY * key);
+int aesni_set_encrypt_key (const unsigned char *userKey, const int bits,
+ AES_KEY * key);
+
+struct aes_ctx
+{
+ AES_KEY expanded_key;
+ AES_KEY expanded_key_dec;
+ uint8_t iv[16];
};
static int
aes_cipher_init (gnutls_cipher_algorithm_t algorithm, void **_ctx)
{
struct aes_ctx *ctx;
-
+
/* we use key size to distinguish */
- if (algorithm != GNUTLS_CIPHER_AES_128_CBC && algorithm != GNUTLS_CIPHER_AES_192_CBC
- && algorithm != GNUTLS_CIPHER_AES_256_CBC)
+ if (algorithm != GNUTLS_CIPHER_AES_128_CBC
+ && algorithm != GNUTLS_CIPHER_AES_192_CBC
+ && algorithm != GNUTLS_CIPHER_AES_256_CBC)
return GNUTLS_E_INVALID_REQUEST;
*_ctx = gnutls_calloc (1, sizeof (struct aes_ctx));
static int
aes_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
{
-struct aes_ctx *ctx = _ctx;
+ struct aes_ctx *ctx = _ctx;
+ int ret;
- if (keysize == 128/8)
- {
- iEncExpandKey128((void*)userkey, ctx->expanded_key);
- iDecExpandKey128((void*)userkey, ctx->expanded_key_dec);
- ctx->enc = iEnc128_CBC;
- ctx->dec = iDec128_CBC;
- }
- else if (keysize == 192/8)
- {
- iEncExpandKey192((void*)userkey, ctx->expanded_key);
- iDecExpandKey192((void*)userkey, ctx->expanded_key_dec);
- ctx->enc = iEnc192_CBC;
- ctx->dec = iDec192_CBC;
- }
- else if (keysize == 256/8)
- {
- iEncExpandKey256((void*)userkey, ctx->expanded_key);
- iDecExpandKey256((void*)userkey, ctx->expanded_key_dec);
- ctx->enc = iEnc256_CBC;
- ctx->dec = iDec256_CBC;
- }
- else
- return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+ ret = aesni_set_encrypt_key (userkey, keysize * 8, &ctx->expanded_key);
+ if (ret != 0)
+ return gnutls_assert_val (GNUTLS_E_ENCRYPTION_FAILED);
- ctx->keysize = keysize;
+ ret = aesni_set_decrypt_key (userkey, keysize * 8, &ctx->expanded_key_dec);
+ if (ret != 0)
+ return gnutls_assert_val (GNUTLS_E_ENCRYPTION_FAILED);
return 0;
}
static int
aes_encrypt (void *_ctx, const void *plain, size_t plainsize,
- void *encr, size_t length)
+ void *encr, size_t length)
{
-struct aes_ctx *ctx = _ctx;
-sAesData aesData;
-
- aesData.iv = ctx->iv;
- aesData.in_block = (void*)plain;
- aesData.out_block = encr;
- aesData.expanded_key = ctx->expanded_key;
- aesData.num_blocks = (plainsize + 1) / 16;
-
- ctx->enc(&aesData);
+ struct aes_ctx *ctx = _ctx;
+ aesni_cbc_encrypt (plain, encr, plainsize, &ctx->expanded_key, ctx->iv, 1);
return 0;
}
static int
aes_decrypt (void *_ctx, const void *encr, size_t encrsize,
- void *plain, size_t length)
+ void *plain, size_t length)
{
-struct aes_ctx *ctx = _ctx;
-sAesData aesData;
-
- aesData.iv = ctx->iv;
- aesData.in_block = (void*)encr;
- aesData.out_block = plain;
- aesData.expanded_key = ctx->expanded_key_dec;
- aesData.num_blocks = (encrsize + 1) / 16;
+ struct aes_ctx *ctx = _ctx;
- ctx->dec(&aesData);
+ aesni_cbc_encrypt (encr, plain, encrsize,
+ &ctx->expanded_key_dec, ctx->iv, 0);
return 0;
}
.deinit = aes_deinit,
};
-static unsigned check_optimized_aes(void)
+static unsigned
+check_optimized_aes (void)
{
-unsigned int a,b,c,d;
- cpuid(1, a,b,c,d);
-
+ unsigned int a, b, c, d;
+ cpuid (1, a, b, c, d);
+
return (c & 0x2000000);
}
void
register_x86_crypto (void)
{
-int ret;
- if (check_optimized_aes()) {
- fprintf(stderr, "Intel AES accelerator was detected\n");
- ret = gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_128_CBC, 80, &cipher_struct);
- if (ret < 0)
- {
- gnutls_assert ();
- }
-
- ret = gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_192_CBC, 80, &cipher_struct);
- if (ret < 0)
- {
- gnutls_assert ();
- }
-
- ret = gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_CBC, 80, &cipher_struct);
- if (ret < 0)
- {
- gnutls_assert ();
- }
- }
-
- return;
+ int ret;
+ if (check_optimized_aes ())
+ {
+ fprintf (stderr, "Intel AES accelerator was detected\n");
+ ret =
+ gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_128_CBC, 80,
+ &cipher_struct);
+ if (ret < 0)
+ {
+ gnutls_assert ();
+ }
+
+ ret =
+ gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_192_CBC, 80,
+ &cipher_struct);
+ if (ret < 0)
+ {
+ gnutls_assert ();
+ }
+
+ ret =
+ gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_CBC, 80,
+ &cipher_struct);
+ if (ret < 0)
+ {
+ gnutls_assert ();
+ }
+ }
+
+ return;
}
--- /dev/null
+# Copyright (c) 2006, Andy Polyakov by <appro@openssl.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain copyright notices,
+# this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# * Neither the name of the Andy Polyakov nor the names of its
+# copyright holder and contributors may be used to endorse or
+# promote products derived from this software without specific
+# prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text
+.globl aesni_encrypt
+.type aesni_encrypt,@function
+.align 16
+aesni_encrypt:
+ movups (%rdi),%xmm0
+ movl 240(%rdx),%eax
+ movaps (%rdx),%xmm4
+ movaps 16(%rdx),%xmm5
+ leaq 32(%rdx),%rdx
+ pxor %xmm4,%xmm0
+.Loop_enc1_1:
+.byte 102,15,56,220,197
+ decl %eax
+ movaps (%rdx),%xmm5
+ leaq 16(%rdx),%rdx
+ jnz .Loop_enc1_1
+.byte 102,15,56,221,197
+ movups %xmm0,(%rsi)
+ .byte 0xf3,0xc3
+.size aesni_encrypt,.-aesni_encrypt
+
+.globl aesni_decrypt
+.type aesni_decrypt,@function
+.align 16
+aesni_decrypt:
+ movups (%rdi),%xmm0
+ movl 240(%rdx),%eax
+ movaps (%rdx),%xmm4
+ movaps 16(%rdx),%xmm5
+ leaq 32(%rdx),%rdx
+ pxor %xmm4,%xmm0
+.Loop_dec1_2:
+.byte 102,15,56,222,197
+ decl %eax
+ movaps (%rdx),%xmm5
+ leaq 16(%rdx),%rdx
+ jnz .Loop_dec1_2
+.byte 102,15,56,223,197
+ movups %xmm0,(%rsi)
+ .byte 0xf3,0xc3
+.size aesni_decrypt, .-aesni_decrypt
+.type _aesni_encrypt3,@function
+.align 16
+_aesni_encrypt3:
+ movaps (%rcx),%xmm4
+ shrl $1,%eax
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+ pxor %xmm4,%xmm1
+ pxor %xmm4,%xmm2
+
+.Lenc_loop3:
+.byte 102,15,56,220,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,220,205
+ decl %eax
+.byte 102,15,56,220,213
+.byte 102,15,56,220,196
+ movaps 16(%rcx),%xmm5
+.byte 102,15,56,220,204
+ leaq 32(%rcx),%rcx
+.byte 102,15,56,220,212
+ jnz .Lenc_loop3
+
+.byte 102,15,56,220,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,220,205
+.byte 102,15,56,220,213
+.byte 102,15,56,221,196
+.byte 102,15,56,221,204
+.byte 102,15,56,221,212
+ .byte 0xf3,0xc3
+.size _aesni_encrypt3,.-_aesni_encrypt3
+.type _aesni_decrypt3,@function
+.align 16
+_aesni_decrypt3:
+ movaps (%rcx),%xmm4
+ shrl $1,%eax
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+ pxor %xmm4,%xmm1
+ pxor %xmm4,%xmm2
+
+.Ldec_loop3:
+.byte 102,15,56,222,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,222,205
+ decl %eax
+.byte 102,15,56,222,213
+.byte 102,15,56,222,196
+ movaps 16(%rcx),%xmm5
+.byte 102,15,56,222,204
+ leaq 32(%rcx),%rcx
+.byte 102,15,56,222,212
+ jnz .Ldec_loop3
+
+.byte 102,15,56,222,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,222,205
+.byte 102,15,56,222,213
+.byte 102,15,56,223,196
+.byte 102,15,56,223,204
+.byte 102,15,56,223,212
+ .byte 0xf3,0xc3
+.size _aesni_decrypt3,.-_aesni_decrypt3
+.type _aesni_encrypt4,@function
+.align 16
+_aesni_encrypt4:
+ movaps (%rcx),%xmm4
+ shrl $1,%eax
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+ pxor %xmm4,%xmm1
+ pxor %xmm4,%xmm2
+ pxor %xmm4,%xmm3
+
+.Lenc_loop4:
+.byte 102,15,56,220,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,220,205
+ decl %eax
+.byte 102,15,56,220,213
+.byte 102,15,56,220,221
+.byte 102,15,56,220,196
+ movaps 16(%rcx),%xmm5
+.byte 102,15,56,220,204
+ leaq 32(%rcx),%rcx
+.byte 102,15,56,220,212
+.byte 102,15,56,220,220
+ jnz .Lenc_loop4
+
+.byte 102,15,56,220,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,220,205
+.byte 102,15,56,220,213
+.byte 102,15,56,220,221
+.byte 102,15,56,221,196
+.byte 102,15,56,221,204
+.byte 102,15,56,221,212
+.byte 102,15,56,221,220
+ .byte 0xf3,0xc3
+.size _aesni_encrypt4,.-_aesni_encrypt4
+.type _aesni_decrypt4,@function
+.align 16
+_aesni_decrypt4:
+ movaps (%rcx),%xmm4
+ shrl $1,%eax
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+ pxor %xmm4,%xmm1
+ pxor %xmm4,%xmm2
+ pxor %xmm4,%xmm3
+
+.Ldec_loop4:
+.byte 102,15,56,222,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,222,205
+ decl %eax
+.byte 102,15,56,222,213
+.byte 102,15,56,222,221
+.byte 102,15,56,222,196
+ movaps 16(%rcx),%xmm5
+.byte 102,15,56,222,204
+ leaq 32(%rcx),%rcx
+.byte 102,15,56,222,212
+.byte 102,15,56,222,220
+ jnz .Ldec_loop4
+
+.byte 102,15,56,222,197
+ movaps (%rcx),%xmm4
+.byte 102,15,56,222,205
+.byte 102,15,56,222,213
+.byte 102,15,56,222,221
+.byte 102,15,56,223,196
+.byte 102,15,56,223,204
+.byte 102,15,56,223,212
+.byte 102,15,56,223,220
+ .byte 0xf3,0xc3
+.size _aesni_decrypt4,.-_aesni_decrypt4
+.globl aesni_ecb_encrypt
+.type aesni_ecb_encrypt,@function
+.align 16
+aesni_ecb_encrypt:
+ cmpq $16,%rdx
+ jb .Lecb_ret
+
+ movl 240(%rcx),%eax
+ andq $-16,%rdx
+ movq %rcx,%r11
+ testl %r8d,%r8d
+ movl %eax,%r10d
+ jz .Lecb_decrypt
+
+ subq $64,%rdx
+ jbe .Lecb_enc_tail
+ jmp .Lecb_enc_loop3
+.align 16
+.Lecb_enc_loop3:
+ movups (%rdi),%xmm0
+ movups 16(%rdi),%xmm1
+ movups 32(%rdi),%xmm2
+ call _aesni_encrypt3
+ subq $48,%rdx
+ leaq 48(%rdi),%rdi
+ leaq 48(%rsi),%rsi
+ movups %xmm0,-48(%rsi)
+ movl %r10d,%eax
+ movups %xmm1,-32(%rsi)
+ movq %r11,%rcx
+ movups %xmm2,-16(%rsi)
+ ja .Lecb_enc_loop3
+
+.Lecb_enc_tail:
+ addq $64,%rdx
+ jz .Lecb_ret
+
+ cmpq $16,%rdx
+ movups (%rdi),%xmm0
+ je .Lecb_enc_one
+ cmpq $32,%rdx
+ movups 16(%rdi),%xmm1
+ je .Lecb_enc_two
+ cmpq $48,%rdx
+ movups 32(%rdi),%xmm2
+ je .Lecb_enc_three
+ movups 48(%rdi),%xmm3
+ call _aesni_encrypt4
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ movups %xmm2,32(%rsi)
+ movups %xmm3,48(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_enc_one:
+ movaps (%rcx),%xmm4
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+.Loop_enc1_3:
+.byte 102,15,56,220,197
+ decl %eax
+ movaps (%rcx),%xmm5
+ leaq 16(%rcx),%rcx
+ jnz .Loop_enc1_3
+.byte 102,15,56,221,197
+ movups %xmm0,(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_enc_two:
+ call _aesni_encrypt3
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_enc_three:
+ call _aesni_encrypt3
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ movups %xmm2,32(%rsi)
+ jmp .Lecb_ret
+
+.align 16
+.Lecb_decrypt:
+ subq $64,%rdx
+ jbe .Lecb_dec_tail
+ jmp .Lecb_dec_loop3
+.align 16
+.Lecb_dec_loop3:
+ movups (%rdi),%xmm0
+ movups 16(%rdi),%xmm1
+ movups 32(%rdi),%xmm2
+ call _aesni_decrypt3
+ subq $48,%rdx
+ leaq 48(%rdi),%rdi
+ leaq 48(%rsi),%rsi
+ movups %xmm0,-48(%rsi)
+ movl %r10d,%eax
+ movups %xmm1,-32(%rsi)
+ movq %r11,%rcx
+ movups %xmm2,-16(%rsi)
+ ja .Lecb_dec_loop3
+
+.Lecb_dec_tail:
+ addq $64,%rdx
+ jz .Lecb_ret
+
+ cmpq $16,%rdx
+ movups (%rdi),%xmm0
+ je .Lecb_dec_one
+ cmpq $32,%rdx
+ movups 16(%rdi),%xmm1
+ je .Lecb_dec_two
+ cmpq $48,%rdx
+ movups 32(%rdi),%xmm2
+ je .Lecb_dec_three
+ movups 48(%rdi),%xmm3
+ call _aesni_decrypt4
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ movups %xmm2,32(%rsi)
+ movups %xmm3,48(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_dec_one:
+ movaps (%rcx),%xmm4
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+.Loop_dec1_4:
+.byte 102,15,56,222,197
+ decl %eax
+ movaps (%rcx),%xmm5
+ leaq 16(%rcx),%rcx
+ jnz .Loop_dec1_4
+.byte 102,15,56,223,197
+ movups %xmm0,(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_dec_two:
+ call _aesni_decrypt3
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ jmp .Lecb_ret
+.align 16
+.Lecb_dec_three:
+ call _aesni_decrypt3
+ movups %xmm0,(%rsi)
+ movups %xmm1,16(%rsi)
+ movups %xmm2,32(%rsi)
+
+.Lecb_ret:
+ .byte 0xf3,0xc3
+.size aesni_ecb_encrypt,.-aesni_ecb_encrypt
+.globl aesni_cbc_encrypt
+.type aesni_cbc_encrypt,@function
+.align 16
+aesni_cbc_encrypt:
+ testq %rdx,%rdx
+ jz .Lcbc_ret
+
+ movl 240(%rcx),%r10d
+ movq %rcx,%r11
+ testl %r9d,%r9d
+ jz .Lcbc_decrypt
+
+ movups (%r8),%xmm0
+ cmpq $16,%rdx
+ movl %r10d,%eax
+ jb .Lcbc_enc_tail
+ subq $16,%rdx
+ jmp .Lcbc_enc_loop
+.align 16
+.Lcbc_enc_loop:
+ movups (%rdi),%xmm1
+ leaq 16(%rdi),%rdi
+ pxor %xmm1,%xmm0
+ movaps (%rcx),%xmm4
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+.Loop_enc1_5:
+.byte 102,15,56,220,197
+ decl %eax
+ movaps (%rcx),%xmm5
+ leaq 16(%rcx),%rcx
+ jnz .Loop_enc1_5
+.byte 102,15,56,221,197
+ subq $16,%rdx
+ leaq 16(%rsi),%rsi
+ movl %r10d,%eax
+ movq %r11,%rcx
+ movups %xmm0,-16(%rsi)
+ jnc .Lcbc_enc_loop
+ addq $16,%rdx
+ jnz .Lcbc_enc_tail
+ movups %xmm0,(%r8)
+ jmp .Lcbc_ret
+
+.Lcbc_enc_tail:
+ movq %rdx,%rcx
+ xchgq %rdi,%rsi
+.long 0x9066A4F3
+ movl $16,%ecx
+ subq %rdx,%rcx
+ xorl %eax,%eax
+.long 0x9066AAF3
+ leaq -16(%rdi),%rdi
+ movl %r10d,%eax
+ movq %rdi,%rsi
+ movq %r11,%rcx
+ xorq %rdx,%rdx
+ jmp .Lcbc_enc_loop
+
+.align 16
+.Lcbc_decrypt:
+ movups (%r8),%xmm6
+ subq $64,%rdx
+ movl %r10d,%eax
+ jbe .Lcbc_dec_tail
+ jmp .Lcbc_dec_loop3
+.align 16
+.Lcbc_dec_loop3:
+ movups (%rdi),%xmm0
+ movups 16(%rdi),%xmm1
+ movups 32(%rdi),%xmm2
+ movaps %xmm0,%xmm7
+ movaps %xmm1,%xmm8
+ movaps %xmm2,%xmm9
+ call _aesni_decrypt3
+ subq $48,%rdx
+ leaq 48(%rdi),%rdi
+ leaq 48(%rsi),%rsi
+ pxor %xmm6,%xmm0
+ pxor %xmm7,%xmm1
+ movaps %xmm9,%xmm6
+ pxor %xmm8,%xmm2
+ movups %xmm0,-48(%rsi)
+ movl %r10d,%eax
+ movups %xmm1,-32(%rsi)
+ movq %r11,%rcx
+ movups %xmm2,-16(%rsi)
+ ja .Lcbc_dec_loop3
+
+.Lcbc_dec_tail:
+ addq $64,%rdx
+ movups %xmm6,(%r8)
+ jz .Lcbc_dec_ret
+
+ movups (%rdi),%xmm0
+ cmpq $16,%rdx
+ movaps %xmm0,%xmm7
+ jbe .Lcbc_dec_one
+ movups 16(%rdi),%xmm1
+ cmpq $32,%rdx
+ movaps %xmm1,%xmm8
+ jbe .Lcbc_dec_two
+ movups 32(%rdi),%xmm2
+ cmpq $48,%rdx
+ movaps %xmm2,%xmm9
+ jbe .Lcbc_dec_three
+ movups 48(%rdi),%xmm3
+ call _aesni_decrypt4
+ pxor %xmm6,%xmm0
+ movups 48(%rdi),%xmm6
+ pxor %xmm7,%xmm1
+ movups %xmm0,(%rsi)
+ pxor %xmm8,%xmm2
+ movups %xmm1,16(%rsi)
+ pxor %xmm9,%xmm3
+ movups %xmm2,32(%rsi)
+ movaps %xmm3,%xmm0
+ leaq 48(%rsi),%rsi
+ jmp .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_one:
+ movaps (%rcx),%xmm4
+ movaps 16(%rcx),%xmm5
+ leaq 32(%rcx),%rcx
+ pxor %xmm4,%xmm0
+.Loop_dec1_6:
+.byte 102,15,56,222,197
+ decl %eax
+ movaps (%rcx),%xmm5
+ leaq 16(%rcx),%rcx
+ jnz .Loop_dec1_6
+.byte 102,15,56,223,197
+ pxor %xmm6,%xmm0
+ movaps %xmm7,%xmm6
+ jmp .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_two:
+ call _aesni_decrypt3
+ pxor %xmm6,%xmm0
+ pxor %xmm7,%xmm1
+ movups %xmm0,(%rsi)
+ movaps %xmm8,%xmm6
+ movaps %xmm1,%xmm0
+ leaq 16(%rsi),%rsi
+ jmp .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_three:
+ call _aesni_decrypt3
+ pxor %xmm6,%xmm0
+ pxor %xmm7,%xmm1
+ movups %xmm0,(%rsi)
+ pxor %xmm8,%xmm2
+ movups %xmm1,16(%rsi)
+ movaps %xmm9,%xmm6
+ movaps %xmm2,%xmm0
+ leaq 32(%rsi),%rsi
+ jmp .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_tail_collected:
+ andq $15,%rdx
+ movups %xmm6,(%r8)
+ jnz .Lcbc_dec_tail_partial
+ movups %xmm0,(%rsi)
+ jmp .Lcbc_dec_ret
+.Lcbc_dec_tail_partial:
+ movaps %xmm0,-24(%rsp)
+ movq %rsi,%rdi
+ movq %rdx,%rcx
+ leaq -24(%rsp),%rsi
+.long 0x9066A4F3
+
+.Lcbc_dec_ret:
+.Lcbc_ret:
+ .byte 0xf3,0xc3
+.size aesni_cbc_encrypt,.-aesni_cbc_encrypt
+.globl aesni_set_decrypt_key
+.type aesni_set_decrypt_key,@function
+.align 16
+aesni_set_decrypt_key:
+.byte 0x48,0x83,0xEC,0x08
+ call _aesni_set_encrypt_key
+ shll $4,%esi
+ testl %eax,%eax
+ jnz .Ldec_key_ret
+ leaq 16(%rdx,%rsi,1),%rdi
+
+ movaps (%rdx),%xmm0
+ movaps (%rdi),%xmm1
+ movaps %xmm0,(%rdi)
+ movaps %xmm1,(%rdx)
+ leaq 16(%rdx),%rdx
+ leaq -16(%rdi),%rdi
+
+.Ldec_key_inverse:
+ movaps (%rdx),%xmm0
+ movaps (%rdi),%xmm1
+.byte 102,15,56,219,192
+.byte 102,15,56,219,201
+ leaq 16(%rdx),%rdx
+ leaq -16(%rdi),%rdi
+ cmpq %rdx,%rdi
+ movaps %xmm0,16(%rdi)
+ movaps %xmm1,-16(%rdx)
+ ja .Ldec_key_inverse
+
+ movaps (%rdx),%xmm0
+.byte 102,15,56,219,192
+ movaps %xmm0,(%rdi)
+.Ldec_key_ret:
+ addq $8,%rsp
+ .byte 0xf3,0xc3
+.LSEH_end_set_decrypt_key:
+.size aesni_set_decrypt_key,.-aesni_set_decrypt_key
+.globl aesni_set_encrypt_key
+.type aesni_set_encrypt_key,@function
+.align 16
+aesni_set_encrypt_key:
+_aesni_set_encrypt_key:
+.byte 0x48,0x83,0xEC,0x08
+ testq %rdi,%rdi
+ movq $-1,%rax
+ jz .Lenc_key_ret
+ testq %rdx,%rdx
+ jz .Lenc_key_ret
+
+ movups (%rdi),%xmm0
+ pxor %xmm4,%xmm4
+ leaq 16(%rdx),%rax
+ cmpl $256,%esi
+ je .L14rounds
+ cmpl $192,%esi
+ je .L12rounds
+ cmpl $128,%esi
+ jne .Lbad_keybits
+
+.L10rounds:
+ movl $9,%esi
+ movaps %xmm0,(%rdx)
+.byte 102,15,58,223,200,1
+ call .Lkey_expansion_128_cold
+.byte 102,15,58,223,200,2
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,4
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,8
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,16
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,32
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,64
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,128
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,27
+ call .Lkey_expansion_128
+.byte 102,15,58,223,200,54
+ call .Lkey_expansion_128
+ movaps %xmm0,(%rax)
+ movl %esi,80(%rax)
+ xorl %eax,%eax
+ jmp .Lenc_key_ret
+
+.align 16
+.L12rounds:
+ movq 16(%rdi),%xmm2
+ movl $11,%esi
+ movaps %xmm0,(%rdx)
+.byte 102,15,58,223,202,1
+ call .Lkey_expansion_192a_cold
+.byte 102,15,58,223,202,2
+ call .Lkey_expansion_192b
+.byte 102,15,58,223,202,4
+ call .Lkey_expansion_192a
+.byte 102,15,58,223,202,8
+ call .Lkey_expansion_192b
+.byte 102,15,58,223,202,16
+ call .Lkey_expansion_192a
+.byte 102,15,58,223,202,32
+ call .Lkey_expansion_192b
+.byte 102,15,58,223,202,64
+ call .Lkey_expansion_192a
+.byte 102,15,58,223,202,128
+ call .Lkey_expansion_192b
+ movaps %xmm0,(%rax)
+ movl %esi,48(%rax)
+ xorq %rax,%rax
+ jmp .Lenc_key_ret
+
+.align 16
+.L14rounds:
+ movups 16(%rdi),%xmm2
+ movl $13,%esi
+ leaq 16(%rax),%rax
+ movaps %xmm0,(%rdx)
+ movaps %xmm2,16(%rdx)
+.byte 102,15,58,223,202,1
+ call .Lkey_expansion_256a_cold
+.byte 102,15,58,223,200,1
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,2
+ call .Lkey_expansion_256a
+.byte 102,15,58,223,200,2
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,4
+ call .Lkey_expansion_256a
+.byte 102,15,58,223,200,4
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,8
+ call .Lkey_expansion_256a
+.byte 102,15,58,223,200,8
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,16
+ call .Lkey_expansion_256a
+.byte 102,15,58,223,200,16
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,32
+ call .Lkey_expansion_256a
+.byte 102,15,58,223,200,32
+ call .Lkey_expansion_256b
+.byte 102,15,58,223,202,64
+ call .Lkey_expansion_256a
+ movaps %xmm0,(%rax)
+ movl %esi,16(%rax)
+ xorq %rax,%rax
+ jmp .Lenc_key_ret
+
+.align 16
+.Lbad_keybits:
+ movq $-2,%rax
+.Lenc_key_ret:
+ addq $8,%rsp
+ .byte 0xf3,0xc3
+.LSEH_end_set_encrypt_key:
+
+.align 16
+.Lkey_expansion_128:
+ movaps %xmm0,(%rax)
+ leaq 16(%rax),%rax
+.Lkey_expansion_128_cold:
+ shufps $16,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ pshufd $255,%xmm1,%xmm1
+ pxor %xmm1,%xmm0
+ .byte 0xf3,0xc3
+
+.align 16
+.Lkey_expansion_192a:
+ movaps %xmm0,(%rax)
+ leaq 16(%rax),%rax
+.Lkey_expansion_192a_cold:
+ movaps %xmm2,%xmm5
+.Lkey_expansion_192b_warm:
+ shufps $16,%xmm0,%xmm4
+ movaps %xmm2,%xmm3
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pslldq $4,%xmm3
+ pxor %xmm4,%xmm0
+ pshufd $85,%xmm1,%xmm1
+ pxor %xmm3,%xmm2
+ pxor %xmm1,%xmm0
+ pshufd $255,%xmm0,%xmm3
+ pxor %xmm3,%xmm2
+ .byte 0xf3,0xc3
+
+.align 16
+.Lkey_expansion_192b:
+ movaps %xmm0,%xmm3
+ shufps $68,%xmm0,%xmm5
+ movaps %xmm5,(%rax)
+ shufps $78,%xmm2,%xmm3
+ movaps %xmm3,16(%rax)
+ leaq 32(%rax),%rax
+ jmp .Lkey_expansion_192b_warm
+
+.align 16
+.Lkey_expansion_256a:
+ movaps %xmm2,(%rax)
+ leaq 16(%rax),%rax
+.Lkey_expansion_256a_cold:
+ shufps $16,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ pshufd $255,%xmm1,%xmm1
+ pxor %xmm1,%xmm0
+ .byte 0xf3,0xc3
+
+.align 16
+.Lkey_expansion_256b:
+ movaps %xmm0,(%rax)
+ leaq 16(%rax),%rax
+
+ shufps $16,%xmm2,%xmm4
+ pxor %xmm4,%xmm2
+ shufps $140,%xmm2,%xmm4
+ pxor %xmm4,%xmm2
+ pshufd $170,%xmm1,%xmm1
+ pxor %xmm1,%xmm2
+ .byte 0xf3,0xc3
+.size aesni_set_encrypt_key,.-aesni_set_encrypt_key
+.byte 65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69,83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.align 64
--- /dev/null
+# Copyright (c) 2006, Andy Polyakov by <appro@openssl.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain copyright notices,
+# this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# * Neither the name of the Andy Polyakov nor the names of its
+# copyright holder and contributors may be used to endorse or
+# promote products derived from this software without specific
+# prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.file "aesni-x86.s"
+.text
+.globl aesni_encrypt
+.type aesni_encrypt,@function
+.align 16
+aesni_encrypt:
+.L_aesni_encrypt_begin:
+ movl 4(%esp),%eax
+ movl 12(%esp),%edx
+ movups (%eax),%xmm0
+ movl 240(%edx),%ecx
+ movl 8(%esp),%eax
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L000enc1_loop:
+ aesenc %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L000enc1_loop
+ aesenclast %xmm4,%xmm0
+ movups %xmm0,(%eax)
+ ret
+.size aesni_encrypt,.-.L_aesni_encrypt_begin
+.globl aesni_decrypt
+.type aesni_decrypt,@function
+.align 16
+aesni_decrypt:
+.L_aesni_decrypt_begin:
+ movl 4(%esp),%eax
+ movl 12(%esp),%edx
+ movups (%eax),%xmm0
+ movl 240(%edx),%ecx
+ movl 8(%esp),%eax
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L001dec1_loop:
+ aesdec %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L001dec1_loop
+ aesdeclast %xmm4,%xmm0
+ movups %xmm0,(%eax)
+ ret
+.size aesni_decrypt,.-.L_aesni_decrypt_begin
+.type _aesni_encrypt3,@function
+.align 16
+_aesni_encrypt3:
+ movups (%edx),%xmm3
+ shrl $1,%ecx
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+ pxor %xmm3,%xmm1
+ pxor %xmm3,%xmm2
+ jmp .L002enc3_loop
+.align 16
+.L002enc3_loop:
+ aesenc %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesenc %xmm4,%xmm1
+ decl %ecx
+ aesenc %xmm4,%xmm2
+ movups 16(%edx),%xmm4
+ aesenc %xmm3,%xmm0
+ leal 32(%edx),%edx
+ aesenc %xmm3,%xmm1
+ aesenc %xmm3,%xmm2
+ jnz .L002enc3_loop
+ aesenc %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesenc %xmm4,%xmm1
+ aesenc %xmm4,%xmm2
+ aesenclast %xmm3,%xmm0
+ aesenclast %xmm3,%xmm1
+ aesenclast %xmm3,%xmm2
+ ret
+.size _aesni_encrypt3,.-_aesni_encrypt3
+.type _aesni_decrypt3,@function
+.align 16
+_aesni_decrypt3:
+ movups (%edx),%xmm3
+ shrl $1,%ecx
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+ pxor %xmm3,%xmm1
+ pxor %xmm3,%xmm2
+ jmp .L003dec3_loop
+.align 16
+.L003dec3_loop:
+ aesdec %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesdec %xmm4,%xmm1
+ decl %ecx
+ aesdec %xmm4,%xmm2
+ movups 16(%edx),%xmm4
+ aesdec %xmm3,%xmm0
+ leal 32(%edx),%edx
+ aesdec %xmm3,%xmm1
+ aesdec %xmm3,%xmm2
+ jnz .L003dec3_loop
+ aesdec %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesdec %xmm4,%xmm1
+ aesdec %xmm4,%xmm2
+ aesdeclast %xmm3,%xmm0
+ aesdeclast %xmm3,%xmm1
+ aesdeclast %xmm3,%xmm2
+ ret
+.size _aesni_decrypt3,.-_aesni_decrypt3
+.type _aesni_encrypt4,@function
+.align 16
+_aesni_encrypt4:
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ shrl $1,%ecx
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+ pxor %xmm3,%xmm1
+ pxor %xmm3,%xmm2
+ pxor %xmm3,%xmm7
+ jmp .L004enc3_loop
+.align 16
+.L004enc3_loop:
+ aesenc %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesenc %xmm4,%xmm1
+ decl %ecx
+ aesenc %xmm4,%xmm2
+ aesenc %xmm4,%xmm7
+ movups 16(%edx),%xmm4
+ aesenc %xmm3,%xmm0
+ leal 32(%edx),%edx
+ aesenc %xmm3,%xmm1
+ aesenc %xmm3,%xmm2
+ aesenc %xmm3,%xmm7
+ jnz .L004enc3_loop
+ aesenc %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesenc %xmm4,%xmm1
+ aesenc %xmm4,%xmm2
+ aesenc %xmm4,%xmm7
+ aesenclast %xmm3,%xmm0
+ aesenclast %xmm3,%xmm1
+ aesenclast %xmm3,%xmm2
+ aesenclast %xmm3,%xmm7
+ ret
+.size _aesni_encrypt4,.-_aesni_encrypt4
+.type _aesni_decrypt4,@function
+.align 16
+_aesni_decrypt4:
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ shrl $1,%ecx
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+ pxor %xmm3,%xmm1
+ pxor %xmm3,%xmm2
+ pxor %xmm3,%xmm7
+ jmp .L005dec3_loop
+.align 16
+.L005dec3_loop:
+ aesdec %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesdec %xmm4,%xmm1
+ decl %ecx
+ aesdec %xmm4,%xmm2
+ aesdec %xmm4,%xmm7
+ movups 16(%edx),%xmm4
+ aesdec %xmm3,%xmm0
+ leal 32(%edx),%edx
+ aesdec %xmm3,%xmm1
+ aesdec %xmm3,%xmm2
+ aesdec %xmm3,%xmm7
+ jnz .L005dec3_loop
+ aesdec %xmm4,%xmm0
+ movups (%edx),%xmm3
+ aesdec %xmm4,%xmm1
+ aesdec %xmm4,%xmm2
+ aesdec %xmm4,%xmm7
+ aesdeclast %xmm3,%xmm0
+ aesdeclast %xmm3,%xmm1
+ aesdeclast %xmm3,%xmm2
+ aesdeclast %xmm3,%xmm7
+ ret
+.size _aesni_decrypt4,.-_aesni_decrypt4
+.globl aesni_ecb_encrypt
+.type aesni_ecb_encrypt,@function
+.align 16
+aesni_ecb_encrypt:
+.L_aesni_ecb_encrypt_begin:
+ pushl %ebp
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ movl 20(%esp),%esi
+ movl 24(%esp),%edi
+ movl 28(%esp),%eax
+ movl 32(%esp),%edx
+ movl 36(%esp),%ecx
+ cmpl $16,%eax
+ jb .L006ecb_ret
+ andl $-16,%eax
+ testl %ecx,%ecx
+ movl 240(%edx),%ecx
+ movl %edx,%ebp
+ movl %ecx,%ebx
+ jz .L007ecb_decrypt
+ subl $64,%eax
+ jbe .L008ecb_enc_tail
+ jmp .L009ecb_enc_loop3
+.align 16
+.L009ecb_enc_loop3:
+ movups (%esi),%xmm0
+ movups 16(%esi),%xmm1
+ movups 32(%esi),%xmm2
+ call _aesni_encrypt3
+ subl $48,%eax
+ leal 48(%esi),%esi
+ leal 48(%edi),%edi
+ movups %xmm0,-48(%edi)
+ movl %ebp,%edx
+ movups %xmm1,-32(%edi)
+ movl %ebx,%ecx
+ movups %xmm2,-16(%edi)
+ ja .L009ecb_enc_loop3
+.L008ecb_enc_tail:
+ addl $64,%eax
+ jz .L006ecb_ret
+ cmpl $16,%eax
+ movups (%esi),%xmm0
+ je .L010ecb_enc_one
+ cmpl $32,%eax
+ movups 16(%esi),%xmm1
+ je .L011ecb_enc_two
+ cmpl $48,%eax
+ movups 32(%esi),%xmm2
+ je .L012ecb_enc_three
+ movups 48(%esi),%xmm7
+ call _aesni_encrypt4
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ movups %xmm2,32(%edi)
+ movups %xmm7,48(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L010ecb_enc_one:
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L013enc1_loop:
+ aesenc %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L013enc1_loop
+ aesenclast %xmm4,%xmm0
+ movups %xmm0,(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L011ecb_enc_two:
+ call _aesni_encrypt3
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L012ecb_enc_three:
+ call _aesni_encrypt3
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ movups %xmm2,32(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L007ecb_decrypt:
+ subl $64,%eax
+ jbe .L014ecb_dec_tail
+ jmp .L015ecb_dec_loop3
+.align 16
+.L015ecb_dec_loop3:
+ movups (%esi),%xmm0
+ movups 16(%esi),%xmm1
+ movups 32(%esi),%xmm2
+ call _aesni_decrypt3
+ subl $48,%eax
+ leal 48(%esi),%esi
+ leal 48(%edi),%edi
+ movups %xmm0,-48(%edi)
+ movl %ebp,%edx
+ movups %xmm1,-32(%edi)
+ movl %ebx,%ecx
+ movups %xmm2,-16(%edi)
+ ja .L015ecb_dec_loop3
+.L014ecb_dec_tail:
+ addl $64,%eax
+ jz .L006ecb_ret
+ cmpl $16,%eax
+ movups (%esi),%xmm0
+ je .L016ecb_dec_one
+ cmpl $32,%eax
+ movups 16(%esi),%xmm1
+ je .L017ecb_dec_two
+ cmpl $48,%eax
+ movups 32(%esi),%xmm2
+ je .L018ecb_dec_three
+ movups 48(%esi),%xmm7
+ call _aesni_decrypt4
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ movups %xmm2,32(%edi)
+ movups %xmm7,48(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L016ecb_dec_one:
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L019dec1_loop:
+ aesdec %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L019dec1_loop
+ aesdeclast %xmm4,%xmm0
+ movups %xmm0,(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L017ecb_dec_two:
+ call _aesni_decrypt3
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ jmp .L006ecb_ret
+.align 16
+.L018ecb_dec_three:
+ call _aesni_decrypt3
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ movups %xmm2,32(%edi)
+.L006ecb_ret:
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %ebp
+ ret
+.size aesni_ecb_encrypt,.-.L_aesni_ecb_encrypt_begin
+.globl aesni_cbc_encrypt
+.type aesni_cbc_encrypt,@function
+.align 16
+aesni_cbc_encrypt:
+.L_aesni_cbc_encrypt_begin:
+ pushl %ebp
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ movl 20(%esp),%esi
+ movl 24(%esp),%edi
+ movl 28(%esp),%eax
+ movl 32(%esp),%edx
+ testl %eax,%eax
+ movl 36(%esp),%ebp
+ jz .L020cbc_ret
+ cmpl $0,40(%esp)
+ movups (%ebp),%xmm5
+ movl 240(%edx),%ecx
+ movl %edx,%ebp
+ movl %ecx,%ebx
+ je .L021cbc_decrypt
+ movaps %xmm5,%xmm0
+ cmpl $16,%eax
+ jb .L022cbc_enc_tail
+ subl $16,%eax
+ jmp .L023cbc_enc_loop
+.align 16
+.L023cbc_enc_loop:
+ movups (%esi),%xmm5
+ leal 16(%esi),%esi
+ pxor %xmm5,%xmm0
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L024enc1_loop:
+ aesenc %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L024enc1_loop
+ aesenclast %xmm4,%xmm0
+ subl $16,%eax
+ leal 16(%edi),%edi
+ movl %ebx,%ecx
+ movl %ebp,%edx
+ movups %xmm0,-16(%edi)
+ jnc .L023cbc_enc_loop
+ addl $16,%eax
+ jnz .L022cbc_enc_tail
+ movaps %xmm0,%xmm5
+ jmp .L020cbc_ret
+.L022cbc_enc_tail:
+ movl %eax,%ecx
+.long 2767451785
+ movl $16,%ecx
+ subl %eax,%ecx
+ xorl %eax,%eax
+.long 2868115081
+ leal -16(%edi),%edi
+ movl %ebx,%ecx
+ movl %edi,%esi
+ movl %ebp,%edx
+ jmp .L023cbc_enc_loop
+.align 16
+.L021cbc_decrypt:
+ subl $64,%eax
+ jbe .L025cbc_dec_tail
+ jmp .L026cbc_dec_loop3
+.align 16
+.L026cbc_dec_loop3:
+ movups (%esi),%xmm0
+ movups 16(%esi),%xmm1
+ movups 32(%esi),%xmm2
+ movaps %xmm0,%xmm6
+ movaps %xmm1,%xmm7
+ call _aesni_decrypt3
+ subl $48,%eax
+ leal 48(%esi),%esi
+ leal 48(%edi),%edi
+ pxor %xmm5,%xmm0
+ pxor %xmm6,%xmm1
+ movups -16(%esi),%xmm5
+ pxor %xmm7,%xmm2
+ movups %xmm0,-48(%edi)
+ movl %ebx,%ecx
+ movups %xmm1,-32(%edi)
+ movl %ebp,%edx
+ movups %xmm2,-16(%edi)
+ ja .L026cbc_dec_loop3
+.L025cbc_dec_tail:
+ addl $64,%eax
+ jz .L020cbc_ret
+ movups (%esi),%xmm0
+ cmpl $16,%eax
+ movaps %xmm0,%xmm6
+ jbe .L027cbc_dec_one
+ movups 16(%esi),%xmm1
+ cmpl $32,%eax
+ movaps %xmm1,%xmm7
+ jbe .L028cbc_dec_two
+ movups 32(%esi),%xmm2
+ cmpl $48,%eax
+ jbe .L029cbc_dec_three
+ movups 48(%esi),%xmm7
+ call _aesni_decrypt4
+ movups 16(%esi),%xmm3
+ movups 32(%esi),%xmm4
+ pxor %xmm5,%xmm0
+ pxor %xmm6,%xmm1
+ movups 48(%esi),%xmm5
+ movups %xmm0,(%edi)
+ pxor %xmm3,%xmm2
+ pxor %xmm4,%xmm7
+ movups %xmm1,16(%edi)
+ movups %xmm2,32(%edi)
+ movaps %xmm7,%xmm0
+ leal 48(%edi),%edi
+ jmp .L030cbc_dec_tail_collected
+.L027cbc_dec_one:
+ movups (%edx),%xmm3
+ movups 16(%edx),%xmm4
+ leal 32(%edx),%edx
+ pxor %xmm3,%xmm0
+.L031dec1_loop:
+ aesdec %xmm4,%xmm0
+ decl %ecx
+ movups (%edx),%xmm4
+ leal 16(%edx),%edx
+ jnz .L031dec1_loop
+ aesdeclast %xmm4,%xmm0
+ pxor %xmm5,%xmm0
+ movaps %xmm6,%xmm5
+ jmp .L030cbc_dec_tail_collected
+.L028cbc_dec_two:
+ call _aesni_decrypt3
+ pxor %xmm5,%xmm0
+ pxor %xmm6,%xmm1
+ movups %xmm0,(%edi)
+ movaps %xmm1,%xmm0
+ movaps %xmm7,%xmm5
+ leal 16(%edi),%edi
+ jmp .L030cbc_dec_tail_collected
+.L029cbc_dec_three:
+ call _aesni_decrypt3
+ pxor %xmm5,%xmm0
+ pxor %xmm6,%xmm1
+ pxor %xmm7,%xmm2
+ movups %xmm0,(%edi)
+ movups %xmm1,16(%edi)
+ movaps %xmm2,%xmm0
+ movups 32(%esi),%xmm5
+ leal 32(%edi),%edi
+.L030cbc_dec_tail_collected:
+ andl $15,%eax
+ jnz .L032cbc_dec_tail_partial
+ movups %xmm0,(%edi)
+ jmp .L020cbc_ret
+.L032cbc_dec_tail_partial:
+ movl %esp,%ebp
+ subl $16,%esp
+ andl $-16,%esp
+ movaps %xmm0,(%esp)
+ movl %esp,%esi
+ movl %eax,%ecx
+.long 2767451785
+ movl %ebp,%esp
+.L020cbc_ret:
+ movl 36(%esp),%ebp
+ movups %xmm5,(%ebp)
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %ebp
+ ret
+.size aesni_cbc_encrypt,.-.L_aesni_cbc_encrypt_begin
+.type _aesni_set_encrypt_key,@function
+.align 16
+_aesni_set_encrypt_key:
+ testl %eax,%eax
+ jz .L033bad_pointer
+ testl %edx,%edx
+ jz .L033bad_pointer
+ movups (%eax),%xmm0
+ pxor %xmm4,%xmm4
+ leal 16(%edx),%edx
+ cmpl $256,%ecx
+ je .L03414rounds
+ cmpl $192,%ecx
+ je .L03512rounds
+ cmpl $128,%ecx
+ jne .L036bad_keybits
+.align 16
+.L03710rounds:
+ movl $9,%ecx
+ movups %xmm0,-16(%edx)
+ aeskeygenassist $1,%xmm0,%xmm1
+ call .L038key_128_cold
+ aeskeygenassist $2,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $4,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $8,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $16,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $32,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $64,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $128,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $27,%xmm0,%xmm1
+ call .L039key_128
+ aeskeygenassist $54,%xmm0,%xmm1
+ call .L039key_128
+ movups %xmm0,(%edx)
+ movl %ecx,80(%edx)
+ xorl %eax,%eax
+ ret
+.align 16
+.L039key_128:
+ movups %xmm0,(%edx)
+ leal 16(%edx),%edx
+.L038key_128_cold:
+ shufps $16,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ pshufd $255,%xmm1,%xmm1
+ pxor %xmm1,%xmm0
+ ret
+.align 16
+.L03512rounds:
+ movq 16(%eax),%xmm2
+ movl $11,%ecx
+ movups %xmm0,-16(%edx)
+ aeskeygenassist $1,%xmm2,%xmm1
+ call .L040key_192a_cold
+ aeskeygenassist $2,%xmm2,%xmm1
+ call .L041key_192b
+ aeskeygenassist $4,%xmm2,%xmm1
+ call .L042key_192a
+ aeskeygenassist $8,%xmm2,%xmm1
+ call .L041key_192b
+ aeskeygenassist $16,%xmm2,%xmm1
+ call .L042key_192a
+ aeskeygenassist $32,%xmm2,%xmm1
+ call .L041key_192b
+ aeskeygenassist $64,%xmm2,%xmm1
+ call .L042key_192a
+ aeskeygenassist $128,%xmm2,%xmm1
+ call .L041key_192b
+ movups %xmm0,(%edx)
+ movl %ecx,48(%edx)
+ xorl %eax,%eax
+ ret
+.align 16
+.L042key_192a:
+ movups %xmm0,(%edx)
+ leal 16(%edx),%edx
+.align 16
+.L040key_192a_cold:
+ movaps %xmm2,%xmm5
+.L043key_192b_warm:
+ shufps $16,%xmm0,%xmm4
+ movaps %xmm2,%xmm3
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pslldq $4,%xmm3
+ pxor %xmm4,%xmm0
+ pshufd $85,%xmm1,%xmm1
+ pxor %xmm3,%xmm2
+ pxor %xmm1,%xmm0
+ pshufd $255,%xmm0,%xmm3
+ pxor %xmm3,%xmm2
+ ret
+.align 16
+.L041key_192b:
+ movaps %xmm0,%xmm3
+ shufps $68,%xmm0,%xmm5
+ movups %xmm5,(%edx)
+ shufps $78,%xmm2,%xmm3
+ movups %xmm3,16(%edx)
+ leal 32(%edx),%edx
+ jmp .L043key_192b_warm
+.align 16
+.L03414rounds:
+ movups 16(%eax),%xmm2
+ movl $13,%ecx
+ leal 16(%edx),%edx
+ movups %xmm0,-32(%edx)
+ movups %xmm2,-16(%edx)
+ aeskeygenassist $1,%xmm2,%xmm1
+ call .L044key_256a_cold
+ aeskeygenassist $1,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $2,%xmm2,%xmm1
+ call .L046key_256a
+ aeskeygenassist $2,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $4,%xmm2,%xmm1
+ call .L046key_256a
+ aeskeygenassist $4,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $8,%xmm2,%xmm1
+ call .L046key_256a
+ aeskeygenassist $8,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $16,%xmm2,%xmm1
+ call .L046key_256a
+ aeskeygenassist $16,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $32,%xmm2,%xmm1
+ call .L046key_256a
+ aeskeygenassist $32,%xmm0,%xmm1
+ call .L045key_256b
+ aeskeygenassist $64,%xmm2,%xmm1
+ call .L046key_256a
+ movups %xmm0,(%edx)
+ movl %ecx,16(%edx)
+ xorl %eax,%eax
+ ret
+.align 16
+.L046key_256a:
+ movups %xmm2,(%edx)
+ leal 16(%edx),%edx
+.L044key_256a_cold:
+ shufps $16,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ shufps $140,%xmm0,%xmm4
+ pxor %xmm4,%xmm0
+ pshufd $255,%xmm1,%xmm1
+ pxor %xmm1,%xmm0
+ ret
+.align 16
+.L045key_256b:
+ movups %xmm0,(%edx)
+ leal 16(%edx),%edx
+ shufps $16,%xmm2,%xmm4
+ pxor %xmm4,%xmm2
+ shufps $140,%xmm2,%xmm4
+ pxor %xmm4,%xmm2
+ pshufd $170,%xmm1,%xmm1
+ pxor %xmm1,%xmm2
+ ret
+.align 4
+.L033bad_pointer:
+ movl $-1,%eax
+ ret
+.align 4
+.L036bad_keybits:
+ movl $-2,%eax
+ ret
+.size _aesni_set_encrypt_key,.-_aesni_set_encrypt_key
+.globl aesni_set_encrypt_key
+.type aesni_set_encrypt_key,@function
+.align 16
+aesni_set_encrypt_key:
+.L_aesni_set_encrypt_key_begin:
+ movl 4(%esp),%eax
+ movl 8(%esp),%ecx
+ movl 12(%esp),%edx
+ call _aesni_set_encrypt_key
+ ret
+.size aesni_set_encrypt_key,.-.L_aesni_set_encrypt_key_begin
+.globl aesni_set_decrypt_key
+.type aesni_set_decrypt_key,@function
+.align 16
+aesni_set_decrypt_key:
+.L_aesni_set_decrypt_key_begin:
+ movl 4(%esp),%eax
+ movl 8(%esp),%ecx
+ movl 12(%esp),%edx
+ call _aesni_set_encrypt_key
+ movl 12(%esp),%edx
+ shll $4,%ecx
+ testl %eax,%eax
+ jnz .L047dec_key_ret
+ leal 16(%edx,%ecx,1),%eax
+ movups (%edx),%xmm0
+ movups (%eax),%xmm1
+ movups %xmm0,(%eax)
+ movups %xmm1,(%edx)
+ leal 16(%edx),%edx
+ leal -16(%eax),%eax
+.L048dec_key_inverse:
+ movups (%edx),%xmm0
+ movups (%eax),%xmm1
+ aesimc %xmm0,%xmm0
+ aesimc %xmm1,%xmm1
+ leal 16(%edx),%edx
+ leal -16(%eax),%eax
+ cmpl %edx,%eax
+ movups %xmm0,16(%eax)
+ movups %xmm1,-16(%edx)
+ ja .L048dec_key_inverse
+ movups (%edx),%xmm0
+ aesimc %xmm0,%xmm0
+ movups %xmm0,(%edx)
+ xorl %eax,%eax
+.L047dec_key_ret:
+ ret
+.size aesni_set_decrypt_key,.-.L_aesni_set_decrypt_key_begin
+.byte 65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
+.byte 83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
+.byte 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
+.byte 115,108,46,111,114,103,62,0
+++ /dev/null
-[bits 64]\r
-[CPU intelnop]\r
-\r
-; Copyright (c) 2010, Intel Corporation\r
-; All rights reserved.\r
-; \r
-; Redistribution and use in source and binary forms, with or without \r
-; modification, are permitted provided that the following conditions are met:\r
-; \r
-; * Redistributions of source code must retain the above copyright notice, \r
-; this list of conditions and the following disclaimer.\r
-; * Redistributions in binary form must reproduce the above copyright notice, \r
-; this list of conditions and the following disclaimer in the documentation \r
-; and/or other materials provided with the distribution.\r
-; * Neither the name of Intel Corporation nor the names of its contributors \r
-; may be used to endorse or promote products derived from this software \r
-; without specific prior written permission.\r
-; \r
-; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \r
-; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
-; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
-; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \r
-; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
-; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
-; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
-; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \r
-; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF \r
-; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-%macro linux_setup 0\r
-%ifdef __linux__\r
- mov rcx, rdi\r
- mov rdx, rsi\r
-%endif\r
-%endmacro\r
-\r
-%macro inversekey 1\r
- movdqu xmm1,%1\r
- aesimc xmm0,xmm1\r
- movdqu %1,xmm0\r
-%endmacro\r
-\r
-%macro aesdeclast1 1\r
- aesdeclast xmm0,%1\r
-%endmacro\r
-\r
-%macro aesenclast1 1\r
- aesenclast xmm0,%1\r
-%endmacro\r
-\r
-%macro aesdec1 1\r
- aesdec xmm0,%1\r
-%endmacro\r
-\r
-%macro aesenc1 1\r
- aesenc xmm0,%1\r
-%endmacro\r
-\r
-\r
-%macro aesdeclast1_u 1\r
- movdqu xmm4,%1\r
- aesdeclast xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesenclast1_u 1\r
- movdqu xmm4,%1\r
- aesenclast xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesdec1_u 1\r
- movdqu xmm4,%1\r
- aesdec xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesenc1_u 1\r
- movdqu xmm4,%1\r
- aesenc xmm0,xmm4\r
-%endmacro\r
- \r
-%macro aesdec4 1\r
- movdqa xmm4,%1\r
-\r
- aesdec xmm0,xmm4\r
- aesdec xmm1,xmm4\r
- aesdec xmm2,xmm4\r
- aesdec xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-%macro aesdeclast4 1\r
- movdqa xmm4,%1\r
-\r
- aesdeclast xmm0,xmm4\r
- aesdeclast xmm1,xmm4\r
- aesdeclast xmm2,xmm4\r
- aesdeclast xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-\r
-%macro aesenc4 1\r
- movdqa xmm4,%1\r
-\r
- aesenc xmm0,xmm4\r
- aesenc xmm1,xmm4\r
- aesenc xmm2,xmm4\r
- aesenc xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-%macro aesenclast4 1\r
- movdqa xmm4,%1\r
-\r
- aesenclast xmm0,xmm4\r
- aesenclast xmm1,xmm4\r
- aesenclast xmm2,xmm4\r
- aesenclast xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-\r
-%macro load_and_inc4 1\r
- movdqa xmm4,%1\r
- movdqa xmm0,xmm5\r
- movdqa xmm1,xmm5\r
- paddq xmm1,[counter_add_one wrt rip]\r
- movdqa xmm2,xmm5\r
- paddq xmm2,[counter_add_two wrt rip]\r
- movdqa xmm3,xmm5\r
- paddq xmm3,[counter_add_three wrt rip]\r
- pxor xmm0,xmm4\r
- paddq xmm5,[counter_add_four wrt rip]\r
- pxor xmm1,xmm4\r
- pxor xmm2,xmm4\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-%macro xor_with_input4 1\r
- movdqu xmm4,[%1]\r
- pxor xmm0,xmm4\r
- movdqu xmm4,[%1+16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[%1+32]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[%1+48]\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-\r
-\r
-%macro load_and_xor4 2\r
- movdqa xmm4,%2\r
- movdqu xmm0,[%1 + 0*16]\r
- pxor xmm0,xmm4\r
- movdqu xmm1,[%1 + 1*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm2,[%1 + 2*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm3,[%1 + 3*16]\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-%macro store4 1\r
- movdqu [%1 + 0*16],xmm0\r
- movdqu [%1 + 1*16],xmm1\r
- movdqu [%1 + 2*16],xmm2\r
- movdqu [%1 + 3*16],xmm3\r
-%endmacro\r
-\r
-%macro copy_round_keys 3\r
- movdqu xmm4,[%2 + ((%3)*16)]\r
- movdqa [%1 + ((%3)*16)],xmm4\r
-%endmacro\r
-\r
-\r
-%macro key_expansion_1_192 1\r
- ;; Assumes the xmm3 includes all zeros at this point. \r
- pshufd xmm2, xmm2, 11111111b \r
- shufps xmm3, xmm1, 00010000b \r
- pxor xmm1, xmm3 \r
- shufps xmm3, xmm1, 10001100b\r
- pxor xmm1, xmm3 \r
- pxor xmm1, xmm2 \r
- movdqu [rdx+%1], xmm1 \r
-%endmacro\r
-\r
-; Calculate w10 and w11 using calculated w9 and known w4-w5\r
-%macro key_expansion_2_192 1 \r
- movdqa xmm5, xmm4\r
- pslldq xmm5, 4\r
- shufps xmm6, xmm1, 11110000b\r
- pxor xmm6, xmm5\r
- pxor xmm4, xmm6\r
- pshufd xmm7, xmm4, 00001110b \r
- movdqu [rdx+%1], xmm7\r
-%endmacro\r
-\r
-\r
-section .data\r
-align 16\r
-shuffle_mask:\r
-DD 0FFFFFFFFh\r
-DD 03020100h\r
-DD 07060504h\r
-DD 0B0A0908h\r
-\r
-\r
-align 16\r
-counter_add_one:\r
-DD 1\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_two:\r
-DD 2\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_three:\r
-DD 3\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_four:\r
-DD 4\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-\r
-\r
-section .text\r
-\r
-align 16\r
-key_expansion256:\r
-\r
- pshufd xmm2, xmm2, 011111111b\r
-\r
- movdqa xmm4, xmm1\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pxor xmm1, xmm2\r
-\r
- movdqu [rdx], xmm1\r
- add rdx, 0x10\r
- \r
- aeskeygenassist xmm4, xmm1, 0\r
- pshufd xmm2, xmm4, 010101010b\r
-\r
- movdqa xmm4, xmm3\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pxor xmm3, xmm2\r
-\r
- movdqu [rdx], xmm3\r
- add rdx, 0x10\r
-\r
- ret\r
-\r
-\r
-\r
-align 16\r
-key_expansion128: \r
- pshufd xmm2, xmm2, 0xFF;\r
- movdqa xmm3, xmm1\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pxor xmm1, xmm2\r
-\r
- ; storing the result in the key schedule array\r
- movdqu [rdx], xmm1\r
- add rdx, 0x10 \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global iEncExpandKey128\r
-iEncExpandKey128:\r
-\r
- linux_setup\r
-\r
- movdqu xmm1, [rcx] ; loading the key\r
-\r
- movdqu [rdx], xmm1\r
-\r
- movdqa xmm5, [shuffle_mask wrt rip]\r
-\r
- add rdx,16\r
-\r
- aeskeygenassist xmm2, xmm1, 0x1 ; Generating round key 1\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x2 ; Generating round key 2\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x4 ; Generating round key 3\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x8 ; Generating round key 4\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x10 ; Generating round key 5\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x20 ; Generating round key 6\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x40 ; Generating round key 7\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x80 ; Generating round key 8\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x1b ; Generating round key 9\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x36 ; Generating round key 10\r
- call key_expansion128\r
-\r
- ret \r
-\r
-\r
-\r
-align 16\r
-global iEncExpandKey192\r
-iEncExpandKey192:\r
-\r
- linux_setup\r
- sub rsp,64+8\r
- movdqa [rsp],xmm6\r
- movdqa [rsp+16],xmm7\r
-\r
-\r
- movq xmm7, [rcx+16] ; loading the AES key\r
- movq [rdx+16], xmm7 ; Storing key in memory where all key expansion \r
- pshufd xmm4, xmm7, 01001111b\r
- movdqu xmm1, [rcx] ; loading the AES key\r
- movdqu [rdx], xmm1 ; Storing key in memory where all key expansion \r
- \r
- pxor xmm3, xmm3 ; Set xmm3 to be all zeros. Required for the key_expansion. \r
- pxor xmm6, xmm6 ; Set xmm3 to be all zeros. Required for the key_expansion. \r
-\r
- aeskeygenassist xmm2, xmm4, 0x1 ; Complete round key 1 and generate round key 2 \r
- key_expansion_1_192 24\r
- key_expansion_2_192 40 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x2 ; Generate round key 3 and part of round key 4\r
- key_expansion_1_192 48\r
- key_expansion_2_192 64 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x4 ; Complete round key 4 and generate round key 5\r
- key_expansion_1_192 72\r
- key_expansion_2_192 88\r
- \r
- aeskeygenassist xmm2, xmm4, 0x8 ; Generate round key 6 and part of round key 7\r
- key_expansion_1_192 96\r
- key_expansion_2_192 112\r
- \r
- aeskeygenassist xmm2, xmm4, 0x10 ; Complete round key 7 and generate round key 8 \r
- key_expansion_1_192 120\r
- key_expansion_2_192 136 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x20 ; Generate round key 9 and part of round key 10\r
- key_expansion_1_192 144\r
- key_expansion_2_192 160 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x40 ; Complete round key 10 and generate round key 11\r
- key_expansion_1_192 168\r
- key_expansion_2_192 184 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x80 ; Generate round key 12\r
- key_expansion_1_192 192\r
-\r
-\r
- movdqa xmm6,[rsp]\r
- movdqa xmm7,[rsp+16]\r
- add rsp,64+8\r
-\r
- ret \r
-\r
-\r
-\r
-\r
-align 16\r
-global iDecExpandKey128\r
-iDecExpandKey128:\r
-\r
- linux_setup\r
- push rcx\r
- push rdx\r
- sub rsp,16+8\r
-\r
- call iEncExpandKey128\r
-\r
- add rsp,16+8\r
- pop rdx\r
- pop rcx\r
-\r
- inversekey [rdx + 1*16]\r
- inversekey [rdx + 2*16]\r
- inversekey [rdx + 3*16]\r
- inversekey [rdx + 4*16]\r
- inversekey [rdx + 5*16]\r
- inversekey [rdx + 6*16]\r
- inversekey [rdx + 7*16]\r
- inversekey [rdx + 8*16]\r
- inversekey [rdx + 9*16]\r
-\r
- ret\r
-\r
-\r
-align 16\r
-global iDecExpandKey192\r
-iDecExpandKey192:\r
-\r
- linux_setup\r
- push rcx\r
- push rdx\r
- sub rsp,16+8\r
-\r
- call iEncExpandKey192\r
-\r
- add rsp,16+8\r
- pop rdx\r
- pop rcx\r
-\r
- \r
- inversekey [rdx + 1*16]\r
- inversekey [rdx + 2*16]\r
- inversekey [rdx + 3*16]\r
- inversekey [rdx + 4*16]\r
- inversekey [rdx + 5*16]\r
- inversekey [rdx + 6*16]\r
- inversekey [rdx + 7*16]\r
- inversekey [rdx + 8*16]\r
- inversekey [rdx + 9*16]\r
- inversekey [rdx + 10*16]\r
- inversekey [rdx + 11*16]\r
-\r
- ret\r
-\r
-\r
-\r
-align 16\r
-global iDecExpandKey256\r
-iDecExpandKey256:\r
-\r
- linux_setup\r
- push rcx\r
- push rdx\r
- sub rsp,16+8\r
-\r
- call iEncExpandKey256\r
-\r
- add rsp,16+8\r
- pop rdx\r
- pop rcx\r
-\r
- inversekey [rdx + 1*16]\r
- inversekey [rdx + 2*16]\r
- inversekey [rdx + 3*16]\r
- inversekey [rdx + 4*16]\r
- inversekey [rdx + 5*16]\r
- inversekey [rdx + 6*16]\r
- inversekey [rdx + 7*16]\r
- inversekey [rdx + 8*16]\r
- inversekey [rdx + 9*16]\r
- inversekey [rdx + 10*16]\r
- inversekey [rdx + 11*16]\r
- inversekey [rdx + 12*16]\r
- inversekey [rdx + 13*16]\r
-\r
- ret\r
- \r
-\r
- \r
- \r
-align 16\r
-global iEncExpandKey256\r
-iEncExpandKey256:\r
-\r
- linux_setup\r
-\r
- movdqu xmm1, [rcx] ; loading the key\r
- movdqu xmm3, [rcx+16]\r
- movdqu [rdx], xmm1 ; Storing key in memory where all key schedule will be stored\r
- movdqu [rdx+16], xmm3 \r
- \r
- add rdx,32\r
-\r
- movdqa xmm5, [shuffle_mask wrt rip] ; this mask is used by key_expansion\r
-\r
- aeskeygenassist xmm2, xmm3, 0x1 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x2 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x4 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x8 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x10 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x20 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x40 ; \r
-; call key_expansion256 \r
-\r
- pshufd xmm2, xmm2, 011111111b\r
-\r
- movdqa xmm4, xmm1\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pxor xmm1, xmm2\r
-\r
- movdqu [rdx], xmm1\r
-\r
-\r
- ret \r
- \r
- \r
- \r
-\r
-\r
-\r
-align 16\r
-global iDec128\r
-iDec128:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
-\r
-\r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
- test eax,eax\r
- jz end_dec128\r
-\r
- cmp eax,4\r
- jl lp128decsingle\r
-\r
- test rcx,0xf\r
- jz lp128decfour\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- mov rcx,rsp \r
- \r
- \r
-\r
-align 16\r
-lp128decfour:\r
- \r
- test eax,eax\r
- jz end_dec128\r
-\r
- cmp eax,4\r
- jl lp128decsingle\r
-\r
- load_and_xor4 rdx, [rcx+10*16]\r
- add rdx,16*4\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
- \r
- sub eax,4\r
- store4 r8+rdx-(16*4)\r
- jmp lp128decfour\r
-\r
-\r
- align 16\r
-lp128decsingle:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+10*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- add rdx, 16\r
- movdqu [r8 + rdx - 16], xmm0\r
- dec eax\r
- jnz lp128decsingle\r
-\r
-end_dec128:\r
-\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iDec128_CBC\r
-iDec128_CBC:\r
- \r
- linux_setup\r
- sub rsp,16*16+8\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_dec128_CBC\r
-\r
- cmp eax,4\r
- jl lp128decsingle_CBC\r
-\r
- test rcx,0xf\r
- jz lp128decfour_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- mov rcx,rsp \r
-\r
-\r
-align 16\r
-lp128decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec128_CBC\r
-\r
- cmp eax,4\r
- jl lp128decsingle_CBC\r
-\r
- load_and_xor4 rdx, [rcx+10*16]\r
- add rdx,16*4\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqu xmm4,[rdx - 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[rdx - 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 r8+rdx-(16*4)\r
- jmp lp128decfour_CBC\r
-\r
-\r
- align 16\r
-lp128decsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqa xmm1,xmm0\r
- movdqu xmm4,[rcx+10*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- add rdx, 16\r
- movdqu [r8 + rdx - 16], xmm0\r
- dec eax\r
- jnz lp128decsingle_CBC\r
-\r
-end_dec128_CBC:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iDec192_CBC\r
-iDec192_CBC:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- \r
- sub r8,rdx\r
-\r
- test eax,eax\r
- jz end_dec192_CBC\r
-\r
- cmp eax,4\r
- jl lp192decsingle_CBC\r
-\r
- test rcx,0xf\r
- jz lp192decfour_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- mov rcx,rsp \r
-\r
-\r
-align 16\r
-lp192decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec192_CBC\r
-\r
- cmp eax,4\r
- jl lp192decsingle_CBC\r
-\r
- load_and_xor4 rdx, [rcx+12*16]\r
- add rdx,16*4\r
- aesdec4 [rcx+11*16]\r
- aesdec4 [rcx+10*16]\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqu xmm4,[rdx - 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[rdx - 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 r8+rdx-(16*4)\r
- jmp lp192decfour_CBC\r
-\r
-\r
- align 16\r
-lp192decsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+12*16]\r
- movdqa xmm1,xmm0\r
- pxor xmm0, xmm4\r
- aesdec1_u [rcx+11*16]\r
- aesdec1_u [rcx+10*16]\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- add rdx, 16\r
- movdqu [r8 + rdx - 16], xmm0\r
- dec eax\r
- jnz lp192decsingle_CBC\r
-\r
-end_dec192_CBC:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global iDec256_CBC\r
-iDec256_CBC:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- \r
- sub r8,rdx\r
-\r
- test eax,eax\r
- jz end_dec256_CBC\r
-\r
- cmp eax,4\r
- jl lp256decsingle_CBC\r
-\r
- test rcx,0xf\r
- jz lp256decfour_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- copy_round_keys rsp,rcx,13\r
- copy_round_keys rsp,rcx,14\r
- mov rcx,rsp \r
-\r
-align 16\r
-lp256decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec256_CBC\r
-\r
- cmp eax,4\r
- jl lp256decsingle_CBC\r
-\r
- load_and_xor4 rdx, [rcx+14*16]\r
- add rdx,16*4\r
- aesdec4 [rcx+13*16]\r
- aesdec4 [rcx+12*16]\r
- aesdec4 [rcx+11*16]\r
- aesdec4 [rcx+10*16]\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqu xmm4,[rdx - 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[rdx - 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[rdx - 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 r8+rdx-(16*4)\r
- jmp lp256decfour_CBC\r
-\r
-\r
- align 16\r
-lp256decsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+14*16]\r
- movdqa xmm1,xmm0\r
- pxor xmm0, xmm4\r
- aesdec1_u [rcx+13*16]\r
- aesdec1_u [rcx+12*16]\r
- aesdec1_u [rcx+11*16]\r
- aesdec1_u [rcx+10*16]\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- add rdx, 16\r
- movdqu [r8 + rdx - 16], xmm0\r
- dec eax\r
- jnz lp256decsingle_CBC\r
-\r
-end_dec256_CBC:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global iDec192\r
-iDec192:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
-\r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
- \r
- test eax,eax\r
- jz end_dec192\r
-\r
- cmp eax,4\r
- jl lp192decsingle\r
- \r
- test rcx,0xf\r
- jz lp192decfour\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- mov rcx,rsp \r
-\r
-align 16\r
-lp192decfour:\r
- \r
- test eax,eax\r
- jz end_dec192\r
-\r
- cmp eax,4\r
- jl lp192decsingle\r
-\r
- load_and_xor4 rdx, [rcx+12*16]\r
- add rdx,16*4\r
- aesdec4 [rcx+11*16]\r
- aesdec4 [rcx+10*16]\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
- \r
- sub eax,4\r
- store4 r8+rdx-(16*4)\r
- jmp lp192decfour\r
-\r
-\r
- align 16\r
-lp192decsingle:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+12*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [rcx+11*16]\r
- aesdec1_u [rcx+10*16]\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- add rdx, 16\r
- movdqu [r8 + rdx - 16], xmm0\r
- dec eax\r
- jnz lp192decsingle\r
-\r
-end_dec192:\r
-\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global iDec256\r
-iDec256:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_dec256\r
- \r
- cmp eax,4\r
- jl lp256dec\r
-\r
- test rcx,0xf\r
- jz lp256dec4\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- copy_round_keys rsp,rcx,13\r
- copy_round_keys rsp,rcx,14\r
- mov rcx,rsp \r
-\r
- \r
- align 16\r
-lp256dec4: \r
- test eax,eax\r
- jz end_dec256\r
- \r
- cmp eax,4\r
- jl lp256dec\r
- \r
- load_and_xor4 rdx,[rcx+14*16]\r
- add rdx, 4*16\r
- aesdec4 [rcx+13*16]\r
- aesdec4 [rcx+12*16]\r
- aesdec4 [rcx+11*16]\r
- aesdec4 [rcx+10*16]\r
- aesdec4 [rcx+9*16]\r
- aesdec4 [rcx+8*16]\r
- aesdec4 [rcx+7*16]\r
- aesdec4 [rcx+6*16]\r
- aesdec4 [rcx+5*16]\r
- aesdec4 [rcx+4*16]\r
- aesdec4 [rcx+3*16]\r
- aesdec4 [rcx+2*16]\r
- aesdec4 [rcx+1*16]\r
- aesdeclast4 [rcx+0*16]\r
-\r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lp256dec4 \r
- \r
- align 16\r
-lp256dec:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+14*16]\r
- add rdx, 16\r
- pxor xmm0, xmm4 ; Round 0 (only xor)\r
- aesdec1_u [rcx+13*16]\r
- aesdec1_u [rcx+12*16]\r
- aesdec1_u [rcx+11*16]\r
- aesdec1_u [rcx+10*16]\r
- aesdec1_u [rcx+9*16]\r
- aesdec1_u [rcx+8*16]\r
- aesdec1_u [rcx+7*16]\r
- aesdec1_u [rcx+6*16]\r
- aesdec1_u [rcx+5*16]\r
- aesdec1_u [rcx+4*16]\r
- aesdec1_u [rcx+3*16]\r
- aesdec1_u [rcx+2*16]\r
- aesdec1_u [rcx+1*16]\r
- aesdeclast1_u [rcx+0*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp256dec\r
-\r
-end_dec256:\r
- \r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global iEnc128\r
-iEnc128:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_enc128\r
- \r
- cmp eax,4\r
- jl lp128encsingle\r
-\r
- test rcx,0xf\r
- jz lpenc128four\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lpenc128four:\r
- \r
- test eax,eax\r
- jz end_enc128\r
- \r
- cmp eax,4\r
- jl lp128encsingle\r
-\r
- load_and_xor4 rdx,[rcx+0*16]\r
- add rdx,4*16\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenclast4 [rcx+10*16]\r
- \r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lpenc128four\r
- \r
- align 16\r
-lp128encsingle:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16] \r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenclast1_u [rcx+10*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp128encsingle\r
-\r
-end_enc128:\r
-\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iEnc128_CTR\r
-iEnc128_CTR:\r
-\r
- linux_setup\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
-\r
-\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_encctr128\r
- \r
- cmp eax,4\r
- jl lp128encctrsingle\r
-\r
- test rcx,0xf\r
- jz lpencctr128four\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr128four:\r
- \r
- test eax,eax\r
- jz end_encctr128\r
- \r
- cmp eax,4\r
- jl lp128encctrsingle\r
-\r
- load_and_inc4 [rcx+0*16]\r
- add rdx,4*16\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenclast4 [rcx+10*16]\r
- xor_with_input4 rdx-(4*16)\r
- \r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lpencctr128four\r
- \r
- align 16\r
-lp128encctrsingle:\r
-\r
- movdqa xmm0,xmm5\r
- paddq xmm5,[counter_add_one wrt rip]\r
- add rdx, 16\r
- movdqu xmm4,[rcx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16] \r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenclast1_u [rcx+10*16]\r
- movdqu xmm4, [rdx-16]\r
- pxor xmm0,xmm4\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp128encctrsingle\r
-\r
-end_encctr128:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-align 16\r
-global iEnc192_CTR\r
-iEnc192_CTR:\r
-\r
- linux_setup\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
-\r
-\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_encctr192\r
- \r
- cmp eax,4\r
- jl lp192encctrsingle\r
-\r
- test rcx,0xf\r
- jz lpencctr192four\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr192four:\r
- \r
- test eax,eax\r
- jz end_encctr192\r
- \r
- cmp eax,4\r
- jl lp192encctrsingle\r
-\r
- load_and_inc4 [rcx+0*16]\r
- add rdx,4*16\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenc4 [rcx+10*16]\r
- aesenc4 [rcx+11*16]\r
- aesenclast4 [rcx+12*16]\r
- xor_with_input4 rdx-(4*16)\r
- \r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lpencctr192four\r
- \r
- align 16\r
-lp192encctrsingle:\r
-\r
- movdqa xmm5,xmm0\r
- movdqu xmm4,[rcx+0*16]\r
- paddq xmm5,[counter_add_one wrt rip]\r
- add rdx, 16\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16] \r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenc1_u [rcx+10*16]\r
- aesenc1_u [rcx+11*16]\r
- aesenclast1_u [rcx+12*16]\r
- movdqu xmm4, [rdx]\r
- pxor xmm0,xmm4\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp192encctrsingle\r
-\r
-end_encctr192:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iEnc256_CTR\r
-iEnc256_CTR:\r
-\r
- linux_setup\r
-\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm5,[rax]\r
-\r
-\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test eax,eax\r
- jz end_encctr256\r
- \r
- cmp eax,4\r
- jl lp256encctrsingle\r
-\r
- test rcx,0xf\r
- jz lpencctr256four\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- copy_round_keys rsp,rcx,13\r
- copy_round_keys rsp,rcx,14\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr256four:\r
- \r
- test eax,eax\r
- jz end_encctr256\r
- \r
- cmp eax,4\r
- jl lp256encctrsingle\r
-\r
- load_and_inc4 [rcx+0*16]\r
- add rdx,4*16\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenc4 [rcx+10*16]\r
- aesenc4 [rcx+11*16]\r
- aesenc4 [rcx+12*16]\r
- aesenc4 [rcx+13*16]\r
- aesenclast4 [rcx+14*16]\r
- xor_with_input4 rdx-(4*16)\r
- \r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lpencctr256four\r
- \r
- align 16\r
-lp256encctrsingle:\r
-\r
- movdqa xmm5,xmm0\r
- movdqu xmm4,[rcx+0*16]\r
- paddq xmm5,[counter_add_one wrt rip]\r
- add rdx, 16\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16] \r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenc1_u [rcx+10*16]\r
- aesenc1_u [rcx+11*16]\r
- aesenc1_u [rcx+12*16]\r
- aesenc1_u [rcx+13*16]\r
- aesenclast1_u [rcx+14*16]\r
- movdqu xmm4, [rdx]\r
- pxor xmm0,xmm4\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp256encctrsingle\r
-\r
-end_encctr256:\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm5\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global iEnc128_CBC\r
-iEnc128_CBC:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm1,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
-\r
- test rcx,0xf\r
- jz lp128encsingle_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lp128encsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4,[rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm1\r
- pxor xmm0, xmm4\r
- aesenc1 [rcx+1*16]\r
- aesenc1 [rcx+2*16]\r
- aesenc1 [rcx+3*16]\r
- aesenc1 [rcx+4*16] \r
- aesenc1 [rcx+5*16]\r
- aesenc1 [rcx+6*16]\r
- aesenc1 [rcx+7*16]\r
- aesenc1 [rcx+8*16]\r
- aesenc1 [rcx+9*16]\r
- aesenclast1 [rcx+10*16]\r
- movdqa xmm1,xmm0\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp128encsingle_CBC\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm1\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iEnc192_CBC\r
-iEnc192_CBC:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm1,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
- test rcx,0xf\r
- jz lp192encsingle_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- mov rcx,rsp \r
-\r
-\r
-\r
- align 16 \r
- \r
-lp192encsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4, [rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm1\r
- pxor xmm0, xmm4\r
- aesenc1 [rcx+1*16]\r
- aesenc1 [rcx+2*16]\r
- aesenc1 [rcx+3*16]\r
- aesenc1 [rcx+4*16] \r
- aesenc1 [rcx+5*16]\r
- aesenc1 [rcx+6*16]\r
- aesenc1 [rcx+7*16]\r
- aesenc1 [rcx+8*16]\r
- aesenc1 [rcx+9*16]\r
- aesenc1 [rcx+10*16]\r
- aesenc1 [rcx+11*16]\r
- aesenclast1 [rcx+12*16]\r
- movdqa xmm1,xmm0\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp192encsingle_CBC\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm1\r
-\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-align 16\r
-global iEnc256_CBC\r
-iEnc256_CBC:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov r9,rcx\r
- mov rax,[rcx+24]\r
- movdqu xmm1,[rax]\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
- test rcx,0xf\r
- jz lp256encsingle_CBC\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- copy_round_keys rsp,rcx,13\r
- copy_round_keys rsp,rcx,14\r
- mov rcx,rsp \r
-\r
- align 16 \r
- \r
-lp256encsingle_CBC:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4, [rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm1\r
- pxor xmm0, xmm4\r
- aesenc1 [rcx+1*16]\r
- aesenc1 [rcx+2*16]\r
- aesenc1 [rcx+3*16]\r
- aesenc1 [rcx+4*16] \r
- aesenc1 [rcx+5*16]\r
- aesenc1 [rcx+6*16]\r
- aesenc1 [rcx+7*16]\r
- aesenc1 [rcx+8*16]\r
- aesenc1 [rcx+9*16]\r
- aesenc1 [rcx+10*16]\r
- aesenc1 [rcx+11*16]\r
- aesenc1 [rcx+12*16]\r
- aesenc1 [rcx+13*16]\r
- aesenclast1 [rcx+14*16]\r
- movdqa xmm1,xmm0\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp256encsingle_CBC\r
-\r
- mov r9,[r9+24]\r
- movdqu [r9],xmm1\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global iEnc192\r
-iEnc192:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
- \r
- sub r8,rdx\r
-\r
- test eax,eax\r
- jz end_enc192\r
- \r
- cmp eax,4\r
- jl lp192encsingle\r
-\r
- test rcx,0xf\r
- jz lpenc192four\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- mov rcx,rsp \r
-\r
-\r
- align 16 \r
- \r
-lpenc192four:\r
- \r
- test eax,eax\r
- jz end_enc192\r
- \r
- cmp eax,4\r
- jl lp192encsingle\r
-\r
- load_and_xor4 rdx,[rcx+0*16]\r
- add rdx,4*16\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenc4 [rcx+10*16]\r
- aesenc4 [rcx+11*16]\r
- aesenclast4 [rcx+12*16]\r
- \r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lpenc192four\r
- \r
- align 16\r
-lp192encsingle:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4, [rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16] \r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenc1_u [rcx+10*16]\r
- aesenc1_u [rcx+11*16]\r
- aesenclast1_u [rcx+12*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp192encsingle\r
-\r
-end_enc192:\r
-\r
- add rsp,16*16+8\r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global iEnc256\r
-iEnc256:\r
-\r
- linux_setup\r
- sub rsp,16*16+8\r
- \r
- mov eax,[rcx+32] ; numblocks\r
- mov rdx,[rcx]\r
- mov r8,[rcx+8]\r
- mov rcx,[rcx+16]\r
-\r
- sub r8,rdx \r
-\r
-\r
- test eax,eax\r
- jz end_enc256\r
-\r
- cmp eax,4\r
- jl lp256enc\r
-\r
- test rcx,0xf\r
- jz lp256enc4\r
- \r
- copy_round_keys rsp,rcx,0\r
- copy_round_keys rsp,rcx,1\r
- copy_round_keys rsp,rcx,2\r
- copy_round_keys rsp,rcx,3\r
- copy_round_keys rsp,rcx,4\r
- copy_round_keys rsp,rcx,5\r
- copy_round_keys rsp,rcx,6\r
- copy_round_keys rsp,rcx,7\r
- copy_round_keys rsp,rcx,8\r
- copy_round_keys rsp,rcx,9\r
- copy_round_keys rsp,rcx,10\r
- copy_round_keys rsp,rcx,11\r
- copy_round_keys rsp,rcx,12\r
- copy_round_keys rsp,rcx,13\r
- copy_round_keys rsp,rcx,14\r
- mov rcx,rsp \r
-\r
-\r
- align 16\r
- \r
-lp256enc4:\r
- test eax,eax\r
- jz end_enc256\r
-\r
- cmp eax,4\r
- jl lp256enc\r
-\r
-\r
- load_and_xor4 rdx,[rcx+0*16]\r
- add rdx, 16*4\r
- aesenc4 [rcx+1*16]\r
- aesenc4 [rcx+2*16]\r
- aesenc4 [rcx+3*16]\r
- aesenc4 [rcx+4*16]\r
- aesenc4 [rcx+5*16]\r
- aesenc4 [rcx+6*16]\r
- aesenc4 [rcx+7*16]\r
- aesenc4 [rcx+8*16]\r
- aesenc4 [rcx+9*16]\r
- aesenc4 [rcx+10*16]\r
- aesenc4 [rcx+11*16]\r
- aesenc4 [rcx+12*16]\r
- aesenc4 [rcx+13*16]\r
- aesenclast4 [rcx+14*16]\r
-\r
- store4 r8+rdx-16*4\r
- sub eax,4\r
- jmp lp256enc4\r
- \r
- align 16\r
-lp256enc:\r
-\r
- movdqu xmm0, [rdx]\r
- movdqu xmm4, [rcx+0*16]\r
- add rdx, 16\r
- pxor xmm0, xmm4\r
- aesenc1_u [rcx+1*16]\r
- aesenc1_u [rcx+2*16]\r
- aesenc1_u [rcx+3*16]\r
- aesenc1_u [rcx+4*16]\r
- aesenc1_u [rcx+5*16]\r
- aesenc1_u [rcx+6*16]\r
- aesenc1_u [rcx+7*16]\r
- aesenc1_u [rcx+8*16]\r
- aesenc1_u [rcx+9*16]\r
- aesenc1_u [rcx+10*16]\r
- aesenc1_u [rcx+11*16]\r
- aesenc1_u [rcx+12*16]\r
- aesenc1_u [rcx+13*16]\r
- aesenclast1_u [rcx+14*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [r8+rdx-16], xmm0\r
- dec eax\r
- jnz lp256enc\r
-\r
-end_enc256:\r
-\r
- add rsp,16*16+8\r
- ret\r
+++ /dev/null
-[bits 32]\r
-[CPU intelnop]\r
-\r
-; Copyright (c) 2010, Intel Corporation\r
-; All rights reserved.\r
-; \r
-; Redistribution and use in source and binary forms, with or without \r
-; modification, are permitted provided that the following conditions are met:\r
-; \r
-; * Redistributions of source code must retain the above copyright notice, \r
-; this list of conditions and the following disclaimer.\r
-; * Redistributions in binary form must reproduce the above copyright notice, \r
-; this list of conditions and the following disclaimer in the documentation \r
-; and/or other materials provided with the distribution.\r
-; * Neither the name of Intel Corporation nor the names of its contributors \r
-; may be used to endorse or promote products derived from this software \r
-; without specific prior written permission.\r
-; \r
-; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \r
-; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
-; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
-; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \r
-; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
-; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
-; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
-; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \r
-; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF \r
-; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-\r
-%macro inversekey 1\r
- movdqu xmm1,%1\r
- aesimc xmm0,xmm1\r
- movdqu %1,xmm0\r
-%endmacro\r
-\r
-\r
-%macro aesdec4 1\r
- movdqa xmm4,%1\r
-\r
- aesdec xmm0,xmm4\r
- aesdec xmm1,xmm4\r
- aesdec xmm2,xmm4\r
- aesdec xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-\r
-%macro aesdeclast4 1\r
- movdqa xmm4,%1\r
-\r
- aesdeclast xmm0,xmm4\r
- aesdeclast xmm1,xmm4\r
- aesdeclast xmm2,xmm4\r
- aesdeclast xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-\r
-%macro aesenc4 1\r
- movdqa xmm4,%1\r
-\r
- aesenc xmm0,xmm4\r
- aesenc xmm1,xmm4\r
- aesenc xmm2,xmm4\r
- aesenc xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-%macro aesenclast4 1\r
- movdqa xmm4,%1\r
-\r
- aesenclast xmm0,xmm4\r
- aesenclast xmm1,xmm4\r
- aesenclast xmm2,xmm4\r
- aesenclast xmm3,xmm4\r
-\r
-%endmacro\r
-\r
-\r
-%macro aesdeclast1 1\r
- aesdeclast xmm0,%1\r
-%endmacro\r
-\r
-%macro aesenclast1 1\r
- aesenclast xmm0,%1\r
-%endmacro\r
-\r
-%macro aesdec1 1\r
- aesdec xmm0,%1\r
-%endmacro\r
-\r
-;abab\r
-%macro aesenc1 1\r
- aesenc xmm0,%1\r
-%endmacro\r
-\r
-\r
-%macro aesdeclast1_u 1\r
- movdqu xmm4,%1\r
- aesdeclast xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesenclast1_u 1\r
- movdqu xmm4,%1\r
- aesenclast xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesdec1_u 1\r
- movdqu xmm4,%1\r
- aesdec xmm0,xmm4\r
-%endmacro\r
-\r
-%macro aesenc1_u 1\r
- movdqu xmm4,%1\r
- aesenc xmm0,xmm4\r
-%endmacro\r
-\r
-\r
-%macro load_and_xor4 2\r
- movdqa xmm4,%2\r
- movdqu xmm0,[%1 + 0*16]\r
- pxor xmm0,xmm4\r
- movdqu xmm1,[%1 + 1*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm2,[%1 + 2*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm3,[%1 + 3*16]\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-\r
-%macro load_and_inc4 1\r
- movdqa xmm4,%1\r
- movdqa xmm0,xmm5\r
- movdqa xmm1,xmm5\r
- paddq xmm1,[counter_add_one]\r
- movdqa xmm2,xmm5\r
- paddq xmm2,[counter_add_two]\r
- movdqa xmm3,xmm5\r
- paddq xmm3,[counter_add_three]\r
- pxor xmm0,xmm4\r
- paddq xmm5,[counter_add_four]\r
- pxor xmm1,xmm4\r
- pxor xmm2,xmm4\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-%macro xor_with_input4 1\r
- movdqu xmm4,[%1]\r
- pxor xmm0,xmm4\r
- movdqu xmm4,[%1+16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[%1+32]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[%1+48]\r
- pxor xmm3,xmm4\r
-%endmacro\r
-\r
-%macro store4 1\r
- movdqu [%1 + 0*16],xmm0\r
- movdqu [%1 + 1*16],xmm1\r
- movdqu [%1 + 2*16],xmm2\r
- movdqu [%1 + 3*16],xmm3\r
-%endmacro\r
-\r
-\r
-%macro copy_round_keys 3\r
- movdqu xmm4,[%2 + ((%3)*16)]\r
- movdqa [%1 + ((%3)*16)],xmm4\r
-%endmacro\r
-\r
-;abab\r
-%macro copy_round_keyx 3\r
- movdqu xmm4,[%2 + ((%3)*16)]\r
- movdqa %1,xmm4\r
-%endmacro\r
-\r
-\r
-\r
-%macro key_expansion_1_192 1\r
- ;; Assumes the xmm3 includes all zeros at this point. \r
- pshufd xmm2, xmm2, 11111111b \r
- shufps xmm3, xmm1, 00010000b \r
- pxor xmm1, xmm3 \r
- shufps xmm3, xmm1, 10001100b\r
- pxor xmm1, xmm3 \r
- pxor xmm1, xmm2 \r
- movdqu [edx+%1], xmm1 \r
-%endmacro\r
-\r
-; Calculate w10 and w11 using calculated w9 and known w4-w5\r
-%macro key_expansion_2_192 1 \r
- movdqa xmm5, xmm4\r
- pslldq xmm5, 4\r
- shufps xmm6, xmm1, 11110000b\r
- pxor xmm6, xmm5\r
- pxor xmm4, xmm6\r
- pshufd xmm7, xmm4, 00001110b \r
- movdqu [edx+%1], xmm7\r
-%endmacro\r
-\r
-\r
-\r
-\r
-\r
-section .data\r
-align 16\r
-shuffle_mask:\r
-DD 0FFFFFFFFh\r
-DD 03020100h\r
-DD 07060504h\r
-DD 0B0A0908h\r
-\r
-align 16\r
-counter_add_one:\r
-DD 1\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_two:\r
-DD 2\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_three:\r
-DD 3\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-counter_add_four:\r
-DD 4\r
-DD 0\r
-DD 0\r
-DD 0\r
-\r
-\r
-section .text\r
-\r
-\r
-\r
-align 16\r
-key_expansion256:\r
-\r
- pshufd xmm2, xmm2, 011111111b\r
-\r
- movdqu xmm4, xmm1\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pxor xmm1, xmm2\r
-\r
- movdqu [edx], xmm1\r
- add edx, 0x10\r
- \r
- aeskeygenassist xmm4, xmm1, 0\r
- pshufd xmm2, xmm4, 010101010b\r
-\r
- movdqu xmm4, xmm3\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm3, xmm4\r
- pxor xmm3, xmm2\r
-\r
- movdqu [edx], xmm3\r
- add edx, 0x10\r
-\r
- ret\r
-\r
-\r
-\r
-align 16\r
-key_expansion128: \r
- pshufd xmm2, xmm2, 0xFF;\r
- movdqu xmm3, xmm1\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pshufb xmm3, xmm5\r
- pxor xmm1, xmm3\r
- pxor xmm1, xmm2\r
-\r
- ; storing the result in the key schedule array\r
- movdqu [edx], xmm1\r
- add edx, 0x10 \r
- ret\r
-\r
-\r
-\r
-align 16\r
-global _iEncExpandKey128\r
-_iEncExpandKey128:\r
-\r
- mov ecx,[esp-4+8] ;input\r
- mov edx,[esp-4+12] ;ctx\r
-\r
- movdqu xmm1, [ecx] ; loading the key\r
-\r
- movdqu [edx], xmm1\r
-\r
- movdqa xmm5, [shuffle_mask]\r
-\r
- add edx,16\r
-\r
- aeskeygenassist xmm2, xmm1, 0x1 ; Generating round key 1\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x2 ; Generating round key 2\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x4 ; Generating round key 3\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x8 ; Generating round key 4\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x10 ; Generating round key 5\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x20 ; Generating round key 6\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x40 ; Generating round key 7\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x80 ; Generating round key 8\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x1b ; Generating round key 9\r
- call key_expansion128\r
- aeskeygenassist xmm2, xmm1, 0x36 ; Generating round key 10\r
- call key_expansion128\r
-\r
- ret\r
-\r
-\r
-align 16\r
-global _iEncExpandKey192\r
-_iEncExpandKey192:\r
-\r
- mov ecx,[esp-4+8] ;input\r
- mov edx,[esp-4+12] ;ctx\r
-\r
- movq xmm7, [ecx+16] ; loading the AES key\r
- movq [edx+16], xmm7 ; Storing key in memory where all key expansion \r
- pshufd xmm4, xmm7, 01001111b\r
- movdqu xmm1, [ecx] ; loading the AES key\r
- movdqu [edx], xmm1 ; Storing key in memory where all key expansion \r
- \r
- pxor xmm3, xmm3 ; Set xmm3 to be all zeros. Required for the key_expansion. \r
- pxor xmm6, xmm6 ; Set xmm3 to be all zeros. Required for the key_expansion. \r
-\r
- aeskeygenassist xmm2, xmm4, 0x1 ; Complete round key 1 and generate round key 2 \r
- key_expansion_1_192 24\r
- key_expansion_2_192 40 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x2 ; Generate round key 3 and part of round key 4\r
- key_expansion_1_192 48\r
- key_expansion_2_192 64 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x4 ; Complete round key 4 and generate round key 5\r
- key_expansion_1_192 72\r
- key_expansion_2_192 88\r
- \r
- aeskeygenassist xmm2, xmm4, 0x8 ; Generate round key 6 and part of round key 7\r
- key_expansion_1_192 96\r
- key_expansion_2_192 112\r
- \r
- aeskeygenassist xmm2, xmm4, 0x10 ; Complete round key 7 and generate round key 8 \r
- key_expansion_1_192 120\r
- key_expansion_2_192 136 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x20 ; Generate round key 9 and part of round key 10\r
- key_expansion_1_192 144\r
- key_expansion_2_192 160 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x40 ; Complete round key 10 and generate round key 11\r
- key_expansion_1_192 168\r
- key_expansion_2_192 184 \r
-\r
- aeskeygenassist xmm2, xmm4, 0x80 ; Generate round key 12\r
- key_expansion_1_192 192\r
-\r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDecExpandKey128\r
-_iDecExpandKey128:\r
- push DWORD [esp+8]\r
- push DWORD [esp+8]\r
- \r
- call _iEncExpandKey128\r
- add esp,8\r
-\r
- mov edx,[esp-4+12] ;ctx\r
- \r
- inversekey [edx + 1*16]\r
- inversekey [edx + 2*16]\r
- inversekey [edx + 3*16]\r
- inversekey [edx + 4*16]\r
- inversekey [edx + 5*16]\r
- inversekey [edx + 6*16]\r
- inversekey [edx + 7*16]\r
- inversekey [edx + 8*16]\r
- inversekey [edx + 9*16]\r
-\r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDecExpandKey192\r
-_iDecExpandKey192:\r
- push DWORD [esp+8]\r
- push DWORD [esp+8]\r
- \r
- call _iEncExpandKey192\r
- add esp,8\r
-\r
- mov edx,[esp-4+12] ;ctx\r
- \r
- inversekey [edx + 1*16]\r
- inversekey [edx + 2*16]\r
- inversekey [edx + 3*16]\r
- inversekey [edx + 4*16]\r
- inversekey [edx + 5*16]\r
- inversekey [edx + 6*16]\r
- inversekey [edx + 7*16]\r
- inversekey [edx + 8*16]\r
- inversekey [edx + 9*16]\r
- inversekey [edx + 10*16]\r
- inversekey [edx + 11*16]\r
-\r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDecExpandKey256\r
-_iDecExpandKey256:\r
- push DWORD [esp+8]\r
- push DWORD [esp+8]\r
- \r
- call _iEncExpandKey256\r
- add esp, 8\r
-\r
- mov edx, [esp-4+12] ;expanded key\r
- \r
- inversekey [edx + 1*16]\r
- inversekey [edx + 2*16]\r
- inversekey [edx + 3*16]\r
- inversekey [edx + 4*16]\r
- inversekey [edx + 5*16]\r
- inversekey [edx + 6*16]\r
- inversekey [edx + 7*16]\r
- inversekey [edx + 8*16]\r
- inversekey [edx + 9*16]\r
- inversekey [edx + 10*16]\r
- inversekey [edx + 11*16]\r
- inversekey [edx + 12*16]\r
- inversekey [edx + 13*16]\r
-\r
- ret\r
- \r
-\r
- \r
- \r
-align 16\r
-global _iEncExpandKey256\r
-_iEncExpandKey256:\r
- mov ecx, [esp-4+8] ;input\r
- mov edx, [esp-4+12] ;expanded key\r
-\r
-\r
- movdqu xmm1, [ecx] ; loading the key\r
- movdqu xmm3, [ecx+16]\r
- movdqu [edx], xmm1 ; Storing key in memory where all key schedule will be stored\r
- movdqu [edx+16], xmm3 \r
- \r
- add edx,32\r
-\r
- movdqa xmm5, [shuffle_mask] ; this mask is used by key_expansion\r
-\r
- aeskeygenassist xmm2, xmm3, 0x1 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x2 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x4 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x8 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x10 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x20 ; \r
- call key_expansion256\r
- aeskeygenassist xmm2, xmm3, 0x40 ; \r
-; call key_expansion256 \r
-\r
- pshufd xmm2, xmm2, 011111111b\r
-\r
- movdqu xmm4, xmm1\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pshufb xmm4, xmm5\r
- pxor xmm1, xmm4\r
- pxor xmm1, xmm2\r
-\r
- movdqu [edx], xmm1\r
-\r
-\r
- ret\r
- \r
- \r
- \r
- \r
- \r
-\r
-align 16\r
-global _iDec128\r
-_iDec128:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
-\r
- sub edi,esi\r
- \r
- test eax,eax\r
- jz end_dec128\r
-\r
- cmp eax,4\r
- jl lp128decsingle\r
-\r
- test ecx,0xf\r
- jz lp128decfour\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- mov ecx,esp \r
- \r
-\r
-align 16\r
-lp128decfour:\r
- \r
- test eax,eax\r
- jz end_dec128\r
-\r
- cmp eax,4\r
- jl lp128decsingle\r
-\r
- load_and_xor4 esi, [ecx+10*16]\r
- add esi,16*4\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
- \r
- sub eax,4\r
- store4 esi+edi-(16*4)\r
- jmp lp128decfour\r
-\r
-\r
- align 16\r
-lp128decsingle:\r
-\r
- movdqu xmm0, [esi]\r
- movdqu xmm4,[ecx+10*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
-\r
- add esi, 16\r
- movdqu [edi+esi - 16], xmm0\r
- dec eax\r
- jnz lp128decsingle\r
-\r
-end_dec128:\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
-\r
-\r
-\r
-align 16\r
-global _iDec128_CBC\r
-_iDec128_CBC:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- sub esp,16*16\r
- and esp,0xfffffff0\r
- \r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;iv\r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_dec128_CBC\r
-\r
- cmp eax,4\r
- jl lp128decsingle_CBC\r
-\r
- test ecx,0xf\r
- jz lp128decfour_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- mov ecx,esp \r
-\r
-\r
-align 16\r
-lp128decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec128_CBC\r
-\r
- cmp eax,4\r
- jl lp128decsingle_CBC\r
-\r
- load_and_xor4 esi, [ecx+10*16]\r
- add esi,16*4\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqu xmm4,[esi- 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[esi- 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[esi- 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[esi- 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 esi+edi-(16*4)\r
- jmp lp128decfour_CBC\r
-\r
-\r
- align 16\r
-lp128decsingle_CBC:\r
-\r
- movdqu xmm0, [esi]\r
- movdqa xmm1,xmm0\r
- movdqu xmm4,[ecx+10*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- \r
- add esi, 16\r
- movdqu [edi+esi - 16], xmm0\r
- dec eax\r
- jnz lp128decsingle_CBC\r
-\r
-end_dec128_CBC:\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last iv for chaining\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDec192\r
-_iDec192:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_dec192\r
-\r
- cmp eax,4\r
- jl lp192decsingle\r
-\r
- test ecx,0xf\r
- jz lp192decfour\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- mov ecx,esp \r
-\r
-\r
-align 16\r
-lp192decfour:\r
- \r
- test eax,eax\r
- jz end_dec192\r
-\r
- cmp eax,4\r
- jl lp192decsingle\r
-\r
- load_and_xor4 esi, [ecx+12*16]\r
- add esi,16*4\r
- aesdec4 [ecx+11*16]\r
- aesdec4 [ecx+10*16]\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
- \r
- sub eax,4\r
- store4 esi+edi-(16*4)\r
- jmp lp192decfour\r
-\r
-\r
- align 16\r
-lp192decsingle:\r
-\r
- movdqu xmm0, [esi]\r
- movdqu xmm4,[ecx+12*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [ecx+11*16]\r
- aesdec1_u [ecx+10*16]\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
-\r
- add esi, 16\r
- movdqu [edi+esi - 16], xmm0\r
- dec eax\r
- jnz lp192decsingle\r
-\r
-end_dec192:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
-\r
-\r
-align 16\r
-global _iDec192_CBC\r
-_iDec192_CBC:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;iv\r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_dec192_CBC\r
-\r
- cmp eax,4\r
- jl lp192decsingle_CBC\r
-\r
- test ecx,0xf\r
- jz lp192decfour_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- mov ecx,esp \r
-\r
-align 16\r
-lp192decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec192_CBC\r
-\r
- cmp eax,4\r
- jl lp192decsingle_CBC\r
-\r
- load_and_xor4 esi, [ecx+12*16]\r
- add esi,16*4\r
- aesdec4 [ecx+11*16]\r
- aesdec4 [ecx+10*16]\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqu xmm4,[esi- 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[esi- 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[esi- 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[esi- 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 esi+edi-(16*4)\r
- jmp lp192decfour_CBC\r
-\r
-\r
- align 16\r
-lp192decsingle_CBC:\r
-\r
- movdqu xmm0, [esi]\r
- movdqu xmm4,[ecx+12*16]\r
- movdqa xmm1,xmm0\r
- pxor xmm0, xmm4\r
- aesdec1_u [ecx+11*16]\r
- aesdec1_u [ecx+10*16]\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- \r
- add esi, 16\r
- movdqu [edi+esi - 16], xmm0\r
- dec eax\r
- jnz lp192decsingle_CBC\r
-\r
-end_dec192_CBC:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8]\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last iv for chaining\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDec256\r
-_iDec256:\r
- mov ecx, [esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
-\r
- test eax,eax\r
- jz end_dec256\r
- \r
- cmp eax,4\r
- jl lp256dec\r
-\r
- test ecx,0xf\r
- jz lp256dec4\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- copy_round_keys esp,ecx,13\r
- copy_round_keys esp,ecx,14\r
- mov ecx,esp \r
- \r
- align 16\r
-lp256dec4:\r
- test eax,eax\r
- jz end_dec256\r
- \r
- cmp eax,4\r
- jl lp256dec\r
- \r
- load_and_xor4 esi,[ecx+14*16]\r
- add esi, 4*16\r
- aesdec4 [ecx+13*16]\r
- aesdec4 [ecx+12*16]\r
- aesdec4 [ecx+11*16]\r
- aesdec4 [ecx+10*16]\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
-\r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lp256dec4 \r
- \r
- align 16\r
-lp256dec:\r
-\r
- movdqu xmm0, [esi]\r
- movdqu xmm4,[ecx+14*16]\r
- add esi, 16\r
- pxor xmm0, xmm4 ; Round 0 (only xor)\r
- aesdec1_u [ecx+13*16]\r
- aesdec1_u [ecx+12*16]\r
- aesdec1_u [ecx+11*16]\r
- aesdec1_u [ecx+10*16]\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp256dec\r
-\r
-end_dec256:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iDec256_CBC\r
-_iDec256_CBC:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;iv\r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_dec256_CBC\r
-\r
- cmp eax,4\r
- jl lp256decsingle_CBC\r
-\r
- test ecx,0xf\r
- jz lp256decfour_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- copy_round_keys esp,ecx,13\r
- copy_round_keys esp,ecx,14\r
- mov ecx,esp \r
-\r
-align 16\r
-lp256decfour_CBC:\r
- \r
- test eax,eax\r
- jz end_dec256_CBC\r
-\r
- cmp eax,4\r
- jl lp256decsingle_CBC\r
-\r
- load_and_xor4 esi, [ecx+14*16]\r
- add esi,16*4\r
- aesdec4 [ecx+13*16]\r
- aesdec4 [ecx+12*16]\r
- aesdec4 [ecx+11*16]\r
- aesdec4 [ecx+10*16]\r
- aesdec4 [ecx+9*16]\r
- aesdec4 [ecx+8*16]\r
- aesdec4 [ecx+7*16]\r
- aesdec4 [ecx+6*16]\r
- aesdec4 [ecx+5*16]\r
- aesdec4 [ecx+4*16]\r
- aesdec4 [ecx+3*16]\r
- aesdec4 [ecx+2*16]\r
- aesdec4 [ecx+1*16]\r
- aesdeclast4 [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqu xmm4,[esi- 16*4 + 0*16]\r
- pxor xmm1,xmm4\r
- movdqu xmm4,[esi- 16*4 + 1*16]\r
- pxor xmm2,xmm4\r
- movdqu xmm4,[esi- 16*4 + 2*16]\r
- pxor xmm3,xmm4\r
- movdqu xmm5,[esi- 16*4 + 3*16]\r
- \r
- sub eax,4\r
- store4 esi+edi-(16*4)\r
- jmp lp256decfour_CBC\r
-\r
-\r
- align 16\r
-lp256decsingle_CBC:\r
-\r
- movdqu xmm0, [esi]\r
- movdqa xmm1,xmm0\r
- movdqu xmm4, [ecx+14*16]\r
- pxor xmm0, xmm4\r
- aesdec1_u [ecx+13*16]\r
- aesdec1_u [ecx+12*16]\r
- aesdec1_u [ecx+11*16]\r
- aesdec1_u [ecx+10*16]\r
- aesdec1_u [ecx+9*16]\r
- aesdec1_u [ecx+8*16]\r
- aesdec1_u [ecx+7*16]\r
- aesdec1_u [ecx+6*16]\r
- aesdec1_u [ecx+5*16]\r
- aesdec1_u [ecx+4*16]\r
- aesdec1_u [ecx+3*16]\r
- aesdec1_u [ecx+2*16]\r
- aesdec1_u [ecx+1*16]\r
- aesdeclast1_u [ecx+0*16]\r
- \r
- pxor xmm0,xmm5\r
- movdqa xmm5,xmm1\r
- \r
- add esi, 16\r
- movdqu [edi+esi - 16], xmm0\r
- dec eax\r
- jnz lp256decsingle_CBC\r
-\r
-end_dec256_CBC:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last iv for chaining\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iEnc128\r
-_iEnc128:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_enc128\r
- \r
- cmp eax,4\r
- jl lp128encsingle\r
-\r
- test ecx,0xf\r
- jz lpenc128four\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- mov ecx,esp \r
-\r
-\r
- align 16 \r
- \r
-lpenc128four:\r
- \r
- test eax,eax\r
- jz end_enc128\r
- \r
- cmp eax,4\r
- jl lp128encsingle\r
-\r
- load_and_xor4 esi,[ecx+0*16]\r
- add esi,4*16\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenclast4 [ecx+10*16]\r
- \r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lpenc128four\r
- \r
- align 16\r
-lp128encsingle:\r
-\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16] \r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenclast1_u [ecx+10*16]\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp128encsingle\r
-\r
-end_enc128:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
-\r
-\r
-align 16\r
-global _iEnc128_CTR\r
-_iEnc128_CTR:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;initial counter\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_encctr128\r
- \r
- cmp eax,4\r
- jl lp128encctrsingle\r
-\r
- test ecx,0xf\r
- jz lpencctr128four\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- mov ecx,esp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr128four:\r
- \r
- test eax,eax\r
- jz end_encctr128\r
- \r
- cmp eax,4\r
- jl lp128encsingle\r
-\r
- load_and_inc4 [ecx+0*16]\r
- add esi,4*16\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenclast4 [ecx+10*16]\r
- xor_with_input4 esi-(4*16)\r
- \r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lpencctr128four\r
- \r
- align 16\r
-lp128encctrsingle:\r
-\r
- movdqa xmm0,xmm5\r
- paddq xmm5,[counter_add_one]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16] \r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenclast1_u [ecx+10*16]\r
- movdqu xmm4, [esi-16]\r
- pxor xmm0,xmm4\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp128encctrsingle\r
-\r
-end_encctr128:\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last counter for chaining\r
- \r
- ret\r
-\r
-\r
-align 16\r
-global _iEnc192_CTR\r
-_iEnc192_CTR:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;initial counter\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_encctr192\r
- \r
- cmp eax,4\r
- jl lp192encctrsingle\r
-\r
- test ecx,0xf\r
- jz lpencctr128four\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- mov ecx,esp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr192four:\r
- \r
- test eax,eax\r
- jz end_encctr192\r
- \r
- cmp eax,4\r
- jl lp192encsingle\r
-\r
- load_and_inc4 [ecx+0*16]\r
- add esi,4*16\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenc4 [ecx+10*16]\r
- aesenc4 [ecx+11*16]\r
- aesenclast4 [ecx+12*16]\r
- xor_with_input4 esi-(4*16)\r
- \r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lpencctr192four\r
- \r
- align 16\r
-lp192encctrsingle:\r
-\r
- movdqa xmm0,xmm5\r
- paddq xmm5,[counter_add_one]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16] \r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenc1_u [ecx+10*16]\r
- aesenc1_u [ecx+11*16]\r
- aesenclast1_u [ecx+12*16]\r
- movdqu xmm4, [esi-16]\r
- pxor xmm0,xmm4\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp192encctrsingle\r
-\r
-end_encctr192:\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last counter for chaining\r
- \r
- ret\r
-\r
-\r
-align 16\r
-global _iEnc256_CTR\r
-_iEnc256_CTR:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm5,[eax] ;initial counter\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_encctr256\r
- \r
- cmp eax,4\r
- jl lp256encctrsingle\r
-\r
- test ecx,0xf\r
- jz lpencctr128four\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- copy_round_keys esp,ecx,13\r
- copy_round_keys esp,ecx,14\r
- mov ecx,esp \r
-\r
-\r
- align 16 \r
- \r
-lpencctr256four:\r
- \r
- test eax,eax\r
- jz end_encctr256\r
- \r
- cmp eax,4\r
- jl lp256encctrsingle\r
-\r
- load_and_inc4 [ecx+0*16]\r
- add esi,4*16\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenc4 [ecx+10*16]\r
- aesenc4 [ecx+11*16]\r
- aesenc4 [ecx+12*16]\r
- aesenc4 [ecx+13*16]\r
- aesenclast4 [ecx+14*16]\r
- xor_with_input4 esi-(4*16)\r
- \r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lpencctr256four\r
- \r
- align 16\r
- \r
-lp256encctrsingle:\r
-\r
- movdqa xmm0,xmm5\r
- paddq xmm5,[counter_add_one]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16] \r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenc1_u [ecx+10*16]\r
- aesenc1_u [ecx+11*16]\r
- aesenc1_u [ecx+12*16]\r
- aesenc1_u [ecx+13*16]\r
- aesenclast1_u [ecx+14*16]\r
- movdqu xmm4, [esi-16]\r
- pxor xmm0,xmm4\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp256encctrsingle\r
-\r
-end_encctr256:\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
-\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm5 ; store last counter for chaining\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iEnc128_CBC\r
-_iEnc128_CBC:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm1,[eax] ;iv \r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- sub edi,esi\r
-\r
- test ecx,0xf\r
- jz lp128encsingle_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- mov ecx,esp \r
-\r
- align 16 \r
- \r
-lp128encsingle_CBC:\r
-\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- pxor xmm0, xmm1\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1 [ecx+1*16]\r
- aesenc1 [ecx+2*16]\r
- aesenc1 [ecx+3*16]\r
- aesenc1 [ecx+4*16] \r
- aesenc1 [ecx+5*16]\r
- aesenc1 [ecx+6*16]\r
- aesenc1 [ecx+7*16]\r
- aesenc1 [ecx+8*16]\r
- aesenc1 [ecx+9*16]\r
- aesenclast1 [ecx+10*16]\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- movdqa xmm1,xmm0\r
- dec eax\r
- jnz lp128encsingle_CBC\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm1 ; store last iv for chaining\r
- \r
- ret\r
-\r
-\r
-align 16\r
-global _iEnc192_CBC\r
-_iEnc192_CBC:\r
- mov ecx,[esp-4+8] ; first arg\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm1,[eax] ;iv \r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- sub edi,esi\r
-\r
- test ecx,0xf\r
- jz lp192encsingle_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- mov ecx,esp \r
-\r
- align 16 \r
- \r
-lp192encsingle_CBC:\r
-\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- pxor xmm0, xmm1\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1 [ecx+1*16]\r
- aesenc1 [ecx+2*16]\r
- aesenc1 [ecx+3*16]\r
- aesenc1 [ecx+4*16] \r
- aesenc1 [ecx+5*16]\r
- aesenc1 [ecx+6*16]\r
- aesenc1 [ecx+7*16]\r
- aesenc1 [ecx+8*16]\r
- aesenc1 [ecx+9*16]\r
- aesenc1 [ecx+10*16]\r
- aesenc1 [ecx+11*16]\r
- aesenclast1 [ecx+12*16]\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- movdqa xmm1,xmm0\r
- dec eax\r
- jnz lp192encsingle_CBC\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- mov ecx,[esp-4+8] ; first arg\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm1 ; store last iv for chaining\r
- \r
- ret\r
-\r
-align 16\r
-global _iEnc256_CBC\r
-_iEnc256_CBC:\r
- mov ecx,[esp-4+8] ; first arg\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+12]\r
- movdqu xmm1,[eax] ;iv \r
- \r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- sub edi,esi\r
-\r
- test ecx,0xf\r
- jz lp256encsingle_CBC\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- copy_round_keys esp,ecx,13\r
- copy_round_keys esp,ecx,14\r
- mov ecx,esp \r
-\r
- align 16 \r
- \r
-lp256encsingle_CBC:\r
-\r
-;abab\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- pxor xmm0, xmm1\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1 [ecx+1*16]\r
- aesenc1 [ecx+2*16]\r
- aesenc1 [ecx+3*16]\r
- aesenc1 [ecx+4*16] \r
- aesenc1 [ecx+5*16]\r
- aesenc1 [ecx+6*16]\r
- aesenc1 [ecx+7*16]\r
- aesenc1 [ecx+8*16]\r
- aesenc1 [ecx+9*16]\r
- aesenc1 [ecx+10*16]\r
- aesenc1 [ecx+11*16]\r
- aesenc1 [ecx+12*16]\r
- aesenc1 [ecx+13*16]\r
- aesenclast1 [ecx+14*16]\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- movdqa xmm1,xmm0\r
- dec eax\r
- jnz lp256encsingle_CBC\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- mov ecx,[esp-4+8]\r
- mov ecx,[ecx+12]\r
- movdqu [ecx],xmm1 ; store last iv for chaining\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iEnc192\r
-_iEnc192:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi\r
-\r
- test eax,eax\r
- jz end_enc192\r
- \r
- cmp eax,4\r
- jl lp192encsingle\r
-\r
- test ecx,0xf\r
- jz lpenc192four\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- mov ecx,esp \r
-\r
- align 16 \r
- \r
-lpenc192four:\r
- \r
- test eax,eax\r
- jz end_enc192\r
- \r
- cmp eax,4\r
- jl lp192encsingle\r
-\r
- load_and_xor4 esi,[ecx+0*16]\r
- add esi,4*16\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenc4 [ecx+10*16]\r
- aesenc4 [ecx+11*16]\r
- aesenclast4 [ecx+12*16]\r
- \r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lpenc192four\r
- \r
- align 16\r
-lp192encsingle:\r
-\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16] \r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenc1_u [ecx+10*16]\r
- aesenc1_u [ecx+11*16]\r
- aesenclast1_u [ecx+12*16]\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp192encsingle\r
-\r
-end_enc192:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
-\r
-\r
-\r
-\r
-align 16\r
-global _iEnc256\r
-_iEnc256:\r
- mov ecx,[esp-4+8]\r
- \r
- push esi\r
- push edi\r
- push ebp\r
- mov ebp,esp\r
- \r
- sub esp,16*16\r
- and esp,0xfffffff0\r
-\r
- mov eax,[ecx+16] ; numblocks\r
- mov esi,[ecx]\r
- mov edi,[ecx+4]\r
- mov ecx,[ecx+8]\r
- \r
- sub edi,esi \r
-\r
- test eax,eax\r
- jz end_enc256\r
-\r
- cmp eax,4\r
- jl lp256enc\r
-\r
- test ecx,0xf\r
- jz lp256enc4\r
- \r
- copy_round_keys esp,ecx,0\r
- copy_round_keys esp,ecx,1\r
- copy_round_keys esp,ecx,2\r
- copy_round_keys esp,ecx,3\r
- copy_round_keys esp,ecx,4\r
- copy_round_keys esp,ecx,5\r
- copy_round_keys esp,ecx,6\r
- copy_round_keys esp,ecx,7\r
- copy_round_keys esp,ecx,8\r
- copy_round_keys esp,ecx,9\r
- copy_round_keys esp,ecx,10\r
- copy_round_keys esp,ecx,11\r
- copy_round_keys esp,ecx,12\r
- copy_round_keys esp,ecx,13\r
- copy_round_keys esp,ecx,14\r
- mov ecx,esp \r
-\r
-\r
-\r
- align 16\r
- \r
-lp256enc4:\r
- test eax,eax\r
- jz end_enc256\r
-\r
- cmp eax,4\r
- jl lp256enc\r
-\r
-\r
- load_and_xor4 esi,[ecx+0*16]\r
- add esi, 16*4\r
- aesenc4 [ecx+1*16]\r
- aesenc4 [ecx+2*16]\r
- aesenc4 [ecx+3*16]\r
- aesenc4 [ecx+4*16]\r
- aesenc4 [ecx+5*16]\r
- aesenc4 [ecx+6*16]\r
- aesenc4 [ecx+7*16]\r
- aesenc4 [ecx+8*16]\r
- aesenc4 [ecx+9*16]\r
- aesenc4 [ecx+10*16]\r
- aesenc4 [ecx+11*16]\r
- aesenc4 [ecx+12*16]\r
- aesenc4 [ecx+13*16]\r
- aesenclast4 [ecx+14*16]\r
-\r
- store4 esi+edi-16*4\r
- sub eax,4\r
- jmp lp256enc4\r
- \r
- align 16\r
-lp256enc:\r
-\r
- movdqu xmm0, [esi]\r
- add esi, 16\r
- movdqu xmm4,[ecx+0*16]\r
- pxor xmm0, xmm4\r
- aesenc1_u [ecx+1*16]\r
- aesenc1_u [ecx+2*16]\r
- aesenc1_u [ecx+3*16]\r
- aesenc1_u [ecx+4*16]\r
- aesenc1_u [ecx+5*16]\r
- aesenc1_u [ecx+6*16]\r
- aesenc1_u [ecx+7*16]\r
- aesenc1_u [ecx+8*16]\r
- aesenc1_u [ecx+9*16]\r
- aesenc1_u [ecx+10*16]\r
- aesenc1_u [ecx+11*16]\r
- aesenc1_u [ecx+12*16]\r
- aesenc1_u [ecx+13*16]\r
- aesenclast1_u [ecx+14*16]\r
-\r
- ; Store output encrypted data into CIPHERTEXT array\r
- movdqu [esi+edi-16], xmm0\r
- dec eax\r
- jnz lp256enc\r
-\r
-end_enc256:\r
-\r
-\r
- mov esp,ebp\r
- pop ebp\r
- pop edi\r
- pop esi\r
- \r
- ret\r
+++ /dev/null
-/* \r
- * Copyright (c) 2010, Intel Corporation\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without \r
- * modification, are permitted provided that the following conditions are met:\r
- * \r
- * * Redistributions of source code must retain the above copyright notice, \r
- * this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright notice, \r
- * this list of conditions and the following disclaimer in the documentation \r
- * and/or other materials provided with the distribution.\r
- * * Neither the name of Intel Corporation nor the names of its contributors \r
- * may be used to endorse or promote products derived from this software \r
- * without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \r
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \r
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \r
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF \r
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
-*/\r
-\r
-#ifndef _INTEL_AES_ASM_INTERFACE_H__\r
-#define _INTEL_AES_ASM_INTERFACE_H__\r
-\r
-\r
-#include "iaesni.h"\r
-\r
-\r
-\r
-//structure to pass aes processing data to asm level functions\r
-typedef struct _sAesData\r
-{\r
- _AES_IN UCHAR *in_block;\r
- _AES_OUT UCHAR *out_block;\r
- _AES_IN UCHAR *expanded_key; \r
- _AES_INOUT UCHAR *iv; // for CBC mode\r
- _AES_IN size_t num_blocks;\r
-} sAesData;\r
-\r
-#if (__cplusplus)\r
-extern "C"\r
-{\r
-#endif\r
-#if 0\r
-#define MYSTDCALL __stdcall\r
-#else\r
-#define MYSTDCALL \r
-#endif\r
-\r
-#ifdef __linux__\r
-#ifndef __LP64__\r
-#define iEncExpandKey256 _iEncExpandKey256\r
-#define iEncExpandKey192 _iEncExpandKey192\r
-#define iEncExpandKey128 _iEncExpandKey128\r
-#define iDecExpandKey256 _iDecExpandKey256\r
-#define iDecExpandKey192 _iDecExpandKey192\r
-#define iDecExpandKey128 _iDecExpandKey128\r
-#define iEnc128 _iEnc128\r
-#define iDec128 _iDec128\r
-#define iEnc256 _iEnc256\r
-#define iDec256 _iDec256\r
-#define iEnc192 _iEnc192\r
-#define iDec192 _iDec192\r
-#define iEnc128_CBC _iEnc128_CBC\r
-#define iDec128_CBC _iDec128_CBC\r
-#define iEnc256_CBC _iEnc256_CBC\r
-#define iDec256_CBC _iDec256_CBC\r
-#define iEnc192_CBC _iEnc192_CBC\r
-#define iDec192_CBC _iDec192_CBC\r
-#define iEnc128_CTR _iEnc128_CTR\r
-#define iEnc192_CTR _iEnc192_CTR\r
-#define iEnc256_CTR _iEnc256_CTR\r
-#define do_rdtsc _do_rdtsc\r
-#endif\r
-#endif\r
- // prepearing the different key rounds, for enc/dec in asm\r
- // expnaded key should be 16-byte aligned\r
- // expanded key should have enough space to hold all key rounds (16 bytes per round) - 256 bytes would cover all cases (AES256 has 14 rounds + 1 xor)\r
- void MYSTDCALL iEncExpandKey256(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
- void MYSTDCALL iEncExpandKey192(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
- void MYSTDCALL iEncExpandKey128(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
-\r
- void MYSTDCALL iDecExpandKey256(UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
- void MYSTDCALL iDecExpandKey192(UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
- void MYSTDCALL iDecExpandKey128(UCHAR *key, _AES_OUT UCHAR *expanded_key);\r
-\r
-\r
- //enc/dec asm functions\r
- void MYSTDCALL iEnc128(sAesData *data);\r
- void MYSTDCALL iDec128(sAesData *data);\r
- void MYSTDCALL iEnc256(sAesData *data);\r
- void MYSTDCALL iDec256(sAesData *data);\r
- void MYSTDCALL iEnc192(sAesData *data);\r
- void MYSTDCALL iDec192(sAesData *data);\r
-\r
- void MYSTDCALL iEnc128_CBC(sAesData *data);\r
- void MYSTDCALL iDec128_CBC(sAesData *data);\r
- void MYSTDCALL iEnc256_CBC(sAesData *data);\r
- void MYSTDCALL iDec256_CBC(sAesData *data);\r
- void MYSTDCALL iEnc192_CBC(sAesData *data);\r
- void MYSTDCALL iDec192_CBC(sAesData *data);\r
-\r
-\r
- void MYSTDCALL iEnc128_CTR(sAesData *data);\r
- void MYSTDCALL iEnc256_CTR(sAesData *data);\r
- void MYSTDCALL iEnc192_CTR(sAesData *data);\r
-\r
- // rdtsc function\r
- unsigned long long do_rdtsc(void);\r
-\r
-\r
-#if (__cplusplus)\r
-}\r
-#endif\r
-\r
-\r
-#endif\r
-\r
+++ /dev/null
-/* \r
- * Copyright (c) 2010, Intel Corporation\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without \r
- * modification, are permitted provided that the following conditions are met:\r
- * \r
- * * Redistributions of source code must retain the above copyright notice, \r
- * this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright notice, \r
- * this list of conditions and the following disclaimer in the documentation \r
- * and/or other materials provided with the distribution.\r
- * * Neither the name of Intel Corporation nor the names of its contributors \r
- * may be used to endorse or promote products derived from this software \r
- * without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \r
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \r
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \r
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF \r
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
-*/\r
-\r
-\r
-#ifndef _IAESNI_H__\r
-#define _IAESNI_H__\r
-\r
-#include <stdlib.h>\r
-\r
-#define AES_INSTRCTIONS_CPUID_BIT (1<<25)\r
-\r
-//indicates input param\r
-#define _AES_IN \r
-\r
-//indicates output param\r
-#define _AES_OUT\r
-\r
-//indicates input/output param - based on context\r
-#define _AES_INOUT\r
-\r
-typedef unsigned char UCHAR;\r
-\r
-\r
-#ifndef bool\r
-#define bool BOOL\r
-#endif\r
-//test if the processor actually supports the above functions\r
-//executing one the functions below without processor support will cause UD fault\r
-//bool check_for_aes_instructions(void);\r
-#if (__cplusplus)\r
-extern "C" {\r
-#endif\r
-int check_for_aes_instructions(void);\r
-\r
-#define ROUND_KEYS_UNALIGNED_TESTING\r
-\r
-#ifdef __linux__\r
-\r
-#ifdef ROUND_KEYS_UNALIGNED_TESTING\r
-\r
-#define DEFINE_ROUND_KEYS \\r
- UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16]; \\r
- UCHAR *expandedKey = _expandedKey + 4; \\r
-\r
-\r
-#else\r
-\r
-\r
-\r
-#define DEFINE_ROUND_KEYS \\r
- UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16]; \\r
- UCHAR *expandedKey = _expandedKey; \\r
-\r
-#endif\r
-\r
-#else // if not __linux__\r
-\r
-#ifdef ROUND_KEYS_UNALIGNED_TESTING\r
-\r
-#define DEFINE_ROUND_KEYS \\r
- __declspec(align(16)) UCHAR _expandedKey[16*16]; \\r
- UCHAR *expandedKey = _expandedKey + 4; \\r
-\r
-\r
-#else\r
-\r
-\r
-\r
-#define DEFINE_ROUND_KEYS \\r
- __declspec(align(16)) UCHAR _expandedKey[16*16]; \\r
- UCHAR *expandedKey = _expandedKey; \\r
-\r
-\r
-#endif\r
-\r
-#endif\r
-\r
-\r
-\r
-// encryption functions\r
-// plainText is pointer to input stream\r
-// cipherText is pointer to buffer to be filled with encrypted (cipher text) data\r
-// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for AES-192, 32 for AES-256)\r
-// numBlocks is number of 16 bytes blocks to process - note that encryption is done of full 16 byte blocks\r
-void intel_AES_enc128(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-void intel_AES_enc192(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-void intel_AES_enc256(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-\r
-\r
-void intel_AES_enc128_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-void intel_AES_enc192_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-void intel_AES_enc256_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-\r
-\r
-// encryption functions\r
-// cipherText is pointer to encrypted stream\r
-// plainText is pointer to buffer to be filled with original (plain text) data\r
-// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for AES-192, 32 for AES-256)\r
-// numBlocks is number of 16 bytes blocks to process - note that decryption is done of full 16 byte blocks\r
-void intel_AES_dec128(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-void intel_AES_dec192(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-void intel_AES_dec256(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks);\r
-\r
-void intel_AES_dec128_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-void intel_AES_dec192_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-void intel_AES_dec256_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv);\r
-\r
-void intel_AES_encdec128_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter);\r
-void intel_AES_encdec192_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter);\r
-void intel_AES_encdec256_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter);\r
-\r
-\r
-#if (__cplusplus)\r
-}\r
-#endif\r
-\r
-\r
-#endif\r
-\r
-\r
-\r
-/* intel_aes_lib source files come from Intel.\r
- * Modified by Patrick Fay\r
- *\r
-Copyright (c) 2010, Intel Corporation\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without \r
-modification, are permitted provided that the following conditions are met:\r
-\r
- * Redistributions of source code must retain the above copyright notice, \r
- this list of conditions and the following disclaimer.\r
- * Redistributions in binary form must reproduce the above copyright notice, \r
- this list of conditions and the following disclaimer in the documentation \r
- and/or other materials provided with the distribution.\r
- * Neither the name of Intel Corporation nor the names of its contributors \r
- may be used to endorse or promote products derived from this software \r
- without specific prior written permission.\r
-\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \r
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \r
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
-IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \r
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \r
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF \r
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
- ---------------------------------------------------------------------------\r
- Issue Date: Aug 6, 2010\r
- */\r
-\r
-Other source code files use the license shown in the source code file.\r
+====================================================================
+Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+project. The module is, however, dual licensed under OpenSSL and
+CRYPTOGAMS licenses depending on where you obtain it. For further
+details see http://www.openssl.org/~appro/cryptogams/.
+====================================================================
+
+Copyright (c) 2006, CRYPTOGAMS by <appro@openssl.org>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain copyright notices,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ * Neither the name of the CRYPTOGAMS nor the names of its
+ copyright holder and contributors may be used to endorse or
+ promote products derived from this software without specific
+ prior written permission.
+
+ALTERNATIVELY, provided that this notice is retained in full, this
+product may be distributed under the terms of the GNU General Public
+License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+those given above.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.