From: Nikos Mavrogiannopoulos Date: Tue, 12 Apr 2011 11:44:51 +0000 (+0200) Subject: Updates in the AES-NI accelerator. X-Git-Tag: gnutls_2_99_1~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=23106912a0ef0dd9a76b0855dc4a3491f45fc5cd;p=thirdparty%2Fgnutls.git Updates in the AES-NI accelerator. --- diff --git a/NEWS b/NEWS index 2fe8caeac4..a3c43cc9d2 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ See the end for copying conditions. * Version 2.99.1 (unreleased) +** libgnutls: Added support for AES-NI if detected. Uses +Intel AES-NI code. + ** libgnutls-extra: Dropped support of LZO compression via liblzo. ** libgnutls: gnutls_transport_set_global_errno() was removed. This diff --git a/lib/accelerated/intel/Makefile.am b/lib/accelerated/intel/Makefile.am index 6f7ab3efb3..f57b09862f 100644 --- a/lib/accelerated/intel/Makefile.am +++ b/lib/accelerated/intel/Makefile.am @@ -29,10 +29,12 @@ AM_CPPFLAGS = \ -I$(srcdir)/../ if ENABLE_MINITASN1 -AM_CPPFLAGS += -I$(srcdir)/../minitasn1 +AM_CPPFLAGS += -I$(srcdir)/../../minitasn1 endif -EXTRA_DIST = aes-x86.h README license.txt +EXTRA_DIST = aes-x86.h README license.txt iaes_asm_interface.h iaesni.h \ + asm/x64_iaesx64.s asm/x86_iaesx86.s + noinst_LTLIBRARIES = libintel.la libintel_la_SOURCES = aes-x86.c @@ -40,21 +42,15 @@ libintel_la_LIBADD = YASM_OPTS = -D__linux__ -x64_do_rdtsc.o: asm/x64_do_rdtsc.s - $(YASM) $(YASM_OPTS) -f elf64 $^ -o $@ - x64_iaesx64.o: asm/x64_iaesx64.s $(YASM) $(YASM_OPTS) -f elf64 $^ -o $@ -x86_do_rdtsc.o: asm/x86_do_rdtsc.s - $(YASM) $(YASM_OPTS) -f elf32 $^ -o $@ - x86_iaesx86.o: asm/x86_iaesx86.s $(YASM) $(YASM_OPTS) -f elf32 $^ -o $@ if ASM_X86_64 -libintel_la_LIBADD += x64_do_rdtsc.o x64_iaesx64.o +libintel_la_LIBADD += x64_iaesx64.o else -libintel_la_LIBADD += x86_do_rdtsc.o x86_iaesx86.o +libintel_la_LIBADD += x86_iaesx86.o endif diff --git a/lib/accelerated/intel/aes-x86.c b/lib/accelerated/intel/aes-x86.c index eeeca30134..df4a49ba97 100644 --- a/lib/accelerated/intel/aes-x86.c +++ b/lib/accelerated/intel/aes-x86.c @@ -31,7 +31,6 @@ #include #include #include -#include "iaesni.h" #include "iaes_asm_interface.h" #ifdef __GNUC__ @@ -43,9 +42,9 @@ typedef void (*enc_func)(sAesData*); struct aes_ctx { - uint8_t iv[16]; 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; @@ -99,6 +98,8 @@ struct aes_ctx *ctx = _ctx; ctx->enc = iEnc256_CBC; ctx->dec = iDec256_CBC; } + else + return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); ctx->keysize = keysize; @@ -111,7 +112,6 @@ aes_setiv (void *_ctx, const void *iv, size_t iv_size) struct aes_ctx *ctx = _ctx; memcpy (ctx->iv, iv, 16); - return 0; } @@ -121,11 +121,12 @@ aes_encrypt (void *_ctx, const void *plain, size_t plainsize, { 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 = length % 16; + aesData.num_blocks = (plainsize + 1) / 16; ctx->enc(&aesData); @@ -139,10 +140,11 @@ aes_decrypt (void *_ctx, const void *encr, size_t encrsize, 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; - aesData.num_blocks = length % 16; + aesData.expanded_key = ctx->expanded_key_dec; + aesData.num_blocks = (encrsize + 1) / 16; ctx->dec(&aesData); diff --git a/lib/accelerated/intel/asm/x64_do_rdtsc.s b/lib/accelerated/intel/asm/x64_do_rdtsc.s deleted file mode 100755 index 74435c73f7..0000000000 --- a/lib/accelerated/intel/asm/x64_do_rdtsc.s +++ /dev/null @@ -1,37 +0,0 @@ -[bits 64] -[CPU intelnop] - -; Copyright (c) 2010, Intel Corporation -; 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 the above copyright notice, -; 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 Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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. - -align 16 -global do_rdtsc -do_rdtsc: - - rdtsc - shl rdx, 32 - or rax, rdx - ret 0 diff --git a/lib/accelerated/intel/asm/x86_do_rdtsc.s b/lib/accelerated/intel/asm/x86_do_rdtsc.s deleted file mode 100755 index ba4f41090a..0000000000 --- a/lib/accelerated/intel/asm/x86_do_rdtsc.s +++ /dev/null @@ -1,35 +0,0 @@ -[bits 32] -[CPU intelnop] - -; Copyright (c) 2010, Intel Corporation -; 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 the above copyright notice, -; 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 Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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. - -align 16 -global _do_rdtsc -_do_rdtsc: - - rdtsc - ret diff --git a/tests/cipher-test.c b/tests/cipher-test.c index 1bce21b1ef..d9ae400ad7 100644 --- a/tests/cipher-test.c +++ b/tests/cipher-test.c @@ -79,6 +79,7 @@ static int test_aes(void) fprintf(stdout, "Tests on AES Encryption: "); for (i = 0; i < sizeof(aes_vectors) / sizeof(aes_vectors[0]); i++) { memset(_iv, 0, sizeof(_iv)); + memset(tmp, 0, sizeof(tmp)); key.data = (void*)aes_vectors[i].key; key.size = 16; @@ -123,6 +124,7 @@ static int test_aes(void) for (i = 0; i < sizeof(aes_vectors) / sizeof(aes_vectors[0]); i++) { memset(_iv, 0, sizeof(_iv)); + memset(tmp, 0x33, sizeof(tmp)); key.data = (void*)aes_vectors[i].key; key.size = 16; @@ -316,11 +318,14 @@ static int test_hash(void) int main(int argc, char** argv) { + gnutls_global_init(); + if (test_aes()) return 1; if (test_hash()) return 1; + gnutls_global_deinit(); return 0; }