]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Updates in the AES-NI accelerator.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 12 Apr 2011 11:44:51 +0000 (13:44 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 12 Apr 2011 11:46:11 +0000 (13:46 +0200)
NEWS
lib/accelerated/intel/Makefile.am
lib/accelerated/intel/aes-x86.c
lib/accelerated/intel/asm/x64_do_rdtsc.s [deleted file]
lib/accelerated/intel/asm/x86_do_rdtsc.s [deleted file]
tests/cipher-test.c

diff --git a/NEWS b/NEWS
index 2fe8caeac4534514412a2598df73e46e9204523c..a3c43cc9d20a4619b129118847ae34c255bde664 100644 (file)
--- 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
index 6f7ab3efb35fa95cc5b0a48a94868ed1e6be4a5d..f57b09862f660f8d7b25024d376226e930ffa42d 100644 (file)
@@ -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
 
index eeeca30134b257585093086c46ab097a17aec878..df4a49ba97356beee026aac5264106cabf1d1076 100644 (file)
@@ -31,7 +31,6 @@
 #include <gnutls_errors.h>
 #include <aes-x86.h>
 #include <x86.h>
-#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 (executable)
index 74435c7..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-[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
-align 16\r
-global do_rdtsc\r
-do_rdtsc:\r
-\r
-       rdtsc\r
-       shl rdx, 32\r
-       or  rax, rdx\r
-       ret     0\r
diff --git a/lib/accelerated/intel/asm/x86_do_rdtsc.s b/lib/accelerated/intel/asm/x86_do_rdtsc.s
deleted file mode 100755 (executable)
index ba4f410..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-[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
-align 16\r
-global _do_rdtsc\r
-_do_rdtsc:\r
-\r
-       rdtsc\r
-       ret\r
index 1bce21b1efc9dfdc73ca4f90d7d019874b1e85f9..d9ae400ad7655ebe46c0016d6163a926b999ae2b 100644 (file)
@@ -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;
 }