gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, master, updated. gnutls_2_99_0-30-g2310691


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_2_99_0-30-g2310691
Date: Tue, 12 Apr 2011 11:48:24 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=23106912a0ef0dd9a76b0855dc4a3491f45fc5cd

The branch, master has been updated
       via  23106912a0ef0dd9a76b0855dc4a3491f45fc5cd (commit)
       via  0bb26a6e8e9bd7ee23884f17342c8e84033907cf (commit)
       via  d64549b02612ff2d363dae32360670ec8aeb3e01 (commit)
       via  06cbbc3d6d582487649f34de46e434466ea7bc04 (commit)
       via  20e0e448a2f3685cc6244f7c052b32f3f0719f73 (commit)
       via  c0f0057cb811e2532709bc9d005d7d8e4120c6d3 (commit)
       via  dd93f6446d6284705b8dcfc94994bc765b73489a (commit)
       via  0baa0937de0e5534b2010039ab047ce8eb7cf92a (commit)
       via  69fd4dd53e25de3794ea368391fc35585a1808d1 (commit)
       via  8326537a849fb3ab12f5e30a6ddb9255995255a2 (commit)
       via  4ea32a2b463192f88b5cef10725d967ee6b9bc95 (commit)
       via  875f93f0e849a25a5428cc11448246b3c35dc04d (commit)
       via  9de39deefebcf28fafe301337a71f1f69e6b5a01 (commit)
       via  cea96577fa0ae1f2de4d679a591d1e4e9045dbe0 (commit)
       via  d1e6347613ba720c838810ff63f7d481d4a06b44 (commit)
       via  446833f006b4a5ce0b8c5c9be7d1f8ba14a1eb06 (commit)
       via  2725c5c9885daa057c11393ad6522048e9d1cc43 (commit)
       via  7c34680c910089bf6d102664d767940d0ceeca64 (commit)
       via  80e5bdd0f09110a00241d901067e1e457a17ec06 (commit)
       via  57555c75a8faf71bc7d664d73a2b9914ddb809d0 (commit)
      from  6ceb3b0e0836f08ede425fd58ff93f322b881636 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 23106912a0ef0dd9a76b0855dc4a3491f45fc5cd
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Apr 12 13:44:51 2011 +0200

    Updates in the AES-NI accelerator.

commit 0bb26a6e8e9bd7ee23884f17342c8e84033907cf
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Apr 12 12:18:02 2011 +0200

    Added gnutls_cipher_set_iv().

commit d64549b02612ff2d363dae32360670ec8aeb3e01
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Apr 12 12:11:51 2011 +0200

    Added test vectors for AES,SHAxxx and MD5.

commit 06cbbc3d6d582487649f34de46e434466ea7bc04
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Apr 12 12:10:59 2011 +0200

    Increased priority of CPU assisted ciphers.

commit 20e0e448a2f3685cc6244f7c052b32f3f0719f73
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Tue Apr 12 11:57:02 2011 +0200

    Do not rely on lowat being set.

commit c0f0057cb811e2532709bc9d005d7d8e4120c6d3
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 23:16:50 2011 +0200

    Added README explaining the usage of Intel AES library.

commit dd93f6446d6284705b8dcfc94994bc765b73489a
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 20:38:18 2011 +0200

    Corrected parsing error in TLS, when many handshake messages
    were packed in a single record message.

commit 0baa0937de0e5534b2010039ab047ce8eb7cf92a
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 16:26:35 2011 +0200

    fixes in acceleration detection.
    Added Intel's library code for AES-NI acceleration.

commit 69fd4dd53e25de3794ea368391fc35585a1808d1
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 09:10:02 2011 +0200

    Purged all references of LZO.

commit 8326537a849fb3ab12f5e30a6ddb9255995255a2
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 08:58:47 2011 +0200

    removed duplicate test

commit 4ea32a2b463192f88b5cef10725d967ee6b9bc95
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 08:58:16 2011 +0200

    No need to under restrict for C++. Only use config.h.

commit 875f93f0e849a25a5428cc11448246b3c35dc04d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 00:01:05 2011 +0200

    gnutls_transport_set_global_errno() is no more.

commit 9de39deefebcf28fafe301337a71f1f69e6b5a01
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Apr 11 00:00:49 2011 +0200

    Combined the safe renegotiation tests with the again-common lib.

commit cea96577fa0ae1f2de4d679a591d1e4e9045dbe0
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 23:17:39 2011 +0200

    Support for liblzo was dropped.

commit d1e6347613ba720c838810ff63f7d481d4a06b44
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 20:48:29 2011 +0200

    bumped version

commit 446833f006b4a5ce0b8c5c9be7d1f8ba14a1eb06
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 20:47:15 2011 +0200

    updated time.h.in

commit 2725c5c9885daa057c11393ad6522048e9d1cc43
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 14:13:23 2011 +0200

    Corrected documentation of several API functions.

commit 7c34680c910089bf6d102664d767940d0ceeca64
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 14:12:41 2011 +0200

    documentation updates.

commit 80e5bdd0f09110a00241d901067e1e457a17ec06
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 13:50:43 2011 +0200

    remove perl warnings from scripts.

commit 57555c75a8faf71bc7d664d73a2b9914ddb809d0
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Apr 10 08:55:41 2011 +0200

    Added support for x86 intel AES instruction acceleration if detected.

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                                    |   14 +
 NEWS                                          |   16 +
 configure.ac                                  |  195 ++-
 doc/cha-gtls-app.texi                         |   41 -
 doc/cha-intro-tls.texi                        |    6 -
 doc/cha-library.texi                          |   41 +
 doc/cha-preface.texi                          |    5 +-
 doc/cha-programs.texi                         |    1 -
 doc/examples/ex-cxx.cpp                       |    1 +
 doc/scripts/gdoc                              |    8 +-
 doc/scripts/sort2.pl                          |   12 +-
 gl/time.h                                     |  564 -------
 guile/modules/gnutls/build/enums.scm          |    3 +-
 lib/Makefile.am                               |    3 +-
 lib/{gcrypt => accelerated}/Makefile.am       |   17 +-
 lib/accelerated/accelerated.c                 |   14 +
 lib/accelerated/accelerated.h                 |    1 +
 lib/{nettle => accelerated/intel}/Makefile.am |   37 +-
 lib/accelerated/intel/README                  |    3 +
 lib/accelerated/intel/aes-x86.c               |  203 +++
 lib/accelerated/intel/aes-x86.h               |    1 +
 lib/accelerated/intel/asm/x64_iaesx64.s       | 2054 +++++++++++++++++++++++
 lib/accelerated/intel/asm/x86_iaesx86.s       | 2183 +++++++++++++++++++++++++
 lib/accelerated/intel/iaes_asm_interface.h    |  126 ++
 lib/accelerated/intel/iaesni.h                |  147 ++
 lib/accelerated/intel/license.txt             |   34 +
 lib/accelerated/x86.h                         |    3 +
 lib/crypto-api.c                              |   17 +
 lib/crypto.c                                  |   15 +-
 lib/gnutls_algorithms.c                       |    2 +-
 lib/gnutls_buffers.c                          |   17 +-
 lib/gnutls_compress.c                         |  120 +--
 lib/gnutls_dtls.c                             |   24 +-
 lib/gnutls_errors.c                           |    2 -
 lib/gnutls_global.c                           |    3 +
 lib/gnutls_mem.c                              |    3 +-
 lib/gnutls_psk.c                              |    2 +-
 lib/gnutls_record.c                           |    4 +-
 lib/gnutls_state.c                            |    5 +-
 lib/includes/gnutls/crypto.h                  |    4 +-
 lib/includes/gnutls/gnutls.h.in               |    8 +-
 lib/libgnutls.map                             |    6 +-
 lib/pkcs11.c                                  |    2 +-
 lib/pkcs11_privkey.c                          |    1 +
 lib/system_override.c                         |   46 -
 lib/x509/verify-high.c                        |    3 +-
 lib/x509/verify.c                             |    4 +-
 libextra/Makefile.am                          |    3 +-
 libextra/gnutls_extra.c                       |   81 +-
 m4/gcc.m4                                     |   28 +
 m4/hooks.m4                                   |   29 -
 src/cli.c                                     |   65 +-
 tests/Makefile.am                             |    4 +-
 tests/cipher-test.c                           |  331 ++++
 tests/eagain-common.h                         |   13 +-
 tests/safe-renegotiation/Makefile.am          |    3 +-
 tests/safe-renegotiation/srn0.c               |  181 +--
 tests/safe-renegotiation/srn1.c               |  132 +--
 tests/safe-renegotiation/srn2.c               |  261 +---
 tests/safe-renegotiation/srn3.c               |  132 +--
 tests/safe-renegotiation/srn4.c               |  182 +--
 tests/safe-renegotiation/srn5.c               |  184 +--
 62 files changed, 5592 insertions(+), 2058 deletions(-)
 delete mode 100644 gl/time.h
 copy lib/{gcrypt => accelerated}/Makefile.am (75%)
 create mode 100644 lib/accelerated/accelerated.c
 create mode 100644 lib/accelerated/accelerated.h
 copy lib/{nettle => accelerated/intel}/Makefile.am (58%)
 create mode 100644 lib/accelerated/intel/README
 create mode 100644 lib/accelerated/intel/aes-x86.c
 create mode 100644 lib/accelerated/intel/aes-x86.h
 create mode 100755 lib/accelerated/intel/asm/x64_iaesx64.s
 create mode 100755 lib/accelerated/intel/asm/x86_iaesx86.s
 create mode 100755 lib/accelerated/intel/iaes_asm_interface.h
 create mode 100755 lib/accelerated/intel/iaesni.h
 create mode 100755 lib/accelerated/intel/license.txt
 create mode 100644 lib/accelerated/x86.h
 create mode 100644 m4/gcc.m4
 create mode 100644 tests/cipher-test.c

diff --git a/.gitignore b/.gitignore
index bd5cdd1..42008a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -437,3 +437,17 @@ gl/m4/fcntl-o.m4
 gl/m4/fcntl_h.m4
 gl/m4/pipe.m4
 doc/examples/ex-client-udp
+gl/tests/test-byteswap
+gl/tests/test-fcntl-h
+gl/tests/test-func
+gl/tests/test-hmac-md5
+gl/tests/test-md5
+gl/tests/test-strings
+gl/tests/test-strverscmp
+gl/tests/test-u64
+gl/tests/test-vasprintf
+gl/tests/test-vsnprintf
+lib/accelerated/libaccelerated.la
+gl/time.h
+lib/accelerated/intel/libintel.la
+doc/cyclo/cyclo-gnutls.html
diff --git a/NEWS b/NEWS
index ddf0aba..a3c43cc 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,22 @@ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
               2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 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
+function required GnuTLS to access system specific data, for no reason.
+Use gnutls_transport_set_errno(), or your system's errno fascility
+instead.
+
+** API and ABI modifications:
+gnutls_transport_set_global_errno: REMOVED
+
+
 * Version 2.99.0 (released 2011-04-09)
 
 ** libgnutls: Added Datagram TLS support.
diff --git a/configure.ac b/configure.ac
index f451464..f6b28b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ dnl Process this file with autoconf to produce a configure 
script.
 # USA
 
 AC_PREREQ(2.61)
-AC_INIT([GnuTLS], [2.99.0], address@hidden)
+AC_INIT([GnuTLS], [2.99.1], address@hidden)
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_MACRO_DIR([m4])
 
@@ -54,7 +54,6 @@ fi
 AC_C_INLINE
 
 # For the C++ code
-AC_PROG_CXX
 AC_ARG_ENABLE(cxx,
   AS_HELP_STRING([--disable-cxx], [unconditionally disable the C++ library]),
     use_cxx=$enableval, use_cxx=yes)
@@ -91,85 +90,38 @@ AC_CHECK_TYPES(uint,,, [
 # include <sys/types.h>
 ])
 
-# For Guile bindings.
-opt_guile_bindings=yes
-AC_MSG_CHECKING([whether building Guile bindings])
-AC_ARG_ENABLE(guile,
-       AS_HELP_STRING([--enable-guile], [build GNU Guile bindings]),
-opt_guile_bindings=$enableval)
-AC_MSG_RESULT($opt_guile_bindings)
-
-AC_ARG_WITH([--with-guile-site-dir],
-  [AS_HELP_STRING([--with-guile-site-dir],
-     [use the given directory as the Guile site (use with care)])])
-
-if test "$opt_guile_bindings" = "yes"; then
-   AC_MSG_RESULT([***
-*** Detecting GNU Guile...
-])
-
-   AC_PATH_PROG([guile_snarf], [guile-snarf])
-   if test "x$guile_snarf" = "x"; then
-      AC_MSG_WARN([`guile-snarf' from Guile 1.8 not found.  Guile bindings not 
built.])
-      opt_guile_bindings=no
-   else
-      GUILE_PROGS
-      GUILE_FLAGS
-
-      save_CFLAGS="$CFLAGS"
-      save_LIBS="$LIBS"
-      CFLAGS="$CFLAGS $GUILE_CFLAGS"
-      LIBS="$LIBS $GUILE_LDFLAGS"
-      AC_MSG_CHECKING([whether GNU Guile is recent enough])
-      AC_LINK_IFELSE(AC_LANG_CALL([], [scm_from_locale_string]),
-        [], [opt_guile_bindings=no])
-      CFLAGS="$save_CFLAGS"
-      LIBS="$save_LIBS"
-
-      if test "$opt_guile_bindings" = "yes"; then
-        AC_MSG_RESULT([yes])
-       case "x$with_guile_site_dir" in 
-            xno)
-               # Use the default $(GUILE_SITE).
-               GUILE_SITE_DIR
-               ;;
-            x|xyes)
-               # Automatically derive $(GUILE_SITE) from $(pkgdatadir).  This
-               # hack is used to allow `distcheck' to work (see
-               # `DISTCHECK_CONFIGURE_FLAGS' in the top-level `Makefile.am').
-               GUILE_SITE="\$(datadir)/guile/site"
-               AC_SUBST(GUILE_SITE)
-               ;;
-            *)
-               # Use the user-specified directory as $(GUILE_SITE).
-               GUILE_SITE="$with_guile_site_dir"
-               AC_SUBST(GUILE_SITE)
-               ;;
-       esac
-        AC_MSG_CHECKING([whether gcc supports -fgnu89-inline])
-        _gcc_cflags_save="$CFLAGS"
-        CFLAGS="${CFLAGS} -fgnu89-inline"
-        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
-                          gnu89_inline=yes, gnu89_inline=no)
-        AC_MSG_RESULT($gnu89_inline)
-        CFLAGS="$_gcc_cflags_save"
 
-       # Optional Guile functions.
-       save_CFLAGS="$CFLAGS"
-       save_LIBS="$LIBS"
-       CFLAGS="$CFLAGS $GUILE_CFLAGS"
-       LIBS="$LIBS $GUILE_LDFLAGS"
-       AC_CHECK_FUNCS([scm_gc_malloc_pointerless])
-       CFLAGS="$save_CFLAGS"
-       LIBS="$save_LIBS"
-      else
-        AC_MSG_RESULT([no])
-        AC_MSG_WARN([A sufficiently recent GNU Guile not found.  Guile 
bindings not built.])
-        opt_guile_bindings=no
+AC_ARG_ENABLE(hardware-acceleration,
+  AS_HELP_STRING([--disable-hardware-acceleration], [unconditionally disable 
hardware acceleration]),
+    use_accel=$enableval, use_accel=yes)
+hw_accel=none
+
+if test "$use_accel" != "no"; then
+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
       fi
-   fi
+    else
+      AC_MSG_WARN([[yasm assembler not found. Disabling AES-NI compilation.]])
+    fi
+  ;;
+  *)
+  ;;
+esac
+
 fi
-AM_CONDITIONAL(HAVE_GUILE, test "$opt_guile_bindings" = "yes")
+
+AM_CONDITIONAL(TRY_X86_OPTIMIZATIONS, test x"$hw_accel" = x"x86" -o 
x"$hw_accel" = x"x86-64")
+AM_CONDITIONAL(ASM_X86_64, test x"$hw_accel" = x"x86-64")
 AM_CONDITIONAL(HAVE_GCC_GNU89_INLINE_OPTION, test "$gnu89_inline" = "yes"])
 AM_CONDITIONAL(HAVE_GCC, test "$GCC" = "yes")
 
@@ -310,7 +262,88 @@ AC_SUBST([WSTACK_CFLAGS])
 AC_SUBST([WARN_CFLAGS])
 AM_CONDITIONAL(ENABLE_CXX, test "$use_cxx" != "no")
 
-LIBGNUTLS_EXTRA_LIBS="-L${libdir} -lgnutls-extra $LZO_LIBS $LIBGNUTLS_LIBS"
+# For Guile bindings.
+opt_guile_bindings=yes
+AC_MSG_CHECKING([whether building Guile bindings])
+AC_ARG_ENABLE(guile,
+       AS_HELP_STRING([--enable-guile], [build GNU Guile bindings]),
+opt_guile_bindings=$enableval)
+AC_MSG_RESULT($opt_guile_bindings)
+
+AC_ARG_WITH([--with-guile-site-dir],
+  [AS_HELP_STRING([--with-guile-site-dir],
+     [use the given directory as the Guile site (use with care)])])
+
+if test "$opt_guile_bindings" = "yes"; then
+   AC_MSG_RESULT([***
+*** Detecting GNU Guile...
+])
+
+   AC_PATH_PROG([guile_snarf], [guile-snarf])
+   if test "x$guile_snarf" = "x"; then
+      AC_MSG_WARN([`guile-snarf' from Guile 1.8 not found.  Guile bindings not 
built.])
+      opt_guile_bindings=no
+   else
+      GUILE_PROGS
+      GUILE_FLAGS
+
+      save_CFLAGS="$CFLAGS"
+      save_LIBS="$LIBS"
+      CFLAGS="$CFLAGS $GUILE_CFLAGS"
+      LIBS="$LIBS $GUILE_LDFLAGS"
+      AC_MSG_CHECKING([whether GNU Guile is recent enough])
+      AC_LINK_IFELSE(AC_LANG_CALL([], [scm_from_locale_string]),
+        [], [opt_guile_bindings=no])
+      CFLAGS="$save_CFLAGS"
+      LIBS="$save_LIBS"
+
+      if test "$opt_guile_bindings" = "yes"; then
+        AC_MSG_RESULT([yes])
+       case "x$with_guile_site_dir" in 
+            xno)
+               # Use the default $(GUILE_SITE).
+               GUILE_SITE_DIR
+               ;;
+            x|xyes)
+               # Automatically derive $(GUILE_SITE) from $(pkgdatadir).  This
+               # hack is used to allow `distcheck' to work (see
+               # `DISTCHECK_CONFIGURE_FLAGS' in the top-level `Makefile.am').
+               GUILE_SITE="\$(datadir)/guile/site"
+               AC_SUBST(GUILE_SITE)
+               ;;
+            *)
+               # Use the user-specified directory as $(GUILE_SITE).
+               GUILE_SITE="$with_guile_site_dir"
+               AC_SUBST(GUILE_SITE)
+               ;;
+       esac
+        AC_MSG_CHECKING([whether gcc supports -fgnu89-inline])
+        _gcc_cflags_save="$CFLAGS"
+        CFLAGS="${CFLAGS} -fgnu89-inline"
+        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
+                          gnu89_inline=yes, gnu89_inline=no)
+        AC_MSG_RESULT($gnu89_inline)
+        CFLAGS="$_gcc_cflags_save"
+
+       # Optional Guile functions.
+       save_CFLAGS="$CFLAGS"
+       save_LIBS="$LIBS"
+       CFLAGS="$CFLAGS $GUILE_CFLAGS"
+       LIBS="$LIBS $GUILE_LDFLAGS"
+       AC_CHECK_FUNCS([scm_gc_malloc_pointerless])
+       CFLAGS="$save_CFLAGS"
+       LIBS="$save_LIBS"
+      else
+        AC_MSG_RESULT([no])
+        AC_MSG_WARN([A sufficiently recent GNU Guile not found.  Guile 
bindings not built.])
+        opt_guile_bindings=no
+      fi
+   fi
+fi
+AM_CONDITIONAL(HAVE_GUILE, test "$opt_guile_bindings" = "yes")
+
+
+LIBGNUTLS_EXTRA_LIBS="-L${libdir} -lgnutls-extra $LIBGNUTLS_LIBS"
 LIBGNUTLS_EXTRA_CFLAGS="-I${includedir}"
 AC_SUBST(LIBGNUTLS_EXTRA_LIBS)
 AC_SUBST(LIBGNUTLS_EXTRA_CFLAGS)
@@ -376,6 +409,8 @@ AC_CONFIG_FILES([
   lib/gcrypt/Makefile
   lib/nettle/Makefile
   tests/suite/Makefile
+  lib/accelerated/Makefile
+  lib/accelerated/intel/Makefile
 ])
 
 AC_OUTPUT
@@ -386,6 +421,7 @@ AC_MSG_NOTICE([summary of build options:
   Host type:        ${host}
   Install prefix:   ${prefix}
   Compiler:         ${CC}
+  CFlags:           ${CFLAGS}
   Warning flags:    errors: ${WERROR_CFLAGS} warnings: ${WARN_CFLAGS}
   Library types:    Shared=${enable_shared}, Static=${enable_static}
   Valgrind:         $opt_valgrind_tests ${VALGRIND}
@@ -393,5 +429,6 @@ AC_MSG_NOTICE([summary of build options:
   C++ library:      $use_cxx
   OpenSSL library:  $enable_openssl
   /dev/crypto:      $enable_cryptodev
+  Hardware accel:   $hw_accel
   Crypto library:   $cryptolib
 ])
diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi
index e91b135..9054549 100644
--- a/doc/cha-gtls-app.texi
+++ b/doc/cha-gtls-app.texi
@@ -5,7 +5,6 @@
 
 @menu
 * Preparation::
-* Multi-threaded applications::
 * Client examples::
 * Server examples::
 * Miscellaneous examples::
@@ -123,46 +122,6 @@ specifying both options to @command{pkg-config}:
 gcc -o foo foo.c `pkg-config gnutls --cflags --libs`
 @end example
 
address@hidden Multi-threaded applications
address@hidden Multi-Threaded Applications
-
-Although the @acronym{GnuTLS} library is thread safe by design, some
-parts of the cryptographic backend, such as the random generator, are not.
-Applications can either call @ref{gnutls_global_init} and use the default 
-operating system provided locks (i.e. @code{pthreads} on GNU/Linux), or
-specify manualy the locking system using the function 
@ref{gnutls_global_set_mutex}
-before calling @ref{gnutls_global_init}. Setting manually mutexes is 
recommended
-only to applications that have full control of the underlying libraries. If 
this
-is not the case, the use of the operating system defaults is recommended.
-
-
-There are helper macros to help you properly initialize the libraries.
-Examples are shown below.
-
address@hidden
-
address@hidden POSIX threads in GNU/Linux
address@hidden
-#include <gnutls.h>
-#include <errno.h>
-#include <pthread.h>
-
-int main()
address@hidden
-   gnutls_global_init();
address@hidden
address@hidden example
-
address@hidden Other thread packages
address@hidden
-
-int main()
address@hidden
-   gnutls_global_mutex_set (mutex_init, mutex_deinit, mutex_lock, 
mutex_unlock);
-   gnutls_global_init();
address@hidden
address@hidden example
address@hidden itemize
 
 @node Client examples
 @section Client Examples
diff --git a/doc/cha-intro-tls.texi b/doc/cha-intro-tls.texi
index 3439ceb..ae71f03 100644
--- a/doc/cha-intro-tls.texi
+++ b/doc/cha-intro-tls.texi
@@ -236,12 +236,6 @@ The supported compression algorithms are:
 @item DEFLATE
 Zlib compression, using the deflate algorithm.
 
address@hidden LZO
-LZO is a very fast compression algorithm.  This algorithm is only
-available if the @acronym{GnuTLS-extra} library has been initialized
-and the private extensions are enabled, and if GnuTLS was built with
-LZO support.
-
 @end table
 
 @node Weaknesses and countermeasures
diff --git a/doc/cha-library.texi b/doc/cha-library.texi
index 6c783be..7618c42 100644
--- a/doc/cha-library.texi
+++ b/doc/cha-library.texi
@@ -62,6 +62,7 @@ small library, with the required features, can be generated.
 * General Idea::
 * Error handling::
 * Memory handling::
+* Thread safety::
 * Callback functions::
 @end menu
 
@@ -153,6 +154,46 @@ used in cases where even the system's swap memory is not 
considered
 secure. See the documentation of @acronym{Libgcrypt} for more
 information.
 
address@hidden Thread safety
address@hidden Thread safety
+
+Although the @acronym{GnuTLS} library is thread safe by design, some
+parts of the cryptographic backend, such as the random generator, are not.
+Applications can either call @ref{gnutls_global_init} which will use the 
default
+operating system provided locks (i.e. @code{pthreads} on GNU/Linux and
address@hidden on Windows), or specify manualy the locking system using 
+the function @ref{gnutls_global_set_mutex} before calling 
@ref{gnutls_global_init}. 
+Setting manually mutexes is recommended
+only to applications that have full control of the underlying libraries. If 
this
+is not the case, the use of the operating system defaults is suggested.
+
+
+There are helper macros to help you properly initialize the libraries.
+Examples are shown below.
+
address@hidden
+
address@hidden Native threads
address@hidden
+#include <gnutls.h>
+
+int main()
address@hidden
+   gnutls_global_init();
address@hidden
address@hidden example
+
address@hidden Other thread packages
address@hidden
+
+int main()
address@hidden
+   gnutls_global_mutex_set (mutex_init, mutex_deinit, mutex_lock, 
mutex_unlock);
+   gnutls_global_init();
address@hidden
address@hidden example
address@hidden itemize
+
 @node Callback functions
 @section Callback Functions
 @cindex Callback functions
diff --git a/doc/cha-preface.texi b/doc/cha-preface.texi
index 1c4058b..10e41d6 100644
--- a/doc/cha-preface.texi
+++ b/doc/cha-preface.texi
@@ -122,9 +122,8 @@ distribution archive.  Typically you invoke 
@code{./configure} and
 then @code{make check install}.  There are a number of compile-time
 parameters, as discussed below.
 
-The compression libraries (libz and lzo) are optional dependencies.
-You can get libz from @url{http://www.zlib.net/}.  You can get lzo
-from @url{http://www.oberhumer.com/opensource/lzo/}.
+The compression library (libz) is an optional dependency.
+You can get libz from @url{http://www.zlib.net/}.  
 
 The X.509 part of GnuTLS needs ASN.1 functionality, from a library
 called libtasn1.  A copy of libtasn1 is included in GnuTLS.  If you
diff --git a/doc/cha-programs.texi b/doc/cha-programs.texi
index 2f44e83..8b9aea5 100644
--- a/doc/cha-programs.texi
+++ b/doc/cha-programs.texi
@@ -506,7 +506,6 @@ Checking for ARCFOUR 40 cipher support... no
 Checking for MD5 MAC support... yes
 Checking for SHA1 MAC support... yes
 Checking for ZLIB compression support (TLS extension)... yes
-Checking for LZO compression support (GnuTLS extension)... yes
 Checking for max record size (TLS extension)... yes
 Checking for SRP authentication support (TLS extension)... yes
 Checking for OpenPGP authentication support (TLS extension)... no
diff --git a/doc/examples/ex-cxx.cpp b/doc/examples/ex-cxx.cpp
index 483f2d7..ce4016a 100644
--- a/doc/examples/ex-cxx.cpp
+++ b/doc/examples/ex-cxx.cpp
@@ -1,3 +1,4 @@
+#include <config.h>
 #include <iostream>
 #include <stdexcept>
 #include <gnutls/gnutls.h>
diff --git a/doc/scripts/gdoc b/doc/scripts/gdoc
index e79d3af..afd0802 100755
--- a/doc/scripts/gdoc
+++ b/doc/scripts/gdoc
@@ -1,6 +1,4 @@
-eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
-  & eval 'exec perl -wS "$0" $argv:q'
-    if 0;
+#!/usr/bin/perl
 
 ## Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Simon Josefsson
 ##                    added -texinfo, -listfunc, -pkg-name
@@ -184,7 +182,7 @@ $blankline_man = "";
                     $type_struct, "\$1",
                     $type_param, "\$1" );
 $blankline_text = "";
-
+my $lineprefix = "";
 
 sub usage {
     print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex | 
-texinfo  -listfunc ]\n";
@@ -746,7 +744,7 @@ sub dump_function {
 #          print STDERR " :> @args\n";
            $type = join " ", @args;
 
-           if ($parameters{$param} eq "" && $param != "void") {
+           if ((!defined($parameters{$param}) || $parameters{$param} eq "") && 
$param ne "void") {
                $parameters{$param} = "-- undescribed --";
                print STDERR "warning: $lineno: Function parameter '$param' not 
described in '$function_name'\n";
            }
diff --git a/doc/scripts/sort2.pl b/doc/scripts/sort2.pl
index 171bab7..485c20f 100755
--- a/doc/scripts/sort2.pl
+++ b/doc/scripts/sort2.pl
@@ -7,11 +7,19 @@ sub key_of_record {
 
   # Split record into lines:
   my @lines = split /\n/, $record;
+  my $max = @lines;
+  if ($max > 5) {
+    $max = 5;
+  }
+  
+  if ($max < 2) {
+    return "";
+  }
 
   my ($i) = 1;
   my ($key) = $lines[$i];
 
-  while( !($key =~ /address@hidden/) && ($i < 5)) { $i=$i+1; $key = 
$lines[$i]; }
+  while( !($key =~ /address@hidden/) && ($i < $max)) { $i=$i+1; $key = 
$lines[$i]; }
 
   $key = $1 if $key =~ /address@hidden {.*} {(.*)}/;
 
@@ -20,7 +28,7 @@ sub key_of_record {
   return $key;
 }
 
-$/="@end deftypefun";          # Records are separated by blank lines.
+$/="address@hidden deftypefun";          # Records are separated by blank 
lines.
 @records = <>;  # Read in whole file, one record per array element.
 
 @records = sort { key_of_record($a) cmp key_of_record($b) } @records;
diff --git a/gl/time.h b/gl/time.h
deleted file mode 100644
index b4aaf35..0000000
--- a/gl/time.h
+++ /dev/null
@@ -1,564 +0,0 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A more-standard <time.h>.
-
-   Copyright (C) 2007-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#if __GNUC__ >= 3
-#pragma GCC system_header
-#endif
-
-#ifdef __cplusplus
-# define restrict
-#endif
-
-/* Don't get in the way of glibc when it includes time.h merely to
-   declare a few standard symbols, rather than to declare all the
-   symbols.  Also, Solaris 8 <time.h> eventually includes itself
-   recursively; if that is happening, just include the system <time.h>
-   without adding our own declarations.  */
-#if (defined __need_time_t || defined __need_clock_t \
-     || defined __need_timespec \
-     || defined _GL_TIME_H)
-
-# include_next <time.h>
-
-#else
-
-# define _GL_TIME_H
-
-# include_next <time.h>
-
-/* NetBSD 5.0 mis-defines NULL.  */
-# include <stddef.h>
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
-   * For providing a substitute for a function that is missing on some
-     platforms, but is declared and works fine on the platforms on which
-     it exists:
-
-       #if @GNULIB_FOO@
-       # if address@hidden@
-       _GL_FUNCDECL_SYS (foo, ...);
-       # endif
-       _GL_CXXALIAS_SYS (foo, ...);
-       _GL_CXXALIASWARN (foo);
-       #elif defined GNULIB_POSIXCHECK
-       ...
-       #endif
-
-   * For providing a replacement for a function that exists on all platforms,
-     but is broken/insufficient and needs to be replaced on some platforms:
-
-       #if @GNULIB_FOO@
-       # if @REPLACE_FOO@
-       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-       #   undef foo
-       #   define foo rpl_foo
-       #  endif
-       _GL_FUNCDECL_RPL (foo, ...);
-       _GL_CXXALIAS_RPL (foo, ...);
-       # else
-       _GL_CXXALIAS_SYS (foo, ...);
-       # endif
-       _GL_CXXALIASWARN (foo);
-       #elif defined GNULIB_POSIXCHECK
-       ...
-       #endif
-
-   * For providing a replacement for a function that exists on some platforms
-     but is broken/insufficient and needs to be replaced on some of them and
-     is additionally either missing or undeclared on some other platforms:
-
-       #if @GNULIB_FOO@
-       # if @REPLACE_FOO@
-       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-       #   undef foo
-       #   define foo rpl_foo
-       #  endif
-       _GL_FUNCDECL_RPL (foo, ...);
-       _GL_CXXALIAS_RPL (foo, ...);
-       # else
-       #  if address@hidden@   or   if address@hidden@
-       _GL_FUNCDECL_SYS (foo, ...);
-       #  endif
-       _GL_CXXALIAS_SYS (foo, ...);
-       # endif
-       _GL_CXXALIASWARN (foo);
-       #elif defined GNULIB_POSIXCHECK
-       ...
-       #endif
-*/
-
-/* _GL_EXTERN_C declaration;
-   performs the declaration with C linkage.  */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
-   declares a replacement function, named rpl_func, with the given prototype,
-   consisting of return type, parameters, and attributes.
-   Example:
-     _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
-                                  _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
-  _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
-  _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
-   declares the system function, named func, with the given prototype,
-   consisting of return type, parameters, and attributes.
-   Example:
-     _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
-                                  _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
-  _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
-   declares a C++ alias called GNULIB_NAMESPACE::func
-   that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
-   Example:
-     _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
-  _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
-    namespace GNULIB_NAMESPACE                                \
-    {                                                         \
-      rettype (*const func) parameters = ::rpl_func;          \
-    }                                                         \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
-   is like  _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
-   except that the C function rpl_func may have a slightly different
-   declaration.  A cast is used to silence the "invalid conversion" error
-   that would otherwise occur.  */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
-    namespace GNULIB_NAMESPACE                                     \
-    {                                                              \
-      rettype (*const func) parameters =                           \
-        reinterpret_cast<rettype(*)parameters>(::rpl_func);        \
-    }                                                              \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
-   declares a C++ alias called GNULIB_NAMESPACE::func
-   that redirects to the system provided function func, if GNULIB_NAMESPACE
-   is defined.
-   Example:
-     _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-  /* If we were to write
-       rettype (*const func) parameters = ::func;
-     like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
-     better (remove an indirection through a 'static' pointer variable),
-     but then the _GL_CXXALIASWARN macro below would cause a warning not only
-     for uses of ::func but also for uses of GNULIB_NAMESPACE::func.  */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
-    namespace GNULIB_NAMESPACE                     \
-    {                                              \
-      static rettype (*func) parameters = ::func;  \
-    }                                              \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
-   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
-   except that the C function func may have a slightly different declaration.
-   A cast is used to silence the "invalid conversion" error that would
-   otherwise occur.  */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
-    namespace GNULIB_NAMESPACE                          \
-    {                                                   \
-      static rettype (*func) parameters =               \
-        reinterpret_cast<rettype(*)parameters>(::func); \
-    }                                                   \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
-   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
-   except that the C function is picked among a set of overloaded functions,
-   namely the one with rettype2 and parameters2.  Two consecutive casts
-   are used to silence the "cannot find a match" and "invalid conversion"
-   errors that would otherwise occur.  */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-  /* The outer cast must be a reinterpret_cast.
-     The inner cast: When the function is defined as a set of overloaded
-     functions, it works as a static_cast<>, choosing the designated variant.
-     When the function is defined as a single variant, it works as a
-     reinterpret_cast<>. The parenthesized cast syntax works both ways.  */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
-    namespace GNULIB_NAMESPACE                                                \
-    {                                                                         \
-      static rettype (*func) parameters =                                     \
-        reinterpret_cast<rettype(*)parameters>(                               \
-          (rettype2(*)parameters2)(::func));                                  \
-    }                                                                         \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
-   causes a warning to be emitted when ::func is used but not when
-   GNULIB_NAMESPACE::func is used.  func must be defined without overloaded
-   variants.  */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
-   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
-   _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
-   we enable the warning only when not optimizing.  */
-# if !__OPTIMIZE__
-#  define _GL_CXXALIASWARN_2(func,namespace) \
-    _GL_WARN_ON_USE (func, \
-                     "The symbol ::" #func " refers to the system function. " \
-                     "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-#  define _GL_CXXALIASWARN_2(func,namespace) \
-     extern __typeof__ (func) func
-# else
-#  define _GL_CXXALIASWARN_2(func,namespace) \
-     _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
-   causes a warning to be emitted when the given overloaded variant of ::func
-   is used but not when GNULIB_NAMESPACE::func is used.  */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
-   _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
-                        GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) 
\
-   _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
-   we enable the warning only when not optimizing.  */
-# if !__OPTIMIZE__
-#  define 
_GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
-    _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
-                         "The symbol ::" #func " refers to the system 
function. " \
-                         "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-#  define 
_GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
-     extern __typeof__ (func) func
-# else
-#  define 
_GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
-     _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
-    _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here.  */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
-   that the values passed as arguments n, ..., m must be non-NULL pointers.
-   n = 1 stands for the first argument, n = 2 for the second argument etc.  */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-#  define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-#  define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here.  */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later.  */
-#  define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function.  */
-#  define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported.  */
-#  define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
-   is like _GL_WARN_ON_USE (function, "string"), except that the function is
-   declared with the given prototype, consisting of return type, parameters,
-   and attributes.
-   This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
-   not work in this case.  */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
-     __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function.  */
-#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported.  */
-#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
-   performs the declaration with C linkage.  */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-#  define _GL_WARN_EXTERN_C extern "C"
-# else
-#  define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
-   Or they define it with the wrong member names or define it in <sys/time.h>
-   (e.g., FreeBSD circa 1997).  Stock Mingw does not define it, but the
-   pthreads-win32 library defines it in <pthread.h>.  */
-# if ! 1
-#  if 0
-#   include <sys/time.h>
-#  elif 0
-#   include <pthread.h>
-/* The pthreads-win32 <pthread.h> also defines a couple of broken macros.  */
-#   undef asctime_r
-#   undef ctime_r
-#   undef gmtime_r
-#   undef localtime_r
-#   undef rand_r
-#   undef strtok_r
-#  else
-
-#   ifdef __cplusplus
-extern "C" {
-#   endif
-
-#   if !GNULIB_defined_struct_timespec
-#    undef timespec
-#    define timespec rpl_timespec
-struct timespec
-{
-  time_t tv_sec;
-  long int tv_nsec;
-};
-#    define GNULIB_defined_struct_timespec 1
-#   endif
-
-#   ifdef __cplusplus
-}
-#   endif
-
-#  endif
-# endif
-
-# if !GNULIB_defined_struct_time_t_must_be_integral
-/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
-   time_t to be an integer type, even though C99 permits floating
-   point.  We don't know of any implementation that uses floating
-   point, and it is much easier to write code that doesn't have to
-   worry about that corner case, so we force the issue.  */
-struct __time_t_must_be_integral {
-  unsigned int __floating_time_t_unsupported : (time_t) 1;
-};
-#  define GNULIB_defined_struct_time_t_must_be_integral 1
-# endif
-
-/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
-   return -1 and store the remaining time into RMTP.  See
-   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
-# if 0
-#  if GNULIB_PORTCHECK
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    define nanosleep rpl_nanosleep
-#   endif
-_GL_FUNCDECL_RPL (nanosleep, int,
-                  (struct timespec const *__rqtp, struct timespec *__rmtp)
-                  _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (nanosleep, int,
-                  (struct timespec const *__rqtp, struct timespec *__rmtp));
-#  else
-#   if ! 1
-_GL_FUNCDECL_SYS (nanosleep, int,
-                  (struct timespec const *__rqtp, struct timespec *__rmtp)
-                  _GL_ARG_NONNULL ((1)));
-#   endif
-_GL_CXXALIAS_SYS (nanosleep, int,
-                  (struct timespec const *__rqtp, struct timespec *__rmtp));
-#  endif
-_GL_CXXALIASWARN (nanosleep);
-# endif
-
-/* Return the 'time_t' representation of TP and normalize TP.  */
-# if 0
-#  if GNULIB_PORTCHECK
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    define mktime rpl_mktime
-#   endif
-_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
-#  else
-_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
-#  endif
-_GL_CXXALIASWARN (mktime);
-# endif
-
-/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
-   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
-   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
-# if 1
-#  if 0
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    undef localtime_r
-#    define localtime_r rpl_localtime_r
-#   endif
-_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
-                                             struct tm *restrict __result)
-                                            _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
-                                             struct tm *restrict __result));
-#  else
-#   if ! 0
-_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
-                                             struct tm *restrict __result)
-                                            _GL_ARG_NONNULL ((1, 2)));
-#   endif
-_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
-                                             struct tm *restrict __result));
-#  endif
-#  if 0
-_GL_CXXALIASWARN (localtime_r);
-#  endif
-#  if 0
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    undef gmtime_r
-#    define gmtime_r rpl_gmtime_r
-#   endif
-_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
-                                          struct tm *restrict __result)
-                                         _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
-                                          struct tm *restrict __result));
-#  else
-#   if ! 0
-_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
-                                          struct tm *restrict __result)
-                                         _GL_ARG_NONNULL ((1, 2)));
-#   endif
-_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
-                                          struct tm *restrict __result));
-#  endif
-#  if 0
-_GL_CXXALIASWARN (gmtime_r);
-#  endif
-# endif
-
-/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
-   the resulting broken-down time into TM.  See
-   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
-# if 0
-#  if ! 1
-_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
-                                     char const *restrict __format,
-                                     struct tm *restrict __tm)
-                                    _GL_ARG_NONNULL ((1, 2, 3)));
-#  endif
-_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
-                                     char const *restrict __format,
-                                     struct tm *restrict __tm));
-_GL_CXXALIASWARN (strptime);
-# endif
-
-/* Convert TM to a time_t value, assuming UTC.  */
-# if 0
-#  if GNULIB_PORTCHECK
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    undef timegm
-#    define timegm rpl_timegm
-#   endif
-_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
-#  else
-#   if ! 1
-_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
-#   endif
-_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
-#  endif
-_GL_CXXALIASWARN (timegm);
-# endif
-
-/* Encourage applications to avoid unsafe functions that can overrun
-   buffers when given outlandish struct tm values.  Portable
-   applications should use strftime (or even sprintf) instead.  */
-# if defined GNULIB_POSIXCHECK
-#  undef asctime
-_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
-                 "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-#  undef asctime_r
-_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
-                 "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-#  undef ctime
-_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
-                 "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-#  undef ctime_r
-_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
-                 "better use strftime (or even sprintf) instead");
-# endif
-
-#endif
diff --git a/guile/modules/gnutls/build/enums.scm 
b/guile/modules/gnutls/build/enums.scm
index 8f53d8e..93293f2 100644
--- a/guile/modules/gnutls/build/enums.scm
+++ b/guile/modules/gnutls/build/enums.scm
@@ -331,7 +331,7 @@
 
 (define %compression-method-enum
   (make-enum-type 'compression-method "gnutls_compression_method_t"
-                  '(null deflate lzo)
+                  '(null deflate)
                   "gnutls_compression_get_name"
                   "GNUTLS_COMP_"))
 
@@ -516,7 +516,6 @@ unknown-pk-algorithm
 init-libextra
 library-version-mismatch
 no-temporary-rsa-params
-lzo-init-failed
 no-compression-algorithms
 no-cipher-suites
 openpgp-getkey-failed
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f8dac67..982ae6e 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -23,7 +23,7 @@
 
 ACLOCAL_AMFLAGS = -I ../m4 -I ../gl/m4
 
-SUBDIRS = includes x509
+SUBDIRS = includes x509 accelerated
 if ENABLE_MINITASN1
 SUBDIRS += minitasn1
 endif
@@ -121,6 +121,7 @@ libgnutls_la_LDFLAGS = -no-undefined \
        -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
 libgnutls_la_LIBADD = ../gl/libgnu.la x509/libgnutls_x509.la \
+       accelerated/libaccelerated.la \
        $(LTLIBZ)  $(LTLIBINTL) $(LIBSOCKET)
 
 if ENABLE_OPENPGP
diff --git a/lib/gcrypt/Makefile.am b/lib/accelerated/Makefile.am
similarity index 75%
copy from lib/gcrypt/Makefile.am
copy to lib/accelerated/Makefile.am
index d01559b..6cccae5 100644
--- a/lib/gcrypt/Makefile.am
+++ b/lib/accelerated/Makefile.am
@@ -1,8 +1,8 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Free Software
+# Copyright (C) 2011 Free Software
 # Foundation, Inc.
 #
-# Author: Nikos Mavroyanopoulos
+# Author: Nikos Mavrogiannopoulos
 #
 # This file is part of GNUTLS.
 #
@@ -22,6 +22,7 @@
 # MA 02110-1301, USA
 
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
+SUBDIRS = 
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
        -I$(srcdir)/../includes         \
@@ -32,6 +33,14 @@ if ENABLE_MINITASN1
 AM_CPPFLAGS += -I$(srcdir)/../minitasn1
 endif
 
-noinst_LTLIBRARIES = libcrypto.la
+noinst_LTLIBRARIES = libaccelerated.la
 
-libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c
+EXTRA_DIST = x86.h accelerated.h
+libaccelerated_la_SOURCES = accelerated.c
+libaccelerated_la_LIBADD =
+
+if TRY_X86_OPTIMIZATIONS
+SUBDIRS += intel
+AM_CFLAGS += -DTRY_X86_OPTIMIZATIONS
+libaccelerated_la_LIBADD += intel/libintel.la
+endif
diff --git a/lib/accelerated/accelerated.c b/lib/accelerated/accelerated.c
new file mode 100644
index 0000000..a25c57b
--- /dev/null
+++ b/lib/accelerated/accelerated.c
@@ -0,0 +1,14 @@
+#include <accelerated.h>
+#ifdef TRY_X86_OPTIMIZATIONS
+# include <intel/aes-x86.h>
+#endif
+
+void _gnutls_register_accel_crypto(void)
+{
+
+#ifdef TRY_X86_OPTIMIZATIONS
+  register_x86_crypto ();
+#endif
+
+  return;
+}
diff --git a/lib/accelerated/accelerated.h b/lib/accelerated/accelerated.h
new file mode 100644
index 0000000..1fccccb
--- /dev/null
+++ b/lib/accelerated/accelerated.h
@@ -0,0 +1 @@
+void _gnutls_register_accel_crypto(void);
diff --git a/lib/nettle/Makefile.am b/lib/accelerated/intel/Makefile.am
similarity index 58%
copy from lib/nettle/Makefile.am
copy to lib/accelerated/intel/Makefile.am
index e902e77..f57b098 100644
--- a/lib/nettle/Makefile.am
+++ b/lib/accelerated/intel/Makefile.am
@@ -1,8 +1,8 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Free Software
+# Copyright (C) 2011 Free Software
 # Foundation, Inc.
 #
-# Author: Nikos Mavroyanopoulos
+# Author: Nikos Mavrogiannopoulos
 #
 # This file is part of GNUTLS.
 #
@@ -23,15 +23,34 @@
 
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
-       -I$(srcdir)/../../gl            \
-       -I$(srcdir)/../includes         \
-       -I$(builddir)/../includes       \
-       -I$(srcdir)/..
+       -I$(srcdir)/../../../gl         \
+       -I$(srcdir)/../../includes      \
+       -I$(srcdir)/../../ \
+       -I$(srcdir)/../
 
 if ENABLE_MINITASN1
-AM_CPPFLAGS += -I$(srcdir)/../minitasn1
+AM_CPPFLAGS += -I$(srcdir)/../../minitasn1
 endif
 
-noinst_LTLIBRARIES = libcrypto.la
+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
+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
+else
+libintel_la_LIBADD += x86_iaesx86.o
+endif
 
-libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c egd.c egd.h
diff --git a/lib/accelerated/intel/README b/lib/accelerated/intel/README
new file mode 100644
index 0000000..187242b
--- /dev/null
+++ b/lib/accelerated/intel/README
@@ -0,0 +1,3 @@
+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.
+
diff --git a/lib/accelerated/intel/aes-x86.c b/lib/accelerated/intel/aes-x86.c
new file mode 100644
index 0000000..df4a49b
--- /dev/null
+++ b/lib/accelerated/intel/aes-x86.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2011, Free Software Foundation
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA
+ *
+ * The following code is an implementation of the AES-128-CBC cipher
+ * using intel's AES instruction set. It is based on Intel reference
+ * code.
+ */
+
+#include <gnutls_errors.h>
+#include <gnutls_int.h>
+#include <gnutls/crypto.h>
+#include <gnutls_errors.h>
+#include <aes-x86.h>
+#include <x86.h>
+#include "iaes_asm_interface.h"
+
+#ifdef __GNUC__
+# 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;
+};
+
+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)
+    return GNUTLS_E_INVALID_REQUEST;
+
+  *_ctx = gnutls_calloc (1, sizeof (struct aes_ctx));
+  if (*_ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ctx = *_ctx;
+
+  return 0;
+}
+
+static int
+aes_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
+{
+struct aes_ctx *ctx = _ctx;
+
+  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);
+
+  ctx->keysize = keysize;
+
+  return 0;
+}
+
+static int
+aes_setiv (void *_ctx, const void *iv, size_t iv_size)
+{
+  struct aes_ctx *ctx = _ctx;
+
+  memcpy (ctx->iv, iv, 16);
+  return 0;
+}
+
+static int
+aes_encrypt (void *_ctx, const void *plain, size_t plainsize,
+                   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);
+
+  return 0;
+}
+
+static int
+aes_decrypt (void *_ctx, const void *encr, size_t encrsize,
+                   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;
+
+  ctx->dec(&aesData);
+
+  return 0;
+}
+
+static void
+aes_deinit (void *_ctx)
+{
+  gnutls_free (_ctx);
+}
+
+static const gnutls_crypto_cipher_st cipher_struct = {
+  .init = aes_cipher_init,
+  .setkey = aes_cipher_setkey,
+  .setiv = aes_setiv,
+  .encrypt = aes_encrypt,
+  .decrypt = aes_decrypt,
+  .deinit = aes_deinit,
+};
+
+static unsigned check_optimized_aes(void)
+{
+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;
+}
diff --git a/lib/accelerated/intel/aes-x86.h b/lib/accelerated/intel/aes-x86.h
new file mode 100644
index 0000000..40d6a0c
--- /dev/null
+++ b/lib/accelerated/intel/aes-x86.h
@@ -0,0 +1 @@
+void register_x86_crypto (void);
diff --git a/lib/accelerated/intel/asm/x64_iaesx64.s 
b/lib/accelerated/intel/asm/x64_iaesx64.s
new file mode 100755
index 0000000..433d177
--- /dev/null
+++ b/lib/accelerated/intel/asm/x64_iaesx64.s
@@ -0,0 +1,2054 @@
+[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.
+
+%macro linux_setup 0
+%ifdef __linux__
+       mov rcx, rdi
+       mov rdx, rsi
+%endif
+%endmacro
+
+%macro inversekey 1
+       movdqu  xmm1,%1
+       aesimc  xmm0,xmm1
+       movdqu  %1,xmm0
+%endmacro
+
+%macro aesdeclast1 1
+       aesdeclast      xmm0,%1
+%endmacro
+
+%macro aesenclast1 1
+       aesenclast      xmm0,%1
+%endmacro
+
+%macro aesdec1 1
+       aesdec  xmm0,%1
+%endmacro
+
+%macro aesenc1 1
+       aesenc  xmm0,%1
+%endmacro
+
+
+%macro aesdeclast1_u 1
+       movdqu xmm4,%1
+       aesdeclast      xmm0,xmm4
+%endmacro
+
+%macro aesenclast1_u 1
+       movdqu xmm4,%1
+       aesenclast      xmm0,xmm4
+%endmacro
+
+%macro aesdec1_u 1
+       movdqu xmm4,%1
+       aesdec  xmm0,xmm4
+%endmacro
+
+%macro aesenc1_u 1
+       movdqu xmm4,%1
+       aesenc  xmm0,xmm4
+%endmacro
+ 
+%macro aesdec4 1
+       movdqa  xmm4,%1
+
+       aesdec  xmm0,xmm4
+       aesdec  xmm1,xmm4
+       aesdec  xmm2,xmm4
+       aesdec  xmm3,xmm4
+
+%endmacro
+
+%macro aesdeclast4 1
+       movdqa  xmm4,%1
+
+       aesdeclast      xmm0,xmm4
+       aesdeclast      xmm1,xmm4
+       aesdeclast      xmm2,xmm4
+       aesdeclast      xmm3,xmm4
+
+%endmacro
+
+
+%macro aesenc4 1
+       movdqa  xmm4,%1
+
+       aesenc  xmm0,xmm4
+       aesenc  xmm1,xmm4
+       aesenc  xmm2,xmm4
+       aesenc  xmm3,xmm4
+
+%endmacro
+
+%macro aesenclast4 1
+       movdqa  xmm4,%1
+
+       aesenclast      xmm0,xmm4
+       aesenclast      xmm1,xmm4
+       aesenclast      xmm2,xmm4
+       aesenclast      xmm3,xmm4
+
+%endmacro
+
+
+%macro load_and_inc4 1
+       movdqa  xmm4,%1
+       movdqa  xmm0,xmm5
+       movdqa  xmm1,xmm5
+       paddq   xmm1,[counter_add_one wrt rip]
+       movdqa  xmm2,xmm5
+       paddq   xmm2,[counter_add_two wrt rip]
+       movdqa  xmm3,xmm5
+       paddq   xmm3,[counter_add_three wrt rip]
+       pxor    xmm0,xmm4
+       paddq   xmm5,[counter_add_four wrt rip]
+       pxor    xmm1,xmm4
+       pxor    xmm2,xmm4
+       pxor    xmm3,xmm4
+%endmacro
+
+%macro xor_with_input4 1
+       movdqu xmm4,[%1]
+       pxor xmm0,xmm4
+       movdqu xmm4,[%1+16]
+       pxor xmm1,xmm4
+       movdqu xmm4,[%1+32]
+       pxor xmm2,xmm4
+       movdqu xmm4,[%1+48]
+       pxor xmm3,xmm4
+%endmacro
+
+
+
+%macro load_and_xor4 2
+       movdqa  xmm4,%2
+       movdqu  xmm0,[%1 + 0*16]
+       pxor    xmm0,xmm4
+       movdqu  xmm1,[%1 + 1*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm2,[%1 + 2*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm3,[%1 + 3*16]
+       pxor    xmm3,xmm4
+%endmacro
+
+%macro store4 1
+       movdqu [%1 + 0*16],xmm0
+       movdqu [%1 + 1*16],xmm1
+       movdqu [%1 + 2*16],xmm2
+       movdqu [%1 + 3*16],xmm3
+%endmacro
+
+%macro copy_round_keys 3
+       movdqu xmm4,[%2 + ((%3)*16)]
+       movdqa [%1 + ((%3)*16)],xmm4
+%endmacro
+
+
+%macro key_expansion_1_192 1
+               ;; Assumes the xmm3 includes all zeros at this point. 
+        pshufd xmm2, xmm2, 11111111b        
+        shufps xmm3, xmm1, 00010000b        
+        pxor xmm1, xmm3        
+        shufps xmm3, xmm1, 10001100b
+        pxor xmm1, xmm3        
+               pxor xmm1, xmm2         
+               movdqu [rdx+%1], xmm1                   
+%endmacro
+
+; Calculate w10 and w11 using calculated w9 and known w4-w5
+%macro key_expansion_2_192 1                           
+               movdqa xmm5, xmm4
+               pslldq xmm5, 4
+               shufps xmm6, xmm1, 11110000b
+               pxor xmm6, xmm5
+               pxor xmm4, xmm6
+               pshufd xmm7, xmm4, 00001110b 
+               movdqu [rdx+%1], xmm7
+%endmacro
+
+
+section .data
+align 16
+shuffle_mask:
+DD 0FFFFFFFFh
+DD 03020100h
+DD 07060504h
+DD 0B0A0908h
+
+
+align 16
+counter_add_one:
+DD 1
+DD 0
+DD 0
+DD 0
+
+counter_add_two:
+DD 2
+DD 0
+DD 0
+DD 0
+
+counter_add_three:
+DD 3
+DD 0
+DD 0
+DD 0
+
+counter_add_four:
+DD 4
+DD 0
+DD 0
+DD 0
+
+
+
+section .text
+
+align 16
+key_expansion256:
+
+    pshufd xmm2, xmm2, 011111111b
+
+    movdqa xmm4, xmm1
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pxor xmm1, xmm2
+
+    movdqu [rdx], xmm1
+    add rdx, 0x10
+    
+    aeskeygenassist xmm4, xmm1, 0
+    pshufd xmm2, xmm4, 010101010b
+
+    movdqa xmm4, xmm3
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pxor xmm3, xmm2
+
+    movdqu [rdx], xmm3
+    add rdx, 0x10
+
+    ret
+
+
+
+align 16
+key_expansion128: 
+    pshufd xmm2, xmm2, 0xFF;
+    movdqa xmm3, xmm1
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pxor xmm1, xmm2
+
+    ; storing the result in the key schedule array
+    movdqu [rdx], xmm1
+    add rdx, 0x10                    
+    ret
+
+
+
+
+
+
+align 16
+global iEncExpandKey128
+iEncExpandKey128:
+
+               linux_setup
+
+        movdqu xmm1, [rcx]    ; loading the key
+
+        movdqu [rdx], xmm1
+
+        movdqa xmm5, [shuffle_mask wrt rip]
+
+        add rdx,16
+
+        aeskeygenassist xmm2, xmm1, 0x1     ; Generating round key 1
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
+        call key_expansion128
+
+               ret 
+
+
+
+align 16
+global iEncExpandKey192
+iEncExpandKey192:
+
+               linux_setup
+               sub rsp,64+8
+               movdqa  [rsp],xmm6
+               movdqa  [rsp+16],xmm7
+
+
+        movq xmm7, [rcx+16]    ; loading the AES key
+        movq [rdx+16], xmm7  ; Storing key in memory where all key expansion 
+        pshufd xmm4, xmm7, 01001111b
+        movdqu xmm1, [rcx]     ; loading the AES key
+        movdqu [rdx], xmm1  ; Storing key in memory where all key expansion 
+                       
+        pxor xmm3, xmm3                ; Set xmm3 to be all zeros. Required 
for the key_expansion. 
+        pxor xmm6, xmm6                ; Set xmm3 to be all zeros. Required 
for the key_expansion. 
+
+        aeskeygenassist xmm2, xmm4, 0x1     ; Complete round key 1 and 
generate round key 2 
+        key_expansion_1_192 24
+               key_expansion_2_192 40                          
+
+        aeskeygenassist xmm2, xmm4, 0x2     ; Generate round key 3 and part of 
round key 4
+        key_expansion_1_192 48
+               key_expansion_2_192 64                          
+
+        aeskeygenassist xmm2, xmm4, 0x4     ; Complete round key 4 and 
generate round key 5
+        key_expansion_1_192 72
+               key_expansion_2_192 88
+               
+        aeskeygenassist xmm2, xmm4, 0x8     ; Generate round key 6 and part of 
round key 7
+        key_expansion_1_192 96
+               key_expansion_2_192 112
+               
+        aeskeygenassist xmm2, xmm4, 0x10     ; Complete round key 7 and 
generate round key 8 
+        key_expansion_1_192 120
+               key_expansion_2_192 136                         
+
+        aeskeygenassist xmm2, xmm4, 0x20     ; Generate round key 9 and part 
of round key 10
+        key_expansion_1_192 144
+               key_expansion_2_192 160                         
+
+        aeskeygenassist xmm2, xmm4, 0x40     ; Complete round key 10 and 
generate round key 11
+        key_expansion_1_192 168
+               key_expansion_2_192 184                         
+
+        aeskeygenassist xmm2, xmm4, 0x80     ; Generate round key 12
+        key_expansion_1_192 192
+
+
+               movdqa  xmm6,[rsp]
+               movdqa  xmm7,[rsp+16]
+               add rsp,64+8
+
+               ret 
+
+
+
+
+align 16
+global iDecExpandKey128
+iDecExpandKey128:
+
+       linux_setup
+       push rcx
+       push rdx
+       sub rsp,16+8
+
+       call iEncExpandKey128
+
+       add rsp,16+8
+       pop rdx
+       pop rcx
+
+       inversekey [rdx + 1*16]
+       inversekey [rdx + 2*16]
+       inversekey [rdx + 3*16]
+       inversekey [rdx + 4*16]
+       inversekey [rdx + 5*16]
+       inversekey [rdx + 6*16]
+       inversekey [rdx + 7*16]
+       inversekey [rdx + 8*16]
+       inversekey [rdx + 9*16]
+
+       ret
+
+
+align 16
+global iDecExpandKey192
+iDecExpandKey192:
+
+       linux_setup
+       push rcx
+       push rdx
+       sub rsp,16+8
+
+       call iEncExpandKey192
+
+       add rsp,16+8
+       pop rdx
+       pop rcx
+
+       
+       inversekey [rdx + 1*16]
+       inversekey [rdx + 2*16]
+       inversekey [rdx + 3*16]
+       inversekey [rdx + 4*16]
+       inversekey [rdx + 5*16]
+       inversekey [rdx + 6*16]
+       inversekey [rdx + 7*16]
+       inversekey [rdx + 8*16]
+       inversekey [rdx + 9*16]
+       inversekey [rdx + 10*16]
+       inversekey [rdx + 11*16]
+
+       ret
+
+
+
+align 16
+global iDecExpandKey256
+iDecExpandKey256:
+
+       linux_setup
+       push rcx
+       push rdx
+       sub rsp,16+8
+
+       call iEncExpandKey256
+
+       add rsp,16+8
+       pop rdx
+       pop rcx
+
+       inversekey [rdx + 1*16]
+       inversekey [rdx + 2*16]
+       inversekey [rdx + 3*16]
+       inversekey [rdx + 4*16]
+       inversekey [rdx + 5*16]
+       inversekey [rdx + 6*16]
+       inversekey [rdx + 7*16]
+       inversekey [rdx + 8*16]
+       inversekey [rdx + 9*16]
+       inversekey [rdx + 10*16]
+       inversekey [rdx + 11*16]
+       inversekey [rdx + 12*16]
+       inversekey [rdx + 13*16]
+
+       ret
+       
+
+       
+       
+align 16
+global iEncExpandKey256
+iEncExpandKey256:
+
+       linux_setup
+
+    movdqu xmm1, [rcx]    ; loading the key
+    movdqu xmm3, [rcx+16]
+    movdqu [rdx], xmm1  ; Storing key in memory where all key schedule will be 
stored
+    movdqu [rdx+16], xmm3 
+    
+    add rdx,32
+
+    movdqa xmm5, [shuffle_mask wrt rip]  ; this mask is used by key_expansion
+
+    aeskeygenassist xmm2, xmm3, 0x1     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x2     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x4     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x8     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x10    ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x20    ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x40    ; 
+;    call key_expansion256 
+
+    pshufd xmm2, xmm2, 011111111b
+
+    movdqa xmm4, xmm1
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pxor xmm1, xmm2
+
+    movdqu [rdx], xmm1
+
+
+       ret 
+       
+       
+       
+
+
+
+align 16
+global iDec128
+iDec128:
+
+       linux_setup
+       sub rsp,16*16+8
+
+
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+       test eax,eax
+       jz end_dec128
+
+       cmp eax,4
+       jl      lp128decsingle
+
+       test    rcx,0xf
+       jz              lp128decfour
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       mov rcx,rsp     
+       
+       
+
+align 16
+lp128decfour:
+       
+       test eax,eax
+       jz end_dec128
+
+       cmp eax,4
+       jl      lp128decsingle
+
+       load_and_xor4 rdx, [rcx+10*16]
+       add rdx,16*4
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+       
+       sub eax,4
+       store4 r8+rdx-(16*4)
+       jmp lp128decfour
+
+
+       align 16
+lp128decsingle:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+10*16]
+       pxor xmm0, xmm4
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+       add rdx, 16
+       movdqu  [r8 + rdx - 16], xmm0
+       dec eax
+       jnz lp128decsingle
+
+end_dec128:
+
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iDec128_CBC
+iDec128_CBC:
+       
+       linux_setup
+       sub rsp,16*16+8
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu  xmm5,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_dec128_CBC
+
+       cmp eax,4
+       jl      lp128decsingle_CBC
+
+       test    rcx,0xf
+       jz              lp128decfour_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       mov rcx,rsp     
+
+
+align 16
+lp128decfour_CBC:
+       
+       test eax,eax
+       jz end_dec128_CBC
+
+       cmp eax,4
+       jl      lp128decsingle_CBC
+
+       load_and_xor4 rdx, [rcx+10*16]
+       add rdx,16*4
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[rdx - 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[rdx - 16*4 + 3*16]
+       
+       sub eax,4
+       store4 r8+rdx-(16*4)
+       jmp lp128decfour_CBC
+
+
+       align 16
+lp128decsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqa  xmm1,xmm0
+       movdqu xmm4,[rcx+10*16]
+       pxor xmm0, xmm4
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       add rdx, 16
+       movdqu  [r8 + rdx - 16], xmm0
+       dec eax
+       jnz lp128decsingle_CBC
+
+end_dec128_CBC:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iDec192_CBC
+iDec192_CBC:
+
+       linux_setup
+       sub rsp,16*16+8
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu  xmm5,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       
+       sub r8,rdx
+
+       test eax,eax
+       jz end_dec192_CBC
+
+       cmp eax,4
+       jl      lp192decsingle_CBC
+
+       test    rcx,0xf
+       jz              lp192decfour_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       mov rcx,rsp     
+
+
+align 16
+lp192decfour_CBC:
+       
+       test eax,eax
+       jz end_dec192_CBC
+
+       cmp eax,4
+       jl      lp192decsingle_CBC
+
+       load_and_xor4 rdx, [rcx+12*16]
+       add rdx,16*4
+       aesdec4 [rcx+11*16]
+       aesdec4 [rcx+10*16]
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[rdx - 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[rdx - 16*4 + 3*16]
+       
+       sub eax,4
+       store4 r8+rdx-(16*4)
+       jmp lp192decfour_CBC
+
+
+       align 16
+lp192decsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+12*16]
+       movdqa  xmm1,xmm0
+       pxor xmm0, xmm4
+       aesdec1_u [rcx+11*16]
+       aesdec1_u [rcx+10*16]
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       add rdx, 16
+       movdqu  [r8 + rdx - 16], xmm0
+       dec eax
+       jnz lp192decsingle_CBC
+
+end_dec192_CBC:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+
+
+align 16
+global iDec256_CBC
+iDec256_CBC:
+
+       linux_setup
+       sub rsp,16*16+8
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu  xmm5,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       
+       sub r8,rdx
+
+       test eax,eax
+       jz end_dec256_CBC
+
+       cmp eax,4
+       jl      lp256decsingle_CBC
+
+       test    rcx,0xf
+       jz              lp256decfour_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       copy_round_keys rsp,rcx,13
+       copy_round_keys rsp,rcx,14
+       mov rcx,rsp     
+
+align 16
+lp256decfour_CBC:
+       
+       test eax,eax
+       jz end_dec256_CBC
+
+       cmp eax,4
+       jl      lp256decsingle_CBC
+
+       load_and_xor4 rdx, [rcx+14*16]
+       add rdx,16*4
+       aesdec4 [rcx+13*16]
+       aesdec4 [rcx+12*16]
+       aesdec4 [rcx+11*16]
+       aesdec4 [rcx+10*16]
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[rdx - 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[rdx - 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[rdx - 16*4 + 3*16]
+       
+       sub eax,4
+       store4 r8+rdx-(16*4)
+       jmp lp256decfour_CBC
+
+
+       align 16
+lp256decsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+14*16]
+       movdqa  xmm1,xmm0
+       pxor xmm0, xmm4
+       aesdec1_u [rcx+13*16]
+       aesdec1_u [rcx+12*16]
+       aesdec1_u [rcx+11*16]
+       aesdec1_u [rcx+10*16]
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       add rdx, 16
+       movdqu  [r8 + rdx - 16], xmm0
+       dec eax
+       jnz lp256decsingle_CBC
+
+end_dec256_CBC:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+
+
+
+align 16
+global iDec192
+iDec192:
+
+       linux_setup
+       sub rsp,16*16+8
+
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+       
+       test eax,eax
+       jz end_dec192
+
+       cmp eax,4
+       jl      lp192decsingle
+       
+       test    rcx,0xf
+       jz              lp192decfour
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       mov rcx,rsp     
+
+align 16
+lp192decfour:
+       
+       test eax,eax
+       jz end_dec192
+
+       cmp eax,4
+       jl      lp192decsingle
+
+       load_and_xor4 rdx, [rcx+12*16]
+       add rdx,16*4
+       aesdec4 [rcx+11*16]
+       aesdec4 [rcx+10*16]
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+       
+       sub eax,4
+       store4 r8+rdx-(16*4)
+       jmp lp192decfour
+
+
+       align 16
+lp192decsingle:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+12*16]
+       pxor xmm0, xmm4
+       aesdec1_u [rcx+11*16]
+       aesdec1_u [rcx+10*16]
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+       add rdx, 16
+       movdqu  [r8 + rdx - 16], xmm0
+       dec eax
+       jnz lp192decsingle
+
+end_dec192:
+
+       add rsp,16*16+8
+       ret
+
+
+
+
+align 16
+global iDec256
+iDec256:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_dec256
+       
+       cmp eax,4
+       jl lp256dec
+
+       test    rcx,0xf
+       jz              lp256dec4
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       copy_round_keys rsp,rcx,13
+       copy_round_keys rsp,rcx,14
+       mov rcx,rsp     
+
+       
+       align 16
+lp256dec4:     
+       test eax,eax
+       jz end_dec256
+       
+       cmp eax,4
+       jl lp256dec
+       
+       load_and_xor4 rdx,[rcx+14*16]
+       add rdx, 4*16
+       aesdec4 [rcx+13*16]
+       aesdec4 [rcx+12*16]
+       aesdec4 [rcx+11*16]
+       aesdec4 [rcx+10*16]
+       aesdec4 [rcx+9*16]
+       aesdec4 [rcx+8*16]
+       aesdec4 [rcx+7*16]
+       aesdec4 [rcx+6*16]
+       aesdec4 [rcx+5*16]
+       aesdec4 [rcx+4*16]
+       aesdec4 [rcx+3*16]
+       aesdec4 [rcx+2*16]
+       aesdec4 [rcx+1*16]
+       aesdeclast4 [rcx+0*16]
+
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lp256dec4   
+       
+       align 16
+lp256dec:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+14*16]
+       add rdx, 16
+       pxor xmm0, xmm4                    ; Round 0 (only xor)
+       aesdec1_u [rcx+13*16]
+       aesdec1_u [rcx+12*16]
+       aesdec1_u [rcx+11*16]
+       aesdec1_u [rcx+10*16]
+       aesdec1_u [rcx+9*16]
+       aesdec1_u [rcx+8*16]
+       aesdec1_u [rcx+7*16]
+       aesdec1_u [rcx+6*16]
+       aesdec1_u [rcx+5*16]
+       aesdec1_u [rcx+4*16]
+       aesdec1_u [rcx+3*16]
+       aesdec1_u [rcx+2*16]
+       aesdec1_u [rcx+1*16]
+       aesdeclast1_u [rcx+0*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp256dec
+
+end_dec256:
+       
+       add rsp,16*16+8
+       ret
+
+
+
+
+
+
+align 16
+global iEnc128
+iEnc128:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_enc128
+       
+       cmp eax,4
+       jl lp128encsingle
+
+       test    rcx,0xf
+       jz              lpenc128four
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lpenc128four:
+       
+       test eax,eax
+       jz end_enc128
+       
+       cmp eax,4
+       jl lp128encsingle
+
+       load_and_xor4 rdx,[rcx+0*16]
+       add rdx,4*16
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenclast4     [rcx+10*16]
+       
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lpenc128four
+       
+       align 16
+lp128encsingle:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]     
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenclast1_u [rcx+10*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp128encsingle
+
+end_enc128:
+
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iEnc128_CTR
+iEnc128_CTR:
+
+       linux_setup
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm5,[rax]
+
+
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_encctr128
+       
+       cmp eax,4
+       jl lp128encctrsingle
+
+       test    rcx,0xf
+       jz              lpencctr128four
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lpencctr128four:
+       
+       test eax,eax
+       jz end_encctr128
+       
+       cmp eax,4
+       jl lp128encctrsingle
+
+       load_and_inc4 [rcx+0*16]
+       add rdx,4*16
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenclast4     [rcx+10*16]
+       xor_with_input4 rdx-(4*16)
+       
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lpencctr128four
+       
+       align 16
+lp128encctrsingle:
+
+       movdqa xmm0,xmm5
+       paddq   xmm5,[counter_add_one wrt rip]
+       add rdx, 16
+       movdqu xmm4,[rcx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]     
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenclast1_u [rcx+10*16]
+       movdqu xmm4, [rdx-16]
+       pxor  xmm0,xmm4
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp128encctrsingle
+
+end_encctr128:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+
+align 16
+global iEnc192_CTR
+iEnc192_CTR:
+
+       linux_setup
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm5,[rax]
+
+
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_encctr192
+       
+       cmp eax,4
+       jl lp192encctrsingle
+
+       test    rcx,0xf
+       jz              lpencctr192four
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lpencctr192four:
+       
+       test eax,eax
+       jz end_encctr192
+       
+       cmp eax,4
+       jl lp192encctrsingle
+
+       load_and_inc4 [rcx+0*16]
+       add rdx,4*16
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenc4 [rcx+10*16]
+       aesenc4 [rcx+11*16]
+       aesenclast4     [rcx+12*16]
+       xor_with_input4 rdx-(4*16)
+       
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lpencctr192four
+       
+       align 16
+lp192encctrsingle:
+
+       movdqa xmm5,xmm0
+       movdqu xmm4,[rcx+0*16]
+       paddq   xmm5,[counter_add_one wrt rip]
+       add rdx, 16
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]     
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenc1_u [rcx+10*16]
+       aesenc1_u [rcx+11*16]
+       aesenclast1_u [rcx+12*16]
+       movdqu xmm4, [rdx]
+       pxor  xmm0,xmm4
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp192encctrsingle
+
+end_encctr192:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iEnc256_CTR
+iEnc256_CTR:
+
+       linux_setup
+
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm5,[rax]
+
+
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test eax,eax
+       jz end_encctr256
+       
+       cmp eax,4
+       jl lp256encctrsingle
+
+       test    rcx,0xf
+       jz              lpencctr256four
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       copy_round_keys rsp,rcx,13
+       copy_round_keys rsp,rcx,14
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lpencctr256four:
+       
+       test eax,eax
+       jz end_encctr256
+       
+       cmp eax,4
+       jl lp256encctrsingle
+
+       load_and_inc4 [rcx+0*16]
+       add rdx,4*16
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenc4 [rcx+10*16]
+       aesenc4 [rcx+11*16]
+       aesenc4 [rcx+12*16]
+       aesenc4 [rcx+13*16]
+       aesenclast4     [rcx+14*16]
+       xor_with_input4 rdx-(4*16)
+       
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lpencctr256four
+       
+       align 16
+lp256encctrsingle:
+
+       movdqa xmm5,xmm0
+       movdqu xmm4,[rcx+0*16]
+       paddq   xmm5,[counter_add_one wrt rip]
+       add rdx, 16
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]     
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenc1_u [rcx+10*16]
+       aesenc1_u [rcx+11*16]
+       aesenc1_u [rcx+12*16]
+       aesenc1_u [rcx+13*16]
+       aesenclast1_u [rcx+14*16]
+       movdqu xmm4, [rdx]
+       pxor  xmm0,xmm4
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp256encctrsingle
+
+end_encctr256:
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm5
+       add rsp,16*16+8
+       ret
+
+
+
+
+
+
+
+align 16
+global iEnc128_CBC
+iEnc128_CBC:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm1,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+
+       test    rcx,0xf
+       jz              lp128encsingle_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lp128encsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4,[rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm1
+       pxor xmm0, xmm4
+       aesenc1 [rcx+1*16]
+       aesenc1 [rcx+2*16]
+       aesenc1 [rcx+3*16]
+       aesenc1 [rcx+4*16]     
+       aesenc1 [rcx+5*16]
+       aesenc1 [rcx+6*16]
+       aesenc1 [rcx+7*16]
+       aesenc1 [rcx+8*16]
+       aesenc1 [rcx+9*16]
+       aesenclast1 [rcx+10*16]
+       movdqa xmm1,xmm0
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp128encsingle_CBC
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm1
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iEnc192_CBC
+iEnc192_CBC:
+
+       linux_setup
+       sub rsp,16*16+8
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm1,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+       test    rcx,0xf
+       jz              lp192encsingle_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       mov rcx,rsp     
+
+
+
+       align 16        
+       
+lp192encsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4, [rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm1
+       pxor xmm0, xmm4
+       aesenc1 [rcx+1*16]
+       aesenc1 [rcx+2*16]
+       aesenc1 [rcx+3*16]
+       aesenc1 [rcx+4*16]     
+       aesenc1 [rcx+5*16]
+       aesenc1 [rcx+6*16]
+       aesenc1 [rcx+7*16]
+       aesenc1 [rcx+8*16]
+       aesenc1 [rcx+9*16]
+       aesenc1 [rcx+10*16]
+       aesenc1 [rcx+11*16]
+       aesenclast1 [rcx+12*16]
+       movdqa xmm1,xmm0
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp192encsingle_CBC
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm1
+
+       add rsp,16*16+8
+       ret
+
+
+align 16
+global iEnc256_CBC
+iEnc256_CBC:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov r9,rcx
+       mov rax,[rcx+24]
+       movdqu xmm1,[rax]
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+       test    rcx,0xf
+       jz              lp256encsingle_CBC
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       copy_round_keys rsp,rcx,13
+       copy_round_keys rsp,rcx,14
+       mov rcx,rsp     
+
+       align 16        
+       
+lp256encsingle_CBC:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4, [rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm1
+       pxor xmm0, xmm4
+       aesenc1 [rcx+1*16]
+       aesenc1 [rcx+2*16]
+       aesenc1 [rcx+3*16]
+       aesenc1 [rcx+4*16]     
+       aesenc1 [rcx+5*16]
+       aesenc1 [rcx+6*16]
+       aesenc1 [rcx+7*16]
+       aesenc1 [rcx+8*16]
+       aesenc1 [rcx+9*16]
+       aesenc1 [rcx+10*16]
+       aesenc1 [rcx+11*16]
+       aesenc1 [rcx+12*16]
+       aesenc1 [rcx+13*16]
+       aesenclast1 [rcx+14*16]
+       movdqa xmm1,xmm0
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp256encsingle_CBC
+
+       mov        r9,[r9+24]
+       movdqu [r9],xmm1
+       add rsp,16*16+8
+       ret
+
+
+
+
+align 16
+global iEnc192
+iEnc192:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+       
+       sub r8,rdx
+
+       test eax,eax
+       jz end_enc192
+       
+       cmp eax,4
+       jl lp192encsingle
+
+       test    rcx,0xf
+       jz              lpenc192four
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       mov rcx,rsp     
+
+
+       align 16        
+       
+lpenc192four:
+       
+       test eax,eax
+       jz end_enc192
+       
+       cmp eax,4
+       jl lp192encsingle
+
+       load_and_xor4 rdx,[rcx+0*16]
+       add rdx,4*16
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenc4 [rcx+10*16]
+       aesenc4 [rcx+11*16]
+       aesenclast4     [rcx+12*16]
+       
+       store4 r8+rdx-16*4
+       sub eax,4
+       jmp lpenc192four
+       
+       align 16
+lp192encsingle:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4, [rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]     
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenc1_u [rcx+10*16]
+       aesenc1_u [rcx+11*16]
+       aesenclast1_u [rcx+12*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp192encsingle
+
+end_enc192:
+
+       add rsp,16*16+8
+       ret
+
+
+
+
+
+
+align 16
+global iEnc256
+iEnc256:
+
+       linux_setup
+       sub rsp,16*16+8
+       
+       mov eax,[rcx+32] ; numblocks
+       mov rdx,[rcx]
+       mov r8,[rcx+8]
+       mov rcx,[rcx+16]
+
+       sub r8,rdx      
+
+
+       test eax,eax
+       jz end_enc256
+
+       cmp eax,4
+       jl lp256enc
+
+       test    rcx,0xf
+       jz              lp256enc4
+       
+       copy_round_keys rsp,rcx,0
+       copy_round_keys rsp,rcx,1
+       copy_round_keys rsp,rcx,2
+       copy_round_keys rsp,rcx,3
+       copy_round_keys rsp,rcx,4
+       copy_round_keys rsp,rcx,5
+       copy_round_keys rsp,rcx,6
+       copy_round_keys rsp,rcx,7
+       copy_round_keys rsp,rcx,8
+       copy_round_keys rsp,rcx,9
+       copy_round_keys rsp,rcx,10
+       copy_round_keys rsp,rcx,11
+       copy_round_keys rsp,rcx,12
+       copy_round_keys rsp,rcx,13
+       copy_round_keys rsp,rcx,14
+       mov rcx,rsp     
+
+
+       align 16
+       
+lp256enc4:
+       test eax,eax
+       jz end_enc256
+
+       cmp eax,4
+       jl lp256enc
+
+
+       load_and_xor4 rdx,[rcx+0*16]
+       add rdx, 16*4
+       aesenc4 [rcx+1*16]
+       aesenc4 [rcx+2*16]
+       aesenc4 [rcx+3*16]
+       aesenc4 [rcx+4*16]
+       aesenc4 [rcx+5*16]
+       aesenc4 [rcx+6*16]
+       aesenc4 [rcx+7*16]
+       aesenc4 [rcx+8*16]
+       aesenc4 [rcx+9*16]
+       aesenc4 [rcx+10*16]
+       aesenc4 [rcx+11*16]
+       aesenc4 [rcx+12*16]
+       aesenc4 [rcx+13*16]
+       aesenclast4 [rcx+14*16]
+
+       store4  r8+rdx-16*4
+       sub eax,4
+       jmp lp256enc4
+       
+       align 16
+lp256enc:
+
+       movdqu xmm0, [rdx]
+       movdqu xmm4, [rcx+0*16]
+       add rdx, 16
+       pxor xmm0, xmm4
+       aesenc1_u [rcx+1*16]
+       aesenc1_u [rcx+2*16]
+       aesenc1_u [rcx+3*16]
+       aesenc1_u [rcx+4*16]
+       aesenc1_u [rcx+5*16]
+       aesenc1_u [rcx+6*16]
+       aesenc1_u [rcx+7*16]
+       aesenc1_u [rcx+8*16]
+       aesenc1_u [rcx+9*16]
+       aesenc1_u [rcx+10*16]
+       aesenc1_u [rcx+11*16]
+       aesenc1_u [rcx+12*16]
+       aesenc1_u [rcx+13*16]
+       aesenclast1_u [rcx+14*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [r8+rdx-16], xmm0
+       dec eax
+       jnz lp256enc
+
+end_enc256:
+
+       add rsp,16*16+8
+       ret
diff --git a/lib/accelerated/intel/asm/x86_iaesx86.s 
b/lib/accelerated/intel/asm/x86_iaesx86.s
new file mode 100755
index 0000000..16fda3b
--- /dev/null
+++ b/lib/accelerated/intel/asm/x86_iaesx86.s
@@ -0,0 +1,2183 @@
+[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.
+
+
+%macro inversekey 1
+       movdqu  xmm1,%1
+       aesimc  xmm0,xmm1
+       movdqu  %1,xmm0
+%endmacro
+
+
+%macro aesdec4 1
+       movdqa  xmm4,%1
+
+       aesdec  xmm0,xmm4
+       aesdec  xmm1,xmm4
+       aesdec  xmm2,xmm4
+       aesdec  xmm3,xmm4
+
+%endmacro
+
+
+%macro aesdeclast4 1
+       movdqa  xmm4,%1
+
+       aesdeclast      xmm0,xmm4
+       aesdeclast      xmm1,xmm4
+       aesdeclast      xmm2,xmm4
+       aesdeclast      xmm3,xmm4
+
+%endmacro
+
+
+%macro aesenc4 1
+       movdqa  xmm4,%1
+
+       aesenc  xmm0,xmm4
+       aesenc  xmm1,xmm4
+       aesenc  xmm2,xmm4
+       aesenc  xmm3,xmm4
+
+%endmacro
+
+%macro aesenclast4 1
+       movdqa  xmm4,%1
+
+       aesenclast      xmm0,xmm4
+       aesenclast      xmm1,xmm4
+       aesenclast      xmm2,xmm4
+       aesenclast      xmm3,xmm4
+
+%endmacro
+
+
+%macro aesdeclast1 1
+       aesdeclast      xmm0,%1
+%endmacro
+
+%macro aesenclast1 1
+       aesenclast      xmm0,%1
+%endmacro
+
+%macro aesdec1 1
+       aesdec  xmm0,%1
+%endmacro
+
+;abab
+%macro aesenc1 1
+       aesenc  xmm0,%1
+%endmacro
+
+
+%macro aesdeclast1_u 1
+       movdqu xmm4,%1
+       aesdeclast      xmm0,xmm4
+%endmacro
+
+%macro aesenclast1_u 1
+       movdqu xmm4,%1
+       aesenclast      xmm0,xmm4
+%endmacro
+
+%macro aesdec1_u 1
+       movdqu xmm4,%1
+       aesdec  xmm0,xmm4
+%endmacro
+
+%macro aesenc1_u 1
+       movdqu xmm4,%1
+       aesenc  xmm0,xmm4
+%endmacro
+
+
+%macro load_and_xor4 2
+       movdqa  xmm4,%2
+       movdqu  xmm0,[%1 + 0*16]
+       pxor    xmm0,xmm4
+       movdqu  xmm1,[%1 + 1*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm2,[%1 + 2*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm3,[%1 + 3*16]
+       pxor    xmm3,xmm4
+%endmacro
+
+
+%macro load_and_inc4 1
+       movdqa  xmm4,%1
+       movdqa  xmm0,xmm5
+       movdqa  xmm1,xmm5
+       paddq   xmm1,[counter_add_one]
+       movdqa  xmm2,xmm5
+       paddq   xmm2,[counter_add_two]
+       movdqa  xmm3,xmm5
+       paddq   xmm3,[counter_add_three]
+       pxor    xmm0,xmm4
+       paddq   xmm5,[counter_add_four]
+       pxor    xmm1,xmm4
+       pxor    xmm2,xmm4
+       pxor    xmm3,xmm4
+%endmacro
+
+%macro xor_with_input4 1
+       movdqu xmm4,[%1]
+       pxor xmm0,xmm4
+       movdqu xmm4,[%1+16]
+       pxor xmm1,xmm4
+       movdqu xmm4,[%1+32]
+       pxor xmm2,xmm4
+       movdqu xmm4,[%1+48]
+       pxor xmm3,xmm4
+%endmacro
+
+%macro store4 1
+       movdqu [%1 + 0*16],xmm0
+       movdqu [%1 + 1*16],xmm1
+       movdqu [%1 + 2*16],xmm2
+       movdqu [%1 + 3*16],xmm3
+%endmacro
+
+
+%macro copy_round_keys 3
+       movdqu xmm4,[%2 + ((%3)*16)]
+       movdqa [%1 + ((%3)*16)],xmm4
+%endmacro
+
+;abab
+%macro copy_round_keyx 3
+       movdqu xmm4,[%2 + ((%3)*16)]
+       movdqa %1,xmm4
+%endmacro
+
+
+
+%macro key_expansion_1_192 1
+               ;; Assumes the xmm3 includes all zeros at this point. 
+        pshufd xmm2, xmm2, 11111111b        
+        shufps xmm3, xmm1, 00010000b        
+        pxor xmm1, xmm3        
+        shufps xmm3, xmm1, 10001100b
+        pxor xmm1, xmm3        
+               pxor xmm1, xmm2         
+               movdqu [edx+%1], xmm1                   
+%endmacro
+
+; Calculate w10 and w11 using calculated w9 and known w4-w5
+%macro key_expansion_2_192 1                           
+               movdqa xmm5, xmm4
+               pslldq xmm5, 4
+               shufps xmm6, xmm1, 11110000b
+               pxor xmm6, xmm5
+               pxor xmm4, xmm6
+               pshufd xmm7, xmm4, 00001110b 
+               movdqu [edx+%1], xmm7
+%endmacro
+
+
+
+
+
+section .data
+align 16
+shuffle_mask:
+DD 0FFFFFFFFh
+DD 03020100h
+DD 07060504h
+DD 0B0A0908h
+
+align 16
+counter_add_one:
+DD 1
+DD 0
+DD 0
+DD 0
+
+counter_add_two:
+DD 2
+DD 0
+DD 0
+DD 0
+
+counter_add_three:
+DD 3
+DD 0
+DD 0
+DD 0
+
+counter_add_four:
+DD 4
+DD 0
+DD 0
+DD 0
+
+
+section .text
+
+
+
+align 16
+key_expansion256:
+
+    pshufd xmm2, xmm2, 011111111b
+
+    movdqu xmm4, xmm1
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pxor xmm1, xmm2
+
+    movdqu [edx], xmm1
+    add edx, 0x10
+    
+    aeskeygenassist xmm4, xmm1, 0
+    pshufd xmm2, xmm4, 010101010b
+
+    movdqu xmm4, xmm3
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm3, xmm4
+    pxor xmm3, xmm2
+
+    movdqu [edx], xmm3
+    add edx, 0x10
+
+    ret
+
+
+
+align 16
+key_expansion128: 
+    pshufd xmm2, xmm2, 0xFF;
+    movdqu xmm3, xmm1
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pshufb xmm3, xmm5
+    pxor xmm1, xmm3
+    pxor xmm1, xmm2
+
+    ; storing the result in the key schedule array
+    movdqu [edx], xmm1
+    add edx, 0x10                    
+    ret
+
+
+
+align 16
+global _iEncExpandKey128
+_iEncExpandKey128:
+
+       mov ecx,[esp-4+8]               ;input
+       mov edx,[esp-4+12]              ;ctx
+
+        movdqu xmm1, [ecx]    ; loading the key
+
+        movdqu [edx], xmm1
+
+        movdqa xmm5, [shuffle_mask]
+
+        add edx,16
+
+        aeskeygenassist xmm2, xmm1, 0x1     ; Generating round key 1
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
+        call key_expansion128
+        aeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
+        call key_expansion128
+
+       ret
+
+
+align 16
+global _iEncExpandKey192
+_iEncExpandKey192:
+
+       mov ecx,[esp-4+8]               ;input
+       mov edx,[esp-4+12]              ;ctx
+
+        movq xmm7, [ecx+16]    ; loading the AES key
+        movq [edx+16], xmm7  ; Storing key in memory where all key expansion 
+        pshufd xmm4, xmm7, 01001111b
+        movdqu xmm1, [ecx]     ; loading the AES key
+        movdqu [edx], xmm1  ; Storing key in memory where all key expansion 
+                       
+        pxor xmm3, xmm3                ; Set xmm3 to be all zeros. Required 
for the key_expansion. 
+        pxor xmm6, xmm6                ; Set xmm3 to be all zeros. Required 
for the key_expansion. 
+
+        aeskeygenassist xmm2, xmm4, 0x1     ; Complete round key 1 and 
generate round key 2 
+        key_expansion_1_192 24
+       key_expansion_2_192 40                          
+
+        aeskeygenassist xmm2, xmm4, 0x2     ; Generate round key 3 and part of 
round key 4
+        key_expansion_1_192 48
+       key_expansion_2_192 64                          
+
+        aeskeygenassist xmm2, xmm4, 0x4     ; Complete round key 4 and 
generate round key 5
+        key_expansion_1_192 72
+       key_expansion_2_192 88
+               
+        aeskeygenassist xmm2, xmm4, 0x8     ; Generate round key 6 and part of 
round key 7
+        key_expansion_1_192 96
+       key_expansion_2_192 112
+               
+        aeskeygenassist xmm2, xmm4, 0x10     ; Complete round key 7 and 
generate round key 8 
+        key_expansion_1_192 120
+       key_expansion_2_192 136                         
+
+        aeskeygenassist xmm2, xmm4, 0x20     ; Generate round key 9 and part 
of round key 10
+        key_expansion_1_192 144
+       key_expansion_2_192 160                         
+
+        aeskeygenassist xmm2, xmm4, 0x40     ; Complete round key 10 and 
generate round key 11
+        key_expansion_1_192 168
+       key_expansion_2_192 184                         
+
+        aeskeygenassist xmm2, xmm4, 0x80     ; Generate round key 12
+        key_expansion_1_192 192
+
+       ret
+
+
+
+
+
+
+align 16
+global _iDecExpandKey128
+_iDecExpandKey128:
+       push DWORD [esp+8]
+       push DWORD [esp+8]
+       
+       call _iEncExpandKey128
+       add esp,8
+
+       mov edx,[esp-4+12]              ;ctx
+       
+       inversekey      [edx + 1*16]
+       inversekey      [edx + 2*16]
+       inversekey      [edx + 3*16]
+       inversekey      [edx + 4*16]
+       inversekey      [edx + 5*16]
+       inversekey      [edx + 6*16]
+       inversekey      [edx + 7*16]
+       inversekey      [edx + 8*16]
+       inversekey      [edx + 9*16]
+
+       ret
+
+
+
+
+align 16
+global _iDecExpandKey192
+_iDecExpandKey192:
+       push DWORD [esp+8]
+       push DWORD [esp+8]
+       
+       call _iEncExpandKey192
+       add esp,8
+
+       mov edx,[esp-4+12]              ;ctx
+       
+       inversekey      [edx + 1*16]
+       inversekey      [edx + 2*16]
+       inversekey      [edx + 3*16]
+       inversekey      [edx + 4*16]
+       inversekey      [edx + 5*16]
+       inversekey      [edx + 6*16]
+       inversekey      [edx + 7*16]
+       inversekey      [edx + 8*16]
+       inversekey      [edx + 9*16]
+       inversekey      [edx + 10*16]
+       inversekey      [edx + 11*16]
+
+       ret
+
+
+
+
+align 16
+global _iDecExpandKey256
+_iDecExpandKey256:
+       push DWORD [esp+8]
+       push DWORD [esp+8]
+       
+       call _iEncExpandKey256
+       add esp, 8
+
+       mov edx, [esp-4+12]             ;expanded key
+       
+       inversekey      [edx + 1*16]
+       inversekey      [edx + 2*16]
+       inversekey      [edx + 3*16]
+       inversekey      [edx + 4*16]
+       inversekey      [edx + 5*16]
+       inversekey      [edx + 6*16]
+       inversekey      [edx + 7*16]
+       inversekey      [edx + 8*16]
+       inversekey      [edx + 9*16]
+       inversekey      [edx + 10*16]
+       inversekey      [edx + 11*16]
+       inversekey      [edx + 12*16]
+       inversekey      [edx + 13*16]
+
+       ret
+       
+
+       
+       
+align 16
+global _iEncExpandKey256
+_iEncExpandKey256:
+       mov ecx, [esp-4+8]              ;input
+       mov edx, [esp-4+12]             ;expanded key
+
+
+    movdqu xmm1, [ecx]    ; loading the key
+    movdqu xmm3, [ecx+16]
+    movdqu [edx], xmm1  ; Storing key in memory where all key schedule will be 
stored
+    movdqu [edx+16], xmm3 
+    
+    add edx,32
+
+    movdqa xmm5, [shuffle_mask]  ; this mask is used by key_expansion
+
+    aeskeygenassist xmm2, xmm3, 0x1     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x2     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x4     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x8     ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x10    ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x20    ; 
+    call key_expansion256
+    aeskeygenassist xmm2, xmm3, 0x40    ; 
+;    call key_expansion256 
+
+    pshufd xmm2, xmm2, 011111111b
+
+    movdqu xmm4, xmm1
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pshufb xmm4, xmm5
+    pxor xmm1, xmm4
+    pxor xmm1, xmm2
+
+    movdqu [edx], xmm1
+
+
+       ret
+       
+       
+       
+       
+       
+
+align 16
+global _iDec128
+_iDec128:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+
+       sub edi,esi
+       
+       test eax,eax
+       jz end_dec128
+
+       cmp eax,4
+       jl      lp128decsingle
+
+       test    ecx,0xf
+       jz              lp128decfour
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       mov ecx,esp     
+       
+
+align 16
+lp128decfour:
+       
+       test eax,eax
+       jz end_dec128
+
+       cmp eax,4
+       jl      lp128decsingle
+
+       load_and_xor4 esi, [ecx+10*16]
+       add esi,16*4
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+       
+       sub eax,4
+       store4 esi+edi-(16*4)
+       jmp lp128decfour
+
+
+       align 16
+lp128decsingle:
+
+       movdqu xmm0, [esi]
+       movdqu xmm4,[ecx+10*16]
+       pxor xmm0, xmm4
+       aesdec1_u  [ecx+9*16]
+       aesdec1_u  [ecx+8*16]
+       aesdec1_u  [ecx+7*16]
+       aesdec1_u  [ecx+6*16]
+       aesdec1_u  [ecx+5*16]
+       aesdec1_u  [ecx+4*16]
+       aesdec1_u  [ecx+3*16]
+       aesdec1_u  [ecx+2*16]
+       aesdec1_u  [ecx+1*16]
+       aesdeclast1_u [ecx+0*16]
+
+       add esi, 16
+       movdqu  [edi+esi - 16], xmm0
+       dec eax
+       jnz lp128decsingle
+
+end_dec128:
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
+
+
+
+align 16
+global _iDec128_CBC
+_iDec128_CBC:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       sub esp,16*16
+       and esp,0xfffffff0
+       
+       mov eax,[ecx+12]
+       movdqu xmm5,[eax]       ;iv
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_dec128_CBC
+
+       cmp eax,4
+       jl      lp128decsingle_CBC
+
+       test    ecx,0xf
+       jz              lp128decfour_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       mov ecx,esp     
+
+
+align 16
+lp128decfour_CBC:
+       
+       test eax,eax
+       jz end_dec128_CBC
+
+       cmp eax,4
+       jl      lp128decsingle_CBC
+
+       load_and_xor4 esi, [ecx+10*16]
+       add esi,16*4
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[esi- 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[esi- 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[esi- 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[esi- 16*4 + 3*16]
+       
+       sub eax,4
+       store4 esi+edi-(16*4)
+       jmp lp128decfour_CBC
+
+
+       align 16
+lp128decsingle_CBC:
+
+       movdqu xmm0, [esi]
+       movdqa xmm1,xmm0
+       movdqu xmm4,[ecx+10*16]
+       pxor xmm0, xmm4
+       aesdec1_u  [ecx+9*16]
+       aesdec1_u  [ecx+8*16]
+       aesdec1_u  [ecx+7*16]
+       aesdec1_u  [ecx+6*16]
+       aesdec1_u  [ecx+5*16]
+       aesdec1_u  [ecx+4*16]
+       aesdec1_u  [ecx+3*16]
+       aesdec1_u  [ecx+2*16]
+       aesdec1_u  [ecx+1*16]
+       aesdeclast1_u [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       
+       add esi, 16
+       movdqu  [edi+esi - 16], xmm0
+       dec eax
+       jnz lp128decsingle_CBC
+
+end_dec128_CBC:
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]   ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last iv for chaining
+       
+       ret
+
+
+
+
+
+
+align 16
+global _iDec192
+_iDec192:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_dec192
+
+       cmp eax,4
+       jl      lp192decsingle
+
+       test    ecx,0xf
+       jz              lp192decfour
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       mov ecx,esp     
+
+
+align 16
+lp192decfour:
+       
+       test eax,eax
+       jz end_dec192
+
+       cmp eax,4
+       jl      lp192decsingle
+
+       load_and_xor4 esi, [ecx+12*16]
+       add esi,16*4
+       aesdec4 [ecx+11*16]
+       aesdec4 [ecx+10*16]
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+       
+       sub eax,4
+       store4 esi+edi-(16*4)
+       jmp lp192decfour
+
+
+       align 16
+lp192decsingle:
+
+       movdqu xmm0, [esi]
+       movdqu xmm4,[ecx+12*16]
+       pxor xmm0, xmm4
+       aesdec1_u [ecx+11*16]
+       aesdec1_u  [ecx+10*16]
+       aesdec1_u  [ecx+9*16]
+       aesdec1_u  [ecx+8*16]
+       aesdec1_u  [ecx+7*16]
+       aesdec1_u  [ecx+6*16]
+       aesdec1_u  [ecx+5*16]
+       aesdec1_u  [ecx+4*16]
+       aesdec1_u  [ecx+3*16]
+       aesdec1_u  [ecx+2*16]
+       aesdec1_u  [ecx+1*16]
+       aesdeclast1_u  [ecx+0*16]
+
+       add esi, 16
+       movdqu  [edi+esi - 16], xmm0
+       dec eax
+       jnz lp192decsingle
+
+end_dec192:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
+
+
+align 16
+global _iDec192_CBC
+_iDec192_CBC:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+12]
+       movdqu xmm5,[eax]       ;iv
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_dec192_CBC
+
+       cmp eax,4
+       jl      lp192decsingle_CBC
+
+       test    ecx,0xf
+       jz              lp192decfour_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       mov ecx,esp     
+
+align 16
+lp192decfour_CBC:
+       
+       test eax,eax
+       jz end_dec192_CBC
+
+       cmp eax,4
+       jl      lp192decsingle_CBC
+
+       load_and_xor4 esi, [ecx+12*16]
+       add esi,16*4
+       aesdec4 [ecx+11*16]
+       aesdec4 [ecx+10*16]
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[esi- 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[esi- 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[esi- 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[esi- 16*4 + 3*16]
+       
+       sub eax,4
+       store4 esi+edi-(16*4)
+       jmp lp192decfour_CBC
+
+
+       align 16
+lp192decsingle_CBC:
+
+       movdqu xmm0, [esi]
+       movdqu xmm4,[ecx+12*16]
+       movdqa xmm1,xmm0
+       pxor xmm0, xmm4
+       aesdec1_u [ecx+11*16]
+       aesdec1_u [ecx+10*16]
+       aesdec1_u [ecx+9*16]
+       aesdec1_u [ecx+8*16]
+       aesdec1_u [ecx+7*16]
+       aesdec1_u [ecx+6*16]
+       aesdec1_u [ecx+5*16]
+       aesdec1_u [ecx+4*16]
+       aesdec1_u [ecx+3*16]
+       aesdec1_u [ecx+2*16]
+       aesdec1_u [ecx+1*16]
+       aesdeclast1_u [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       
+       add esi, 16
+       movdqu  [edi+esi - 16], xmm0
+       dec eax
+       jnz lp192decsingle_CBC
+
+end_dec192_CBC:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last iv for chaining
+       
+       ret
+
+
+
+
+
+align 16
+global _iDec256
+_iDec256:
+       mov ecx, [esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+
+       test eax,eax
+       jz end_dec256
+       
+       cmp eax,4
+       jl lp256dec
+
+       test    ecx,0xf
+       jz      lp256dec4
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       copy_round_keys esp,ecx,13
+       copy_round_keys esp,ecx,14
+       mov ecx,esp     
+       
+       align 16
+lp256dec4:
+       test eax,eax
+       jz end_dec256
+       
+       cmp eax,4
+       jl lp256dec
+       
+       load_and_xor4 esi,[ecx+14*16]
+       add esi, 4*16
+       aesdec4 [ecx+13*16]
+       aesdec4 [ecx+12*16]
+       aesdec4 [ecx+11*16]
+       aesdec4 [ecx+10*16]
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lp256dec4   
+       
+       align 16
+lp256dec:
+
+       movdqu xmm0, [esi]
+       movdqu xmm4,[ecx+14*16]
+       add esi, 16
+       pxor xmm0, xmm4                     ; Round 0 (only xor)
+       aesdec1_u  [ecx+13*16]
+       aesdec1_u  [ecx+12*16]
+       aesdec1_u  [ecx+11*16]
+       aesdec1_u  [ecx+10*16]
+       aesdec1_u  [ecx+9*16]
+       aesdec1_u  [ecx+8*16]
+       aesdec1_u  [ecx+7*16]
+       aesdec1_u  [ecx+6*16]
+       aesdec1_u  [ecx+5*16]
+       aesdec1_u  [ecx+4*16]
+       aesdec1_u  [ecx+3*16]
+       aesdec1_u  [ecx+2*16]
+       aesdec1_u  [ecx+1*16]
+       aesdeclast1_u  [ecx+0*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp256dec
+
+end_dec256:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
+
+
+
+
+align 16
+global _iDec256_CBC
+_iDec256_CBC:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+12]
+       movdqu xmm5,[eax]       ;iv
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_dec256_CBC
+
+       cmp eax,4
+       jl      lp256decsingle_CBC
+
+       test    ecx,0xf
+       jz      lp256decfour_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       copy_round_keys esp,ecx,13
+       copy_round_keys esp,ecx,14
+       mov ecx,esp     
+
+align 16
+lp256decfour_CBC:
+       
+       test eax,eax
+       jz end_dec256_CBC
+
+       cmp eax,4
+       jl      lp256decsingle_CBC
+
+       load_and_xor4 esi, [ecx+14*16]
+       add esi,16*4
+       aesdec4 [ecx+13*16]
+       aesdec4 [ecx+12*16]
+       aesdec4 [ecx+11*16]
+       aesdec4 [ecx+10*16]
+       aesdec4 [ecx+9*16]
+       aesdec4 [ecx+8*16]
+       aesdec4 [ecx+7*16]
+       aesdec4 [ecx+6*16]
+       aesdec4 [ecx+5*16]
+       aesdec4 [ecx+4*16]
+       aesdec4 [ecx+3*16]
+       aesdec4 [ecx+2*16]
+       aesdec4 [ecx+1*16]
+       aesdeclast4 [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqu  xmm4,[esi- 16*4 + 0*16]
+       pxor    xmm1,xmm4
+       movdqu  xmm4,[esi- 16*4 + 1*16]
+       pxor    xmm2,xmm4
+       movdqu  xmm4,[esi- 16*4 + 2*16]
+       pxor    xmm3,xmm4
+       movdqu  xmm5,[esi- 16*4 + 3*16]
+       
+       sub eax,4
+       store4 esi+edi-(16*4)
+       jmp lp256decfour_CBC
+
+
+       align 16
+lp256decsingle_CBC:
+
+       movdqu xmm0, [esi]
+       movdqa xmm1,xmm0
+       movdqu xmm4, [ecx+14*16]
+       pxor xmm0, xmm4
+       aesdec1_u  [ecx+13*16]
+       aesdec1_u  [ecx+12*16]
+       aesdec1_u  [ecx+11*16]
+       aesdec1_u  [ecx+10*16]
+       aesdec1_u  [ecx+9*16]
+       aesdec1_u  [ecx+8*16]
+       aesdec1_u  [ecx+7*16]
+       aesdec1_u  [ecx+6*16]
+       aesdec1_u  [ecx+5*16]
+       aesdec1_u  [ecx+4*16]
+       aesdec1_u  [ecx+3*16]
+       aesdec1_u  [ecx+2*16]
+       aesdec1_u  [ecx+1*16]
+       aesdeclast1_u  [ecx+0*16]
+       
+       pxor    xmm0,xmm5
+       movdqa  xmm5,xmm1
+       
+       add esi, 16
+       movdqu  [edi+esi - 16], xmm0
+       dec eax
+       jnz lp256decsingle_CBC
+
+end_dec256_CBC:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last iv for chaining
+       
+       ret
+
+
+
+
+
+
+
+
+
+align 16
+global _iEnc128
+_iEnc128:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_enc128
+       
+       cmp eax,4
+       jl lp128encsingle
+
+       test    ecx,0xf
+       jz              lpenc128four
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       mov ecx,esp     
+
+
+       align 16        
+       
+lpenc128four:
+       
+       test eax,eax
+       jz end_enc128
+       
+       cmp eax,4
+       jl lp128encsingle
+
+       load_and_xor4 esi,[ecx+0*16]
+       add esi,4*16
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenclast4     [ecx+10*16]
+       
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lpenc128four
+       
+       align 16
+lp128encsingle:
+
+       movdqu xmm0, [esi]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u  [ecx+1*16]
+       aesenc1_u  [ecx+2*16]
+       aesenc1_u  [ecx+3*16]
+       aesenc1_u  [ecx+4*16]     
+       aesenc1_u  [ecx+5*16]
+       aesenc1_u  [ecx+6*16]
+       aesenc1_u  [ecx+7*16]
+       aesenc1_u  [ecx+8*16]
+       aesenc1_u  [ecx+9*16]
+       aesenclast1_u  [ecx+10*16]
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp128encsingle
+
+end_enc128:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
+
+
+align 16
+global _iEnc128_CTR
+_iEnc128_CTR:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm5,[eax]       ;initial counter
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_encctr128
+       
+       cmp eax,4
+       jl lp128encctrsingle
+
+       test    ecx,0xf
+       jz              lpencctr128four
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       mov ecx,esp     
+
+
+       align 16        
+       
+lpencctr128four:
+       
+       test eax,eax
+       jz end_encctr128
+       
+       cmp eax,4
+       jl lp128encsingle
+
+       load_and_inc4 [ecx+0*16]
+       add esi,4*16
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenclast4     [ecx+10*16]
+       xor_with_input4 esi-(4*16)
+       
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lpencctr128four
+       
+       align 16
+lp128encctrsingle:
+
+       movdqa  xmm0,xmm5
+       paddq   xmm5,[counter_add_one]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u [ecx+1*16]
+       aesenc1_u [ecx+2*16]
+       aesenc1_u [ecx+3*16]
+       aesenc1_u [ecx+4*16]     
+       aesenc1_u [ecx+5*16]
+       aesenc1_u [ecx+6*16]
+       aesenc1_u [ecx+7*16]
+       aesenc1_u [ecx+8*16]
+       aesenc1_u [ecx+9*16]
+       aesenclast1_u [ecx+10*16]
+       movdqu xmm4, [esi-16]
+       pxor    xmm0,xmm4
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp128encctrsingle
+
+end_encctr128:
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last counter for chaining
+       
+       ret
+
+
+align 16
+global _iEnc192_CTR
+_iEnc192_CTR:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm5,[eax]       ;initial counter
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_encctr192
+       
+       cmp eax,4
+       jl lp192encctrsingle
+
+       test    ecx,0xf
+       jz              lpencctr128four
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       mov ecx,esp     
+
+
+       align 16        
+       
+lpencctr192four:
+       
+       test eax,eax
+       jz end_encctr192
+       
+       cmp eax,4
+       jl lp192encsingle
+
+       load_and_inc4 [ecx+0*16]
+       add esi,4*16
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenc4 [ecx+10*16]
+       aesenc4 [ecx+11*16]
+       aesenclast4     [ecx+12*16]
+       xor_with_input4 esi-(4*16)
+       
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lpencctr192four
+       
+       align 16
+lp192encctrsingle:
+
+       movdqa  xmm0,xmm5
+       paddq   xmm5,[counter_add_one]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u  [ecx+1*16]
+       aesenc1_u  [ecx+2*16]
+       aesenc1_u  [ecx+3*16]
+       aesenc1_u  [ecx+4*16]     
+       aesenc1_u  [ecx+5*16]
+       aesenc1_u  [ecx+6*16]
+       aesenc1_u  [ecx+7*16]
+       aesenc1_u  [ecx+8*16]
+       aesenc1_u  [ecx+9*16]
+       aesenc1_u  [ecx+10*16]
+       aesenc1_u  [ecx+11*16]
+       aesenclast1_u  [ecx+12*16]
+       movdqu xmm4, [esi-16]
+       pxor    xmm0,xmm4
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp192encctrsingle
+
+end_encctr192:
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last counter for chaining
+       
+       ret
+
+
+align 16
+global _iEnc256_CTR
+_iEnc256_CTR:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm5,[eax]       ;initial counter
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_encctr256
+       
+       cmp eax,4
+       jl lp256encctrsingle
+
+       test    ecx,0xf
+       jz              lpencctr128four
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       copy_round_keys esp,ecx,13
+       copy_round_keys esp,ecx,14
+       mov ecx,esp     
+
+
+       align 16        
+       
+lpencctr256four:
+       
+       test eax,eax
+       jz end_encctr256
+       
+       cmp eax,4
+       jl lp256encctrsingle
+
+       load_and_inc4 [ecx+0*16]
+       add esi,4*16
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenc4 [ecx+10*16]
+       aesenc4 [ecx+11*16]
+       aesenc4 [ecx+12*16]
+       aesenc4 [ecx+13*16]
+       aesenclast4     [ecx+14*16]
+       xor_with_input4 esi-(4*16)
+       
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lpencctr256four
+       
+       align 16
+       
+lp256encctrsingle:
+
+       movdqa  xmm0,xmm5
+       paddq   xmm5,[counter_add_one]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u  [ecx+1*16]
+       aesenc1_u  [ecx+2*16]
+       aesenc1_u  [ecx+3*16]
+       aesenc1_u  [ecx+4*16]     
+       aesenc1_u  [ecx+5*16]
+       aesenc1_u  [ecx+6*16]
+       aesenc1_u  [ecx+7*16]
+       aesenc1_u  [ecx+8*16]
+       aesenc1_u  [ecx+9*16]
+       aesenc1_u  [ecx+10*16]
+       aesenc1_u  [ecx+11*16]
+       aesenc1_u  [ecx+12*16]
+       aesenc1_u  [ecx+13*16]
+       aesenclast1_u  [ecx+14*16]
+       movdqu xmm4, [esi-16]
+       pxor    xmm0,xmm4
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp256encctrsingle
+
+end_encctr256:
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm5 ; store last counter for chaining
+       
+       ret
+
+
+
+
+
+
+align 16
+global _iEnc128_CBC
+_iEnc128_CBC:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm1,[eax]       ;iv     
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       sub edi,esi
+
+       test    ecx,0xf
+       jz              lp128encsingle_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       mov ecx,esp     
+
+       align 16        
+       
+lp128encsingle_CBC:
+
+       movdqu xmm0, [esi]
+       add esi, 16
+       pxor xmm0, xmm1
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1  [ecx+1*16]
+       aesenc1  [ecx+2*16]
+       aesenc1  [ecx+3*16]
+       aesenc1  [ecx+4*16]     
+       aesenc1  [ecx+5*16]
+       aesenc1  [ecx+6*16]
+       aesenc1  [ecx+7*16]
+       aesenc1  [ecx+8*16]
+       aesenc1  [ecx+9*16]
+       aesenclast1  [ecx+10*16]
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       movdqa xmm1,xmm0
+       dec eax
+       jnz lp128encsingle_CBC
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm1 ; store last iv for chaining
+       
+       ret
+
+
+align 16
+global _iEnc192_CBC
+_iEnc192_CBC:
+       mov ecx,[esp-4+8]  ; first arg
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm1,[eax]       ;iv     
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       sub edi,esi
+
+       test    ecx,0xf
+       jz              lp192encsingle_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       mov ecx,esp     
+
+       align 16        
+       
+lp192encsingle_CBC:
+
+       movdqu xmm0, [esi]
+       add esi, 16
+       pxor xmm0, xmm1
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1  [ecx+1*16]
+       aesenc1  [ecx+2*16]
+       aesenc1  [ecx+3*16]
+       aesenc1  [ecx+4*16]     
+       aesenc1  [ecx+5*16]
+       aesenc1  [ecx+6*16]
+       aesenc1  [ecx+7*16]
+       aesenc1  [ecx+8*16]
+       aesenc1  [ecx+9*16]
+       aesenc1  [ecx+10*16]
+       aesenc1  [ecx+11*16]
+       aesenclast1  [ecx+12*16]
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       movdqa xmm1,xmm0
+       dec eax
+       jnz lp192encsingle_CBC
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       mov ecx,[esp-4+8]  ; first arg
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm1 ; store last iv for chaining
+       
+       ret
+
+align 16
+global _iEnc256_CBC
+_iEnc256_CBC:
+       mov ecx,[esp-4+8]  ; first arg
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov     eax,[ecx+12]
+       movdqu xmm1,[eax]       ;iv     
+       
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       sub edi,esi
+
+       test    ecx,0xf
+       jz              lp256encsingle_CBC
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       copy_round_keys esp,ecx,13
+       copy_round_keys esp,ecx,14
+       mov ecx,esp     
+
+       align 16        
+       
+lp256encsingle_CBC:
+
+;abab
+       movdqu xmm0, [esi]
+       add esi, 16
+       pxor xmm0, xmm1
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1 [ecx+1*16]
+       aesenc1 [ecx+2*16]
+       aesenc1 [ecx+3*16]
+       aesenc1 [ecx+4*16]     
+       aesenc1 [ecx+5*16]
+       aesenc1 [ecx+6*16]
+       aesenc1 [ecx+7*16]
+       aesenc1 [ecx+8*16]
+       aesenc1 [ecx+9*16]
+       aesenc1 [ecx+10*16]
+       aesenc1 [ecx+11*16]
+       aesenc1 [ecx+12*16]
+       aesenc1 [ecx+13*16]
+       aesenclast1 [ecx+14*16]
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       movdqa xmm1,xmm0
+       dec eax
+       jnz lp256encsingle_CBC
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       mov ecx,[esp-4+8]
+       mov ecx,[ecx+12]
+       movdqu  [ecx],xmm1 ; store last iv for chaining
+       
+       ret
+
+
+
+
+
+align 16
+global _iEnc192
+_iEnc192:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi
+
+       test eax,eax
+       jz end_enc192
+       
+       cmp eax,4
+       jl lp192encsingle
+
+       test    ecx,0xf
+       jz              lpenc192four
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       mov ecx,esp     
+
+       align 16        
+       
+lpenc192four:
+       
+       test eax,eax
+       jz end_enc192
+       
+       cmp eax,4
+       jl lp192encsingle
+
+       load_and_xor4 esi,[ecx+0*16]
+       add esi,4*16
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenc4 [ecx+10*16]
+       aesenc4 [ecx+11*16]
+       aesenclast4     [ecx+12*16]
+       
+       store4 esi+edi-16*4
+       sub eax,4
+       jmp lpenc192four
+       
+       align 16
+lp192encsingle:
+
+       movdqu xmm0, [esi]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u [ecx+1*16]
+       aesenc1_u [ecx+2*16]
+       aesenc1_u [ecx+3*16]
+       aesenc1_u [ecx+4*16]     
+       aesenc1_u [ecx+5*16]
+       aesenc1_u [ecx+6*16]
+       aesenc1_u [ecx+7*16]
+       aesenc1_u [ecx+8*16]
+       aesenc1_u [ecx+9*16]
+       aesenc1_u [ecx+10*16]
+       aesenc1_u [ecx+11*16]
+       aesenclast1_u [ecx+12*16]
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp192encsingle
+
+end_enc192:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
+
+
+
+
+align 16
+global _iEnc256
+_iEnc256:
+       mov ecx,[esp-4+8]
+       
+       push esi
+       push edi
+       push ebp
+       mov ebp,esp
+       
+       sub esp,16*16
+       and esp,0xfffffff0
+
+       mov eax,[ecx+16] ; numblocks
+       mov esi,[ecx]
+       mov edi,[ecx+4]
+       mov ecx,[ecx+8]
+       
+       sub edi,esi     
+
+       test eax,eax
+       jz end_enc256
+
+       cmp eax,4
+       jl lp256enc
+
+       test    ecx,0xf
+       jz      lp256enc4
+       
+       copy_round_keys esp,ecx,0
+       copy_round_keys esp,ecx,1
+       copy_round_keys esp,ecx,2
+       copy_round_keys esp,ecx,3
+       copy_round_keys esp,ecx,4
+       copy_round_keys esp,ecx,5
+       copy_round_keys esp,ecx,6
+       copy_round_keys esp,ecx,7
+       copy_round_keys esp,ecx,8
+       copy_round_keys esp,ecx,9
+       copy_round_keys esp,ecx,10
+       copy_round_keys esp,ecx,11
+       copy_round_keys esp,ecx,12
+       copy_round_keys esp,ecx,13
+       copy_round_keys esp,ecx,14
+       mov ecx,esp     
+
+
+
+       align 16
+       
+lp256enc4:
+       test eax,eax
+       jz end_enc256
+
+       cmp eax,4
+       jl lp256enc
+
+
+       load_and_xor4 esi,[ecx+0*16]
+       add esi, 16*4
+       aesenc4 [ecx+1*16]
+       aesenc4 [ecx+2*16]
+       aesenc4 [ecx+3*16]
+       aesenc4 [ecx+4*16]
+       aesenc4 [ecx+5*16]
+       aesenc4 [ecx+6*16]
+       aesenc4 [ecx+7*16]
+       aesenc4 [ecx+8*16]
+       aesenc4 [ecx+9*16]
+       aesenc4 [ecx+10*16]
+       aesenc4 [ecx+11*16]
+       aesenc4 [ecx+12*16]
+       aesenc4 [ecx+13*16]
+       aesenclast4 [ecx+14*16]
+
+       store4  esi+edi-16*4
+       sub eax,4
+       jmp lp256enc4
+       
+       align 16
+lp256enc:
+
+       movdqu xmm0, [esi]
+       add esi, 16
+       movdqu xmm4,[ecx+0*16]
+       pxor xmm0, xmm4
+       aesenc1_u [ecx+1*16]
+       aesenc1_u [ecx+2*16]
+       aesenc1_u [ecx+3*16]
+       aesenc1_u [ecx+4*16]
+       aesenc1_u [ecx+5*16]
+       aesenc1_u [ecx+6*16]
+       aesenc1_u [ecx+7*16]
+       aesenc1_u [ecx+8*16]
+       aesenc1_u [ecx+9*16]
+       aesenc1_u [ecx+10*16]
+       aesenc1_u [ecx+11*16]
+       aesenc1_u [ecx+12*16]
+       aesenc1_u [ecx+13*16]
+       aesenclast1_u [ecx+14*16]
+
+               ; Store output encrypted data into CIPHERTEXT array
+       movdqu  [esi+edi-16], xmm0
+       dec eax
+       jnz lp256enc
+
+end_enc256:
+
+
+       mov esp,ebp
+       pop ebp
+       pop edi
+       pop esi
+       
+       ret
diff --git a/lib/accelerated/intel/iaes_asm_interface.h 
b/lib/accelerated/intel/iaes_asm_interface.h
new file mode 100755
index 0000000..093d2a5
--- /dev/null
+++ b/lib/accelerated/intel/iaes_asm_interface.h
@@ -0,0 +1,126 @@
+/* 
+ * 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.
+ * 
+*/
+
+#ifndef _INTEL_AES_ASM_INTERFACE_H__
+#define _INTEL_AES_ASM_INTERFACE_H__
+
+
+#include "iaesni.h"
+
+
+
+//structure to pass aes processing data to asm level functions
+typedef struct _sAesData
+{
+       _AES_IN         UCHAR   *in_block;
+       _AES_OUT        UCHAR   *out_block;
+       _AES_IN         UCHAR   *expanded_key;          
+       _AES_INOUT      UCHAR   *iv;                                    // for 
CBC mode
+       _AES_IN         size_t  num_blocks;
+} sAesData;
+
+#if (__cplusplus)
+extern "C"
+{
+#endif
+#if 0
+#define MYSTDCALL __stdcall
+#else
+#define MYSTDCALL 
+#endif
+
+#ifdef __linux__
+#ifndef __LP64__
+#define iEncExpandKey256 _iEncExpandKey256
+#define iEncExpandKey192 _iEncExpandKey192
+#define iEncExpandKey128 _iEncExpandKey128
+#define iDecExpandKey256 _iDecExpandKey256
+#define iDecExpandKey192 _iDecExpandKey192
+#define iDecExpandKey128 _iDecExpandKey128
+#define iEnc128 _iEnc128
+#define iDec128 _iDec128
+#define iEnc256 _iEnc256
+#define iDec256 _iDec256
+#define iEnc192 _iEnc192
+#define iDec192 _iDec192
+#define iEnc128_CBC _iEnc128_CBC
+#define iDec128_CBC _iDec128_CBC
+#define iEnc256_CBC _iEnc256_CBC
+#define iDec256_CBC _iDec256_CBC
+#define iEnc192_CBC _iEnc192_CBC
+#define iDec192_CBC _iDec192_CBC
+#define iEnc128_CTR _iEnc128_CTR
+#define iEnc192_CTR _iEnc192_CTR
+#define iEnc256_CTR _iEnc256_CTR
+#define do_rdtsc    _do_rdtsc
+#endif
+#endif
+       // prepearing the different key rounds, for enc/dec in asm
+       // expnaded key should be 16-byte aligned
+       // 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)
+       void MYSTDCALL iEncExpandKey256(_AES_IN UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+       void MYSTDCALL iEncExpandKey192(_AES_IN UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+       void MYSTDCALL iEncExpandKey128(_AES_IN UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+
+       void MYSTDCALL iDecExpandKey256(UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+       void MYSTDCALL iDecExpandKey192(UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+       void MYSTDCALL iDecExpandKey128(UCHAR *key, _AES_OUT UCHAR 
*expanded_key);
+
+
+       //enc/dec asm functions
+       void MYSTDCALL iEnc128(sAesData *data);
+       void MYSTDCALL iDec128(sAesData *data);
+       void MYSTDCALL iEnc256(sAesData *data);
+       void MYSTDCALL iDec256(sAesData *data);
+       void MYSTDCALL iEnc192(sAesData *data);
+       void MYSTDCALL iDec192(sAesData *data);
+
+       void MYSTDCALL iEnc128_CBC(sAesData *data);
+       void MYSTDCALL iDec128_CBC(sAesData *data);
+       void MYSTDCALL iEnc256_CBC(sAesData *data);
+       void MYSTDCALL iDec256_CBC(sAesData *data);
+       void MYSTDCALL iEnc192_CBC(sAesData *data);
+       void MYSTDCALL iDec192_CBC(sAesData *data);
+
+
+       void MYSTDCALL iEnc128_CTR(sAesData *data);
+       void MYSTDCALL iEnc256_CTR(sAesData *data);
+       void MYSTDCALL iEnc192_CTR(sAesData *data);
+
+       // rdtsc function
+       unsigned long long do_rdtsc(void);
+
+
+#if (__cplusplus)
+}
+#endif
+
+
+#endif
+
diff --git a/lib/accelerated/intel/iaesni.h b/lib/accelerated/intel/iaesni.h
new file mode 100755
index 0000000..b358faa
--- /dev/null
+++ b/lib/accelerated/intel/iaesni.h
@@ -0,0 +1,147 @@
+/* 
+ * 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.
+ * 
+*/
+
+
+#ifndef _IAESNI_H__
+#define _IAESNI_H__
+
+#include <stdlib.h>
+
+#define AES_INSTRCTIONS_CPUID_BIT (1<<25)
+
+//indicates input param
+#define _AES_IN        
+
+//indicates output param
+#define _AES_OUT
+
+//indicates input/output param - based on context
+#define _AES_INOUT
+
+typedef unsigned char UCHAR;
+
+
+#ifndef bool
+#define bool BOOL
+#endif
+//test if the processor actually supports the above functions
+//executing one the functions below without processor support will cause UD 
fault
+//bool check_for_aes_instructions(void);
+#if (__cplusplus)
+extern "C" {
+#endif
+int check_for_aes_instructions(void);
+
+#define ROUND_KEYS_UNALIGNED_TESTING
+
+#ifdef __linux__
+
+#ifdef ROUND_KEYS_UNALIGNED_TESTING
+
+#define DEFINE_ROUND_KEYS \
+       UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16];       \
+       UCHAR *expandedKey = _expandedKey + 4;  \
+
+
+#else
+
+
+
+#define DEFINE_ROUND_KEYS \
+       UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16];       \
+       UCHAR *expandedKey = _expandedKey;      \
+
+#endif
+
+#else // if not __linux__
+
+#ifdef ROUND_KEYS_UNALIGNED_TESTING
+
+#define DEFINE_ROUND_KEYS \
+       __declspec(align(16)) UCHAR _expandedKey[16*16];        \
+       UCHAR *expandedKey = _expandedKey + 4;  \
+
+
+#else
+
+
+
+#define DEFINE_ROUND_KEYS \
+       __declspec(align(16)) UCHAR _expandedKey[16*16];        \
+       UCHAR *expandedKey = _expandedKey;      \
+
+
+#endif
+
+#endif
+
+
+
+// encryption functions
+// plainText is pointer to input stream
+// cipherText is pointer to buffer to be filled with encrypted (cipher text) 
data
+// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for 
AES-192, 32 for AES-256)
+// numBlocks is number of 16 bytes blocks to process - note that encryption is 
done of full 16 byte blocks
+void intel_AES_enc128(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+void intel_AES_enc192(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+void intel_AES_enc256(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+
+
+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);
+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);
+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);
+
+
+// encryption functions
+// cipherText is pointer to encrypted stream
+// plainText is pointer to buffer to be filled with original (plain text) data
+// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for 
AES-192, 32 for AES-256)
+// numBlocks is number of 16 bytes blocks to process - note that decryption is 
done of full 16 byte blocks
+void intel_AES_dec128(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+void intel_AES_dec192(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+void intel_AES_dec256(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, 
_AES_IN UCHAR *key, _AES_IN size_t numBlocks);
+
+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);
+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);
+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);
+
+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);
+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);
+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);
+
+
+#if (__cplusplus)
+}
+#endif
+
+
+#endif
+
+
+
diff --git a/lib/accelerated/intel/license.txt 
b/lib/accelerated/intel/license.txt
new file mode 100755
index 0000000..a93c323
--- /dev/null
+++ b/lib/accelerated/intel/license.txt
@@ -0,0 +1,34 @@
+/* intel_aes_lib source files come from Intel.
+ * Modified by Patrick Fay
+ *
+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.
+
+ ---------------------------------------------------------------------------
+ Issue Date: Aug 6, 2010
+ */
+
+Other source code files use the license shown in the source code file.
diff --git a/lib/accelerated/x86.h b/lib/accelerated/x86.h
new file mode 100644
index 0000000..c344283
--- /dev/null
+++ b/lib/accelerated/x86.h
@@ -0,0 +1,3 @@
+#define cpuid(func,ax,bx,cx,dx)\
+  __asm__ __volatile__ ("cpuid":\
+  "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
diff --git a/lib/crypto-api.c b/lib/crypto-api.c
index f7f200c..5fb633e 100644
--- a/lib/crypto-api.c
+++ b/lib/crypto-api.c
@@ -114,6 +114,23 @@ gnutls_cipher_add_auth (gnutls_cipher_hd_t handle, const 
void *text, size_t text
 }
 
 /**
+ * gnutls_cipher_set_iv:
+ * @handle: is a #gnutls_cipher_hd_t structure.
+ * @iv: the IV to set
+ * @ivlen: The length of the IV
+ *
+ * This function will set the IV to be used for the next
+ * encryption block.
+ *
+ * Since: 2.99.0
+ **/
+void
+gnutls_cipher_set_iv (gnutls_cipher_hd_t handle, void *iv, size_t ivlen)
+{
+  _gnutls_cipher_setiv((cipher_hd_st *)handle, iv, ivlen);
+}
+
+/**
  * gnutls_cipher_encrypt:
  * @handle: is a #gnutls_cipher_hd_t structure.
  * @text: the data to encrypt
diff --git a/lib/crypto.c b/lib/crypto.c
index 853df9e..aa914b0 100644
--- a/lib/crypto.c
+++ b/lib/crypto.c
@@ -156,7 +156,7 @@ _gnutls_crypto_deregister (void)
  * This function will register a cipher algorithm to be used by
  * gnutls.  Any algorithm registered will override the included
  * algorithms and by convention kernel implemented algorithms have
- * priority of 90.  The algorithm with the lowest priority will be
+ * priority of 90 and CPU-assisted of 80.  The algorithm with the lowest 
priority will be
  * used by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -197,7 +197,7 @@ _gnutls_get_crypto_cipher (gnutls_cipher_algorithm_t algo)
  * This function will register a random generator to be used by
  * gnutls.  Any generator registered will override the included
  * generator and by convention kernel implemented generators have
- * priority of 90.  The generator with the lowest priority will be
+ * priority of 90 and CPU-assisted of 80. The generator with the lowest 
priority will be
  * used by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -238,7 +238,8 @@ gnutls_crypto_rnd_register2 (int priority, int version,
  *
  * This function will register a MAC algorithm to be used by gnutls.
  * Any algorithm registered will override the included algorithms and
- * by convention kernel implemented algorithms have priority of 90.
+ * by convention kernel implemented algorithms have priority of 90
+ *  and CPU-assisted of 80.
  * The algorithm with the lowest priority will be used by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -280,7 +281,7 @@ _gnutls_get_crypto_mac (gnutls_mac_algorithm_t algo)
  * This function will register a digest (hash) algorithm to be used by
  * gnutls.  Any algorithm registered will override the included
  * algorithms and by convention kernel implemented algorithms have
- * priority of 90.  The algorithm with the lowest priority will be
+ * priority of 90  and CPU-assisted of 80.  The algorithm with the lowest 
priority will be
  * used by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -409,7 +410,7 @@ gnutls_crypto_pk_register2 (int priority, int version,
  * This function will register a cipher interface to be used by
  * gnutls. Any interface registered will override the included engine
  * and by convention kernel implemented interfaces should have
- * priority of 90. The interface with the lowest priority will be used
+ * priority of 90  and CPU-assisted of 80. The interface with the lowest 
priority will be used
  * by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -450,7 +451,7 @@ gnutls_crypto_cipher_register2 (int priority, int version,
  * This function will register a mac interface to be used by
  * gnutls. Any interface registered will override the included engine
  * and by convention kernel implemented interfaces should have
- * priority of 90. The interface with the lowest priority will be used
+ * priority of 90  and CPU-assisted of 80. The interface with the lowest 
priority will be used
  * by gnutls.
  *
  * This function should be called before gnutls_global_init().
@@ -491,7 +492,7 @@ gnutls_crypto_mac_register2 (int priority, int version,
  * This function will register a digest interface to be used by
  * gnutls. Any interface registered will override the included engine
  * and by convention kernel implemented interfaces should have
- * priority of 90. The interface with the lowest priority will be used
+ * priority of 90  and CPU-assisted of 80. The interface with the lowest 
priority will be used
  * by gnutls.
  *
  * This function should be called before gnutls_global_init().
diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c
index 8f3b687..972eee5 100644
--- a/lib/gnutls_algorithms.c
+++ b/lib/gnutls_algorithms.c
@@ -1572,7 +1572,7 @@ gnutls_cipher_suite_get_name (gnutls_kx_algorithm_t 
kx_algorithm,
  * @kx: output variable indicating key exchange algorithm, or %NULL.
  * @cipher: output variable indicating cipher, or %NULL.
  * @mac: output variable indicating MAC algorithm, or %NULL.
- * @version: output variable indicating TLS protocol version, or %NULL.
+ * @min_version: output variable indicating TLS protocol version, or %NULL.
  *
  * Get information about supported cipher suites.  Use the function
  * iteratively to get information about all supported cipher suites.
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index 7b24966..f222177 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -779,7 +779,7 @@ parse_handshake_header (gnutls_session_t session, 
mbuffer_st* bufel, gnutls_hand
         {
           hsk->sequence = 0;
           hsk->start_offset = 0;
-          hsk->end_offset = _mbuffer_get_udata_size(bufel) - 
handshake_header_size;
+          hsk->end_offset = hsk->length;
         }
     }
 
@@ -1024,10 +1024,9 @@ parse_record_buffered_msgs (gnutls_session_t session,
               ret = _gnutls_buffer_append_data(&recv_buf[0].data, 
_mbuffer_get_udata_ptr(bufel), data_size);
               if (ret < 0)
                 return gnutls_assert_val(ret);
-
+              _mbuffer_set_uhead_size(bufel, 0);
               _mbuffer_head_remove_bytes(&session->internals.record_buffer, 
data_size+header_size);
 
-
               if (cmp_hsk_types(htype, recv_buf[0].htype) == 0)
                 { /* an unexpected packet */
                   hsk->htype = recv_buf[0].htype;
@@ -1147,8 +1146,16 @@ _gnutls_handshake_io_recv_int (gnutls_session_t session,
    * trying to receive.
    */
   ret = parse_record_buffered_msgs(session, htype, hsk);
-  if (ret >= 0)
-    return ret;
+  if (IS_DTLS(session))
+    {
+      if (ret >= 0)
+        return ret;
+    }
+  else
+    {
+      if ((ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && ret < 0) || ret >= 
0)
+        return gnutls_assert_val(ret);
+    }
 
   /* if we don't have a complete message waiting for us, try 
    * receiving more */
diff --git a/lib/gnutls_compress.c b/lib/gnutls_compress.c
index b0f67ce..67db1fa 100644
--- a/lib/gnutls_compress.c
+++ b/lib/gnutls_compress.c
@@ -103,9 +103,6 @@ gnutls_compression_entry 
_gnutls_compression_algorithms[MAX_COMP_METHODS] = {
 };
 
 static const gnutls_compression_method_t supported_compressions[] = {
-#ifdef USE_LZO
-  GNUTLS_COMP_LZO,
-#endif
 #ifdef HAVE_LIBZ
   GNUTLS_COMP_DEFLATE,
 #endif
@@ -168,9 +165,7 @@ gnutls_compression_get_id (const char *name)
 /**
  * gnutls_compression_list:
  *
- * Get a list of compression methods.  Note that to be able to use LZO
- * compression, you must link to libgnutls-extra and call
- * gnutls_global_init_extra().
+ * Get a list of compression methods.  
  *
  * Returns: a zero-terminated list of #gnutls_compression_method_t
  *   integers indicating the available compression methods.
@@ -299,26 +294,6 @@ _gnutls_supported_compression_methods (gnutls_session_t 
session,
 }
 
 
-#ifdef USE_LZO
-#ifdef USE_MINILZO
-/* Get the prototypes only.  Since LZO is a GPLed library, the
- * gnutls_global_init_extra() has to be called, before LZO compression
- * can be used.
- */
-#include "../libextra/minilzo/minilzo.h"
-#elif HAVE_LZO_LZO1X_H
-#include <lzo/lzo1x.h>
-#elif HAVE_LZO1X_H
-#include <lzo1x.h>
-#endif
-
-typedef int (*LZO_FUNC) ();
-
-LZO_FUNC _gnutls_lzo1x_decompress_safe = NULL;
-LZO_FUNC _gnutls_lzo1x_1_compress = NULL;
-
-#endif
-
 /* The flag d is the direction (compress, decompress). Non zero is
  * decompress.
  */
@@ -381,21 +356,6 @@ _gnutls_comp_init (gnutls_compression_method_t method, int 
d)
       }
       break;
 #endif
-    case GNUTLS_COMP_LZO:
-#ifdef USE_LZO
-      /* LZO does not use memory on decompressor */
-      if (!d)
-        {
-          ret->handle = gnutls_malloc (LZO1X_1_MEM_COMPRESS);
-
-          if (ret->handle == NULL)
-            {
-              gnutls_assert ();
-              goto cleanup_ret;
-            }
-        }
-      break;
-#endif
     case GNUTLS_COMP_NULL:
     case GNUTLS_COMP_UNKNOWN:
       break;
@@ -459,39 +419,6 @@ _gnutls_compress (comp_hd_t handle, const opaque * plain,
 
   switch (handle->algo)
     {
-#ifdef USE_LZO
-    case GNUTLS_COMP_LZO:
-      {
-        lzo_uint out_len;
-        size_t size;
-        int err;
-
-        if (_gnutls_lzo1x_1_compress == NULL)
-          return GNUTLS_E_COMPRESSION_FAILED;
-
-        size = plain_size + plain_size / 64 + 16 + 3;
-        *compressed = gnutls_malloc (size);
-        if (*compressed == NULL)
-          {
-            gnutls_assert ();
-            return GNUTLS_E_MEMORY_ERROR;
-          }
-
-        err = _gnutls_lzo1x_1_compress (plain, plain_size, *compressed,
-                                        &out_len, handle->handle);
-
-        if (err != LZO_E_OK)
-          {
-            gnutls_assert ();
-            gnutls_free (*compressed);
-            *compressed = NULL;
-            return GNUTLS_E_COMPRESSION_FAILED;
-          }
-
-        compressed_size = out_len;
-        break;
-      }
-#endif
 #ifdef HAVE_LIBZ
     case GNUTLS_COMP_DEFLATE:
       {
@@ -574,51 +501,6 @@ _gnutls_decompress (comp_hd_t handle, opaque * compressed,
 
   switch (handle->algo)
     {
-#ifdef USE_LZO
-    case GNUTLS_COMP_LZO:
-      {
-        lzo_uint out_size;
-        lzo_uint new_size;
-        int err;
-
-        if (_gnutls_lzo1x_decompress_safe == NULL)
-          return GNUTLS_E_DECOMPRESSION_FAILED;
-
-        *plain = NULL;
-        out_size = compressed_size + compressed_size;
-        plain_size = 0;
-
-        do
-          {
-            out_size += 512;
-            *plain = gnutls_realloc_fast (*plain, out_size);
-            if (*plain == NULL)
-              {
-                gnutls_assert ();
-                return GNUTLS_E_MEMORY_ERROR;
-              }
-
-            new_size = out_size;
-            err =
-              _gnutls_lzo1x_decompress_safe (compressed,
-                                             compressed_size, *plain,
-                                             &new_size, NULL);
-
-          }
-        while ((err == LZO_E_OUTPUT_OVERRUN && out_size < max_record_size));
-
-        if (err != LZO_E_OK)
-          {
-            gnutls_assert ();
-            gnutls_free (*plain);
-            *plain = NULL;
-            return GNUTLS_E_DECOMPRESSION_FAILED;
-          }
-
-        plain_size = new_size;
-        break;
-      }
-#endif
 #ifdef HAVE_LIBZ
     case GNUTLS_COMP_DEFLATE:
       {
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c
index 0f37484..a77b65f 100644
--- a/lib/gnutls_dtls.c
+++ b/lib/gnutls_dtls.c
@@ -498,7 +498,7 @@ unsigned int gnutls_dtls_get_mtu (gnutls_session_t session)
  * @key: is a random key to be used at cookie generation
  * @client_data: contains data identifying the client (i.e. address)
  * @client_data_size: The size of client's data
- * @cookie: The previous cookie returned by gnutls_dtls_cookie_verify()
+ * @prestate: The previous cookie returned by gnutls_dtls_cookie_verify()
  * @ptr: A transport pointer to be used by @push_func
  * @push_func: A function that will be used to reply
  *
@@ -601,9 +601,9 @@ uint8_t digest[C_HASH_SIZE];
  * @key: is a random key to be used at cookie generation
  * @client_data: contains data identifying the client (i.e. address)
  * @client_data_size: The size of client's data
- * @msg: An incoming message that initiates a connection.
+ * @_msg: An incoming message that initiates a connection.
  * @msg_size: The size of the message.
- * @cookie: The cookie of this client.
+ * @prestate: The cookie of this client.
  *
  * This function will verify an incoming message for
  * a valid cookie. If a valid cookie is returned then
@@ -615,7 +615,7 @@ uint8_t digest[C_HASH_SIZE];
  **/
 int gnutls_dtls_cookie_verify(gnutls_datum_t* key, 
   void* client_data, size_t client_data_size, 
-  void* _msg, size_t msg_size, gnutls_dtls_prestate_st* out)
+  void* _msg, size_t msg_size, gnutls_dtls_prestate_st* prestate)
 {
 gnutls_datum_t cookie;
 int sid_size;
@@ -663,9 +663,9 @@ uint8_t digest[C_HASH_SIZE];
   if (memcmp(digest, cookie.data, COOKIE_MAC_SIZE) != 0)
     return gnutls_assert_val(GNUTLS_E_BAD_COOKIE);
   
-  out->record_seq = msg[10]; /* client's record seq */
-  out->hsk_read_seq =  msg[DTLS_RECORD_HEADER_SIZE+5]; /* client's hsk seq */
-  out->hsk_write_seq = 0;/* we always send zero for this msg */
+  prestate->record_seq = msg[10]; /* client's record seq */
+  prestate->hsk_read_seq =  msg[DTLS_RECORD_HEADER_SIZE+5]; /* client's hsk 
seq */
+  prestate->hsk_write_seq = 0;/* we always send zero for this msg */
   
   return 0;
 }
@@ -682,12 +682,12 @@ uint8_t digest[C_HASH_SIZE];
  * Returns: zero on success, or a negative error code.  
  *
  **/
-void gnutls_dtls_prestate_set(gnutls_session_t session, 
gnutls_dtls_prestate_st* st)
+void gnutls_dtls_prestate_set(gnutls_session_t session, 
gnutls_dtls_prestate_st* prestate)
 {
   record_parameters_st *params;
   int ret;
 
-  if (st == NULL)
+  if (prestate == NULL)
     return;
 
   /* we do not care about read_params, since we accept anything
@@ -697,8 +697,8 @@ void gnutls_dtls_prestate_set(gnutls_session_t session, 
gnutls_dtls_prestate_st*
   if (ret < 0)
     return;
 
-  params->write.sequence_number.i[7] = st->record_seq;
+  params->write.sequence_number.i[7] = prestate->record_seq;
 
-  session->internals.dtls.hsk_read_seq = st->hsk_read_seq;
-  session->internals.dtls.hsk_write_seq = st->hsk_write_seq + 1;
+  session->internals.dtls.hsk_read_seq = prestate->hsk_read_seq;
+  session->internals.dtls.hsk_write_seq = prestate->hsk_write_seq + 1;
 }
diff --git a/lib/gnutls_errors.c b/lib/gnutls_errors.c
index 3ba8a1a..c87f1cf 100644
--- a/lib/gnutls_errors.c
+++ b/lib/gnutls_errors.c
@@ -224,8 +224,6 @@ static const gnutls_error_entry error_algorithms[] = {
                GNUTLS_E_OPENPGP_KEYRING_ERROR, 1),
   ERROR_ENTRY (N_("The initialization of crypto backend has failed."),
                GNUTLS_E_CRYPTO_INIT_FAILED, 1),
-  ERROR_ENTRY (N_("The initialization of LZO has failed."),
-               GNUTLS_E_LZO_INIT_FAILED, 1),
   ERROR_ENTRY (N_("No supported compression algorithms have been found."),
                GNUTLS_E_NO_COMPRESSION_ALGORITHMS, 1),
   ERROR_ENTRY (N_("No supported cipher suites have been found."),
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index 1a59bdf..3c7f263 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -33,6 +33,7 @@
 #include <gnutls_extensions.h>  /* for _gnutls_ext_init */
 #include <gnutls_cryptodev.h>
 #include <locks.h>
+#include <accelerated/accelerated.h>
 
 #include "sockets.h"
 #include "gettext.h"
@@ -187,6 +188,8 @@ gnutls_global_init (void)
       return GNUTLS_E_CRYPTO_INIT_FAILED;
     }
 
+  _gnutls_register_accel_crypto();
+
   /* initialize ASN.1 parser
    * This should not deal with files in the final
    * version.
diff --git a/lib/gnutls_mem.c b/lib/gnutls_mem.c
index bc96662..0226fe2 100644
--- a/lib/gnutls_mem.c
+++ b/lib/gnutls_mem.c
@@ -106,6 +106,7 @@ _gnutls_strdup (const char *str)
 
 /**
  * gnutls_malloc:
+ * @s: size to allocate in bytes
  *
  * This function will allocate 's' bytes data, and
  * return a pointer to memory. This function is supposed
@@ -121,7 +122,7 @@ gnutls_malloc (size_t s)
 
 /**
  * gnutls_free:
- * @d: pointer to memory
+ * @ptr: pointer to memory
  *
  * This function will free data pointed by ptr.
  *
diff --git a/lib/gnutls_psk.c b/lib/gnutls_psk.c
index 20b9a06..c164178 100644
--- a/lib/gnutls_psk.c
+++ b/lib/gnutls_psk.c
@@ -78,7 +78,7 @@ gnutls_psk_allocate_client_credentials 
(gnutls_psk_client_credentials_t * sc)
  * @res: is a #gnutls_psk_client_credentials_t structure.
  * @username: is the user's zero-terminated userid
  * @key: is the user's key
- * @format: indicate the format of the key, either
+ * @flags: indicate the format of the key, either
  *   %GNUTLS_PSK_KEY_RAW or %GNUTLS_PSK_KEY_HEX.
  *
  * This function sets the username and password, in a
diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c
index 8ec637a..ceee3f0 100644
--- a/lib/gnutls_record.c
+++ b/lib/gnutls_record.c
@@ -1260,7 +1260,7 @@ gnutls_record_recv (gnutls_session_t session, void *data, 
size_t data_size)
  * @session: is a #gnutls_session_t structure.
  * @data: the buffer that the data will be read into
  * @data_size: the number of requested bytes
- * @seq: is the packet's 64-bit sequence number.
+ * @seq: is the packet's 64-bit sequence number. Should have space for 8 bytes.
  *
  * This function is the same as gnutls_record_recv(), except that
  * it returns in addition to data, the sequence number of the data.
@@ -1277,7 +1277,7 @@ gnutls_record_recv (gnutls_session_t session, void *data, 
size_t data_size)
  **/
 ssize_t
 gnutls_record_recv_seq (gnutls_session_t session, void *data, size_t data_size,
-  unsigned char seq[8])
+  unsigned char *seq)
 {
   return _gnutls_recv_int (session, GNUTLS_APPLICATION_DATA, -1, data,
                            data_size, seq);
diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c
index ed3037d..bce13df 100644
--- a/lib/gnutls_state.c
+++ b/lib/gnutls_state.c
@@ -764,9 +764,8 @@ _gnutls_record_set_default_version (gnutls_session_t 
session,
  * suites (the ones that start with 0xFF).  By default or if @allow
  * is 0 then these cipher suites will not be advertized nor used.
  *
- * Unless this function is called with the option to allow (1), then
- * no compression algorithms, like LZO.  That is because these
- * algorithms are not yet defined in any RFC or even internet draft.
+ * Currently GnuTLS does not include such cipher-suites or
+ * compression algorithms.
  *
  * Enabling the private ciphersuites when talking to other than
  * gnutls servers and clients may cause interoperability problems.
diff --git a/lib/includes/gnutls/crypto.h b/lib/includes/gnutls/crypto.h
index 0b2b00b..a1cf4b5 100644
--- a/lib/includes/gnutls/crypto.h
+++ b/lib/includes/gnutls/crypto.h
@@ -43,10 +43,12 @@ extern "C"
   int gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle,
                               const void *ciphertext, size_t ciphertextlen,
                               void *text, size_t textlen);
-  int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, void *text,
+  int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, const void *text,
                               size_t textlen, void *ciphertext,
                               size_t ciphertextlen);
 
+  void gnutls_cipher_set_iv (gnutls_cipher_hd_t handle, void *iv, size_t 
ivlen);
+
   int gnutls_cipher_tag( gnutls_cipher_hd_t handle, void* tag, size_t 
tag_size);
   int gnutls_cipher_add_auth( gnutls_cipher_hd_t handle, const void* test, 
size_t textlen);
 
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 8210021..3e7a715 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -263,7 +263,6 @@ extern "C"
    * @GNUTLS_COMP_NULL: The NULL compression method (uncompressed).
    * @GNUTLS_COMP_DEFLATE: The deflate/zlib compression method.
    * @GNUTLS_COMP_ZLIB: Same as %GNUTLS_COMP_DEFLATE.
-   * @GNUTLS_COMP_LZO: The non-standard LZO compression method.
    *
    * Enumeration of different TLS compression methods.
    */
@@ -273,9 +272,6 @@ extern "C"
     GNUTLS_COMP_NULL = 1,
     GNUTLS_COMP_DEFLATE = 2,
     GNUTLS_COMP_ZLIB = GNUTLS_COMP_DEFLATE,
-    GNUTLS_COMP_LZO = 3         /* only available if gnutls-extra has
-                                   been initialized
-                                 */
   } gnutls_compression_method_t;
 
   /**
@@ -782,7 +778,7 @@ extern "C"
 #define gnutls_read gnutls_record_recv
 #define gnutls_write gnutls_record_send
   ssize_t gnutls_record_recv_seq (gnutls_session_t session, void *data, size_t 
data_size,
-    unsigned char seq[8]);
+    unsigned char *seq);
 
   void gnutls_session_enable_compatibility_mode (gnutls_session_t session);
 
@@ -1214,7 +1210,6 @@ extern "C"
                                             gnutls_errno_func errno_func);
 
   void gnutls_transport_set_errno (gnutls_session_t session, int err);
-  void gnutls_transport_set_global_errno (int err);
 
 /* session specific 
  */
@@ -1644,7 +1639,6 @@ extern "C"
    */
 #define GNUTLS_E_NO_TEMPORARY_RSA_PARAMS -84
 
-#define GNUTLS_E_LZO_INIT_FAILED -85
 #define GNUTLS_E_NO_COMPRESSION_ALGORITHMS -86
 #define GNUTLS_E_NO_CIPHER_SUITES -87
 
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index f5d967e..85b301c 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -701,6 +701,7 @@ GNUTLS_3_0_0 {
        gnutls_dtls_cookie_send;
        gnutls_dtls_prestate_set;
        gnutls_dtls_get_data_mtu;
+       gnutls_cipher_set_iv;
 } GNUTLS_2_12;
 
 GNUTLS_PRIVATE {
@@ -714,11 +715,6 @@ GNUTLS_PRIVATE {
     _gnutls_read_uint24;
     _gnutls_get_cred;
     _gnutls_recv_int;
-    # Internal symbols needed by libgnutls-extra for LZO:
-    _gnutls_compression_algorithms;
-    _gnutls_comp_algorithms_size;
-    _gnutls_lzo1x_decompress_safe;
-    _gnutls_lzo1x_1_compress;
     # Internal symbols needed by libgnutls-openssl:
     _gnutls_pkix1_asn;
     _gnutls_x509_parse_dn_oid;
diff --git a/lib/pkcs11.c b/lib/pkcs11.c
index 81c043b..c261553 100644
--- a/lib/pkcs11.c
+++ b/lib/pkcs11.c
@@ -2011,7 +2011,7 @@ gnutls_pkcs11_obj_export_url (gnutls_pkcs11_obj_t obj,
 
 /**
  * gnutls_pkcs11_obj_get_type:
- * @certificate: Holds the PKCS 11 certificate
+ * @obj: Holds the PKCS 11 object
  *
  * This function will return the type of the certificate being
  * stored in the structure.
diff --git a/lib/pkcs11_privkey.c b/lib/pkcs11_privkey.c
index 7842f06..cf02a24 100644
--- a/lib/pkcs11_privkey.c
+++ b/lib/pkcs11_privkey.c
@@ -75,6 +75,7 @@ gnutls_pkcs11_privkey_deinit (gnutls_pkcs11_privkey_t key)
 /**
  * gnutls_pkcs11_privkey_get_pk_algorithm:
  * @key: should contain a #gnutls_pkcs11_privkey_t structure
+ * @bits: if bits is non null it will hold the size of the parameters' in bits
  *
  * This function will return the public key algorithm of a private
  * key.
diff --git a/lib/system_override.c b/lib/system_override.c
index e2a284c..44aec97 100644
--- a/lib/system_override.c
+++ b/lib/system_override.c
@@ -58,9 +58,6 @@
  * variable that is used by GnuTLS (e.g., the application is linked to
  * msvcr71.dll and gnutls is linked to msvcrt.dll).
  *
- * If you don't have the @session variable easily accessible from the
- * push/pull function, and don't worry about thread conflicts, you can
- * also use gnutls_transport_set_global_errno().
  **/
 void
 gnutls_transport_set_errno (gnutls_session_t session, int err)
@@ -69,49 +66,6 @@ gnutls_transport_set_errno (gnutls_session_t session, int 
err)
 }
 
 /**
- * gnutls_transport_set_global_errno:
- * @err: error value to store in global errno variable.
- *
- * Store @err in the global errno variable.  Useful values for @err is
- * EAGAIN and EINTR, other values are treated will be treated as real
- * errors in the push/pull function.
- *
- * This function is useful in replacement push/pull functions set by
- * gnutls_transport_set_push_function and
- * gnutls_transport_set_pullpush_function under Windows, where the
- * replacement push/pull may not have access to the same @errno
- * variable that is used by GnuTLS (e.g., the application is linked to
- * msvcr71.dll and gnutls is linked to msvcrt.dll).
- *
- * Whether this function is thread safe or not depends on whether the
- * global variable errno is thread safe, some system libraries make it
- * a thread-local variable.  When feasible, using the guaranteed
- * thread-safe gnutls_transport_set_errno() may be better.
- **/
-void
-gnutls_transport_set_global_errno (int err)
-{
-#ifdef _WIN32
-  /* Keep this in sync with system_errno */
-  switch (err)
-    {
-    case EAGAIN:
-      SetLastError (WSAEWOULDBLOCK);
-      break;
-    case EINTR:
-      SetLastError (WSAEINTR);
-      break;
-    default:
-      /* We don't care about anything else */
-      SetLastError (NO_ERROR);
-      break;
-    }
-#else
-  errno = err;
-#endif
-}
-
-/**
  * gnutls_transport_set_pull_function:
  * @session: is a #gnutls_session_t structure.
  * @pull_func: a callback function similar to read()
diff --git a/lib/x509/verify-high.c b/lib/x509/verify-high.c
index 479f3c2..7aaedcb 100644
--- a/lib/x509/verify-high.c
+++ b/lib/x509/verify-high.c
@@ -319,7 +319,8 @@ gnutls_datum_t dn;
 /**
  * gnutls_x509_trust_list_verify_crt:
  * @list: The structure of the list
- * @cert: is the certificate to be verified
+ * @cert_list: is the certificate list to be verified
+ * @cert_list_size: is the certificate list size
  * @flags: Flags that may be used to change the verification algorithm. Use OR 
of the gnutls_certificate_verify_flags enumerations.
  * @verify: will hold the certificate verification output.
  * @func: If non-null will be called on each chain element verification with 
the output.
diff --git a/lib/x509/verify.c b/lib/x509/verify.c
index f05c191..5b6831a 100644
--- a/lib/x509/verify.c
+++ b/lib/x509/verify.c
@@ -1194,10 +1194,10 @@ gnutls_x509_crt_verify (gnutls_x509_crt_t cert,
  *   negative error value.
  **/
 int
-gnutls_x509_crl_check_issuer (gnutls_x509_crl_t cert,
+gnutls_x509_crl_check_issuer (gnutls_x509_crl_t crl,
                               gnutls_x509_crt_t issuer)
 {
-  return is_crl_issuer (cert, issuer);
+  return is_crl_issuer (crl, issuer);
 }
 
 /**
diff --git a/libextra/Makefile.am b/libextra/Makefile.am
index 27a05ba..6bfe0b8 100644
--- a/libextra/Makefile.am
+++ b/libextra/Makefile.am
@@ -97,8 +97,7 @@ endif
 DISTCLEANFILES += $(defexec_DATA)
 
 libgnutls_extra_la_LDFLAGS += \
-       -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-       $(LZO_LIBS)
+       -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
 libgnutls_extra_la_LIBADD += ../gl/libgnu.la \
        ../lib/libgnutls.la
diff --git a/libextra/gnutls_extra.c b/libextra/gnutls_extra.c
index 302b092..bdcbfcc 100644
--- a/libextra/gnutls_extra.c
+++ b/libextra/gnutls_extra.c
@@ -25,69 +25,12 @@
 #include <gnutls_errors.h>
 #include <gnutls_extensions.h>
 #include <gnutls_algorithms.h>
+#include <gnutls/extra.h>
 
 #ifdef HAVE_GCRYPT
 #include <gcrypt.h>
 #endif
 
-#ifdef USE_LZO
-#ifdef USE_MINILZO
-#include "minilzo/minilzo.h"
-#elif HAVE_LZO_LZO1X_H
-#include <lzo/lzo1x.h>
-#elif HAVE_LZO1X_H
-#include <lzo1x.h>
-#endif
-#endif
-#include <gnutls/extra.h>
-
-#ifdef USE_LZO
-#include <gnutls_compress.h>
-
-/* the number of the compression algorithms available in the compression
- * structure.
- */
-extern int _gnutls_comp_algorithms_size;
-
-typedef int (*LZO_FUNC) ();
-extern LZO_FUNC _gnutls_lzo1x_decompress_safe;
-extern LZO_FUNC _gnutls_lzo1x_1_compress;
-
-extern gnutls_compression_entry _gnutls_compression_algorithms[];
-
-static int
-_gnutls_add_lzo_comp (void)
-{
-  int i;
-
-  /* find the last element */
-  for (i = 0; i < _gnutls_comp_algorithms_size; i++)
-    {
-      if (_gnutls_compression_algorithms[i].name == NULL)
-        break;
-    }
-
-  if (_gnutls_compression_algorithms[i].name == NULL
-      && (i < _gnutls_comp_algorithms_size - 1))
-    {
-      _gnutls_compression_algorithms[i].name = "GNUTLS_COMP_LZO";
-      _gnutls_compression_algorithms[i].id = GNUTLS_COMP_LZO;
-      _gnutls_compression_algorithms[i].num = 0xf2;
-
-      _gnutls_compression_algorithms[i + 1].name = 0;
-
-      /* Now enable the lzo functions: */
-      _gnutls_lzo1x_decompress_safe = lzo1x_decompress_safe;
-      _gnutls_lzo1x_1_compress = lzo1x_1_compress;
-
-      return 0;                 /* ok */
-    }
-
-
-  return GNUTLS_E_MEMORY_ERROR;
-}
-#endif
-
 static int _gnutls_init_extra = 0;
 
 /**
@@ -123,28 +66,6 @@ gnutls_global_init_extra (void)
   if (_gnutls_init_extra != 1)
     return 0;
 
-  /* Initialize the LZO library
-   */
-#ifdef USE_LZO
-  if (lzo_init () != LZO_E_OK)
-    return GNUTLS_E_LZO_INIT_FAILED;
-
-  /* Add the LZO compression method in the list of compression
-   * methods.
-   */
-  {
-    int ret;
-
-    ret = _gnutls_add_lzo_comp ();
-    if (ret < 0)
-      {
-       gnutls_assert ();
-       return ret;
-      }
-  }
-#endif
-
-
 #ifdef HAVE_GCRYPT
 #ifdef gcry_fips_mode_active
   /* Libgcrypt manual says that gcry_version_check must be called
diff --git a/m4/gcc.m4 b/m4/gcc.m4
new file mode 100644
index 0000000..78ba570
--- /dev/null
+++ b/m4/gcc.m4
@@ -0,0 +1,28 @@
+# gcc.m4 serial 2
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Based on code by Simon Josefsson
+
+# GCC_FLAG_ADD(PARAMETER, [ACTION])
+# ------------------------------------------------
+# Adds parameter to CFLAGS if the compiler supports it.  For example,
+# GCC_FLAG_ADD([-maes], [VAR]).
+AC_DEFUN([GCC_FLAG_ADD],
+[AS_VAR_PUSHDEF([GCC_FLAG], [gl_cv_GCC_FLAG_$1])dnl
+AC_CACHE_CHECK([whether compiler handles $1], [GCC_FLAG], [
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="${CFLAGS} $1"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
+                    [AS_VAR_SET([GCC_FLAG], [yes])],
+                    [AS_VAR_SET([GCC_FLAG], [no])])
+  CFLAGS="$save_CFLAGS"
+])
+AS_VAR_IF([GCC_FLAG], [yes], [
+m4_ifval([$2], [AC_SUBST([$2],[yes])])
+CFLAGS="${CFLAGS} $1"
+])dnl
+AS_VAR_POPDEF([GCC_FLAG])
+])
diff --git a/m4/hooks.m4 b/m4/hooks.m4
index c629e6f..76a366c 100644
--- a/m4/hooks.m4
+++ b/m4/hooks.m4
@@ -156,35 +156,6 @@ fi
 
   fi
 
-  AC_ARG_WITH(lzo,
-    AS_HELP_STRING([--with-lzo], [use experimental LZO compression]),
-                   use_lzo=$withval, use_lzo=no)
-  AC_MSG_CHECKING([whether to include LZO compression support])
-  AC_MSG_RESULT($use_lzo)
-  LZO_LIBS=
-  if test "$use_lzo" = "yes"; then
-    AC_CHECK_LIB(lzo2, lzo1x_1_compress, LZO_LIBS=-llzo2)
-    if test "$LZO_LIBS" = ""; then
-      AC_CHECK_LIB(lzo, lzo1x_1_compress, LZO_LIBS=-llzo, [
-        use_lzo=no
-        AC_MSG_WARN(
-  ***
-  *** Could not find liblzo or liblzo2.  Disabling LZO compression.
-  )
-        ])
-    fi
-  fi
-  AC_SUBST(LZO_LIBS)
-  if test "$use_lzo" = "yes"; then
-    AC_DEFINE([USE_LZO], 1, [whether to use the LZO compression])
-    if test "$LZO_LIBS" = "-llzo"; then
-      AC_CHECK_HEADERS(lzo1x.h)
-    elif test "$LZO_LIBS" = "-llzo2"; then
-      AC_CHECK_HEADERS(lzo/lzo1x.h)
-    fi
-  fi
-  AM_CONDITIONAL(USE_LZO, test "$use_lzo" = "yes")
-
   AC_MSG_CHECKING([whether C99 macros are supported])
   AC_TRY_COMPILE(,
   [
diff --git a/src/cli.c b/src/cli.c
index 82a2eb8..31eb80e 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -677,19 +677,58 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
+#define IN_KEYBOARD 1
+#define IN_NET 2
+#define IN_NONE 0
+/* returns IN_KEYBOARD for keyboard input and IN_NET for network input
+ */
+static int check_net_or_keyboard_input(socket_st* hd)
+{
+  int maxfd;
+  fd_set rset;
+  int err;
+  struct timeval tv;
+
+  do
+    {
+      FD_ZERO (&rset);
+      FD_SET (fileno (stdin), &rset);
+      FD_SET (hd->fd, &rset);
+
+      maxfd = MAX (fileno (stdin), hd->fd);
+      tv.tv_sec = 0;
+      tv.tv_usec = 500 * 1000;
+
+      if (hd->secure == 1)
+        if (gnutls_record_check_pending(hd->session))
+          return IN_NET;
+
+      err = select (maxfd + 1, &rset, NULL, NULL, &tv);
+      if (err < 0)
+        continue;
+
+      if (FD_ISSET (hd->fd, &rset))
+        return IN_NET;
+
+
+      if (FD_ISSET (fileno (stdin), &rset))
+        return IN_KEYBOARD;
+    }
+  while(err == 0);
+  
+  return IN_NONE;
+}
+
 int
 main (int argc, char **argv)
 {
-  int err, ret;
-  int ii, i;
+  int ret;
+  int ii, i, inp;
   char buffer[MAX_BUF + 1];
   char *session_data = NULL;
   char *session_id = NULL;
   size_t session_data_size;
   size_t session_id_size = 0;
-  fd_set rset;
-  int maxfd;
-  struct timeval tv;
   int user_term = 0, retval = 0;
   socket_st hd;
   ssize_t bytes;
@@ -848,19 +887,9 @@ after_handshake:
             }
         }
 
-      FD_ZERO (&rset);
-      FD_SET (fileno (stdin), &rset);
-      FD_SET (hd.fd, &rset);
+      inp = check_net_or_keyboard_input(&hd);
 
-      maxfd = MAX (fileno (stdin), hd.fd);
-      tv.tv_sec = 3;
-      tv.tv_usec = 0;
-
-      err = select (maxfd + 1, &rset, NULL, NULL, &tv);
-      if (err < 0)
-        continue;
-
-      if (FD_ISSET (hd.fd, &rset))
+      if (inp == IN_NET)
         {
           memset (buffer, 0, MAX_BUF + 1);
           ret = socket_recv (&hd, buffer, MAX_BUF);
@@ -892,7 +921,7 @@ after_handshake:
             break;
         }
 
-      if (FD_ISSET (fileno (stdin), &rset))
+      if (inp == IN_KEYBOARD)
         {
           if ((bytes = read (fileno (stdin), buffer, MAX_BUF - 1)) <= 0)
             {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa33da4..3c58d68 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -64,7 +64,7 @@ ctests = simple gc set_pkcs12_cred certder certuniqueid mpi   
                \
        crq_key_id x509sign-verify cve-2009-1415 cve-2009-1416          \
        crq_apis init_roundtrip pkcs12_s2k_pem dn2 mini-eagain          \
        nul-in-x509-names x509_altname pkcs12_encode mini-x509          \
-       mini-x509-rehandshake rng-fork mini-eagain-dtls #gendh
+       mini-x509-rehandshake rng-fork mini-eagain-dtls cipher-test #gendh
 
 if ENABLE_OPENSSL
 ctests +=  openssl
@@ -100,5 +100,3 @@ TESTS_ENVIRONMENT =                                         
\
        srcdir="$(srcdir)"                                      \
        $(VALGRIND)
 
-check-local:
-       if test -d suite; then $(MAKE) -C suite check; fi
diff --git a/tests/cipher-test.c b/tests/cipher-test.c
new file mode 100644
index 0000000..d9ae400
--- /dev/null
+++ b/tests/cipher-test.c
@@ -0,0 +1,331 @@
+/*
+ * Demo on how to use /dev/ncr device for HMAC.
+ *
+ * Placed under public domain.
+ *
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
+
+struct aes_vectors_st {
+       const uint8_t *key;
+       const uint8_t *plaintext;
+       const uint8_t *ciphertext;
+} aes_vectors[] = {
+       {
+       .key =
+                   (uint8_t *)
+                   
"\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   plaintext =
+                   (uint8_t *)
+                   
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   ciphertext =
+                   (uint8_t *)
+                   
"\x4b\xc3\xf8\x83\x45\x0c\x11\x3c\x64\xca\x42\xe1\x11\x2a\x9e\x87",},
+       {
+       .key =
+                   (uint8_t *)
+                   
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   plaintext =
+                   (uint8_t *)
+                   
"\xf3\x44\x81\xec\x3c\xc6\x27\xba\xcd\x5d\xc3\xfb\x08\xf2\x73\xe6",.
+                   ciphertext =
+                   (uint8_t *)
+                   
"\x03\x36\x76\x3e\x96\x6d\x92\x59\x5a\x56\x7c\xc9\xce\x53\x7f\x5e",},
+       {
+       .key =
+                   (uint8_t *)
+                   
"\x10\xa5\x88\x69\xd7\x4b\xe5\xa3\x74\xcf\x86\x7c\xfb\x47\x38\x59",.
+                   plaintext =
+                   (uint8_t *)
+                   
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   ciphertext =
+                   (uint8_t *)
+                   
"\x6d\x25\x1e\x69\x44\xb0\x51\xe0\x4e\xaa\x6f\xb4\xdb\xf7\x84\x65",},
+       {
+       .key =
+                   (uint8_t *)
+                   
"\xca\xea\x65\xcd\xbb\x75\xe9\x16\x9e\xcd\x22\xeb\xe6\xe5\x46\x75",.
+                   plaintext =
+                   (uint8_t *)
+                   
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   ciphertext =
+                   (uint8_t *)
+                   
"\x6e\x29\x20\x11\x90\x15\x2d\xf4\xee\x05\x81\x39\xde\xf6\x10\xbb",},
+       {
+.key =
+                   (uint8_t *)
+                   
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",.
+                   plaintext =
+                   (uint8_t *)
+                   
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",.
+                   ciphertext =
+                   (uint8_t *)
+                   
"\x9b\xa4\xa9\x14\x3f\x4e\x5d\x40\x48\x52\x1c\x4f\x88\x77\xd8\x8e",},};
+
+/* AES cipher */
+static int test_aes(void)
+{
+       gnutls_cipher_hd_t hd;
+       int ret, i, j;
+       uint8_t _iv[16];
+       uint8_t tmp[16];
+       gnutls_datum_t key, iv;
+       
+       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;
+               
+               iv.data = _iv;
+               iv.size = 16;
+
+               ret = gnutls_cipher_init( &hd, GNUTLS_CIPHER_AES_128_CBC, 
+                       &key, &iv);
+               if (ret < 0) {
+                       fprintf(stderr, "%d: AES test %d failed\n", __LINE__, 
i);
+                       return 1;
+               }
+               
+               ret = gnutls_cipher_encrypt2(hd, aes_vectors[i].plaintext, 16,
+                       tmp, 16);
+               if (ret < 0) {
+                       fprintf(stderr, "%d: AES test %d failed\n", __LINE__, 
i);
+                       return 1;
+               }
+               
+               gnutls_cipher_deinit(hd);
+
+               if (memcmp(tmp, aes_vectors[i].ciphertext, 16) != 0) {
+                       fprintf(stderr, "AES test vector %d failed!\n", i);
+
+                       fprintf(stderr, "Cipher[%d]: ", 16);
+                       for (j = 0; j < 16; j++)
+                               fprintf(stderr, "%.2x:", (int)tmp[j]);
+                       fprintf(stderr, "\n");
+
+                       fprintf(stderr, "Expected[%d]: ", 16);
+                       for (j = 0; j < 16; j++)
+                               fprintf(stderr, "%.2x:",
+                                       (int)aes_vectors[i].ciphertext[j]);
+                       fprintf(stderr, "\n");
+                       return 1;
+               }
+       }
+       fprintf(stdout, "ok\n");
+
+       fprintf(stdout, "Tests on AES Decryption: ");
+       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;
+               
+               iv.data = _iv;
+               iv.size = 16;
+
+               ret = gnutls_cipher_init( &hd, GNUTLS_CIPHER_AES_128_CBC, 
+                       &key, &iv);
+               if (ret < 0) {
+                       fprintf(stderr, "%d: AES test %d failed\n", __LINE__, 
i);
+                       return 1;
+               }
+               
+               ret = gnutls_cipher_decrypt2(hd, aes_vectors[i].ciphertext, 16,
+                       tmp, 16);
+               if (ret < 0) {
+                       fprintf(stderr, "%d: AES test %d failed\n", __LINE__, 
i);
+                       return 1;
+               }
+               
+               gnutls_cipher_deinit(hd);
+
+               if (memcmp(tmp, aes_vectors[i].plaintext, 16) != 0) {
+                       fprintf(stderr, "AES test vector %d failed!\n", i);
+
+                       fprintf(stderr, "Plain[%d]: ", 16);
+                       for (j = 0; j < 16; j++)
+                               fprintf(stderr, "%.2x:", (int)tmp[j]);
+                       fprintf(stderr, "\n");
+
+                       fprintf(stderr, "Expected[%d]: ", 16);
+                       for (j = 0; j < 16; j++)
+                               fprintf(stderr, "%.2x:",
+                                       (int)aes_vectors[i].plaintext[j]);
+                       fprintf(stderr, "\n");
+                       return 1;
+               }
+       }
+
+       fprintf(stdout, "ok\n");
+       fprintf(stdout, "\n");
+
+       return 0;
+
+}
+
+struct hash_vectors_st {
+       const char * name;
+       int algorithm;
+       const uint8_t *key;     /* if hmac */
+       int key_size;
+       const uint8_t *plaintext;
+       int plaintext_size;
+       const uint8_t *output;
+       int output_size;
+} hash_vectors[] = {
+       {
+       .name = "SHA1",
+       .algorithm = GNUTLS_MAC_SHA1,.key = NULL,.plaintext =
+                   (uint8_t *) "what do ya want for nothing?",.
+                   plaintext_size =
+                   sizeof("what do ya want for nothing?") - 1,.output =
+                   (uint8_t *)
+                   
"\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32",.
+                   output_size = 20,}
+       , {
+       .name = "HMAC-MD5",
+       .algorithm = GNUTLS_MAC_MD5,.key = (uint8_t *) "Jefe",.key_size =
+                   4,.plaintext =
+                   (uint8_t *) "what do ya want for nothing?",.
+                   plaintext_size =
+                   sizeof("what do ya want for nothing?") - 1,.output =
+                   (uint8_t *)
+                   
"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",.
+                   output_size = 16,}
+       ,
+           /* from rfc4231 */
+       {
+       .name = "HMAC-SHA2-224",
+       .algorithm = GNUTLS_MAC_SHA224,.key =
+                   (uint8_t *)
+                   
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
+                   key_size = 20,.plaintext =
+                   (uint8_t *) "Hi There",.plaintext_size =
+                   sizeof("Hi There") - 1,.output =
+                   (uint8_t *)
+                   
"\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22",.
+                   output_size = 28,}
+       , {
+       .name = "HMAC-SHA2-256",
+       .algorithm = GNUTLS_MAC_SHA256,.key =
+                   (uint8_t *)
+                   
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
+                   key_size = 20,.plaintext =
+                   (uint8_t *) "Hi There",.plaintext_size =
+                   sizeof("Hi There") - 1,.output =
+                   (uint8_t *)
+                   
"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7",.
+                   output_size = 32,}
+       , {
+       .name = "HMAC-SHA2-384",
+       .algorithm = GNUTLS_MAC_SHA384,.key =
+                   (uint8_t *)
+                   
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
+                   key_size = 20,.plaintext =
+                   (uint8_t *) "Hi There",.plaintext_size =
+                   sizeof("Hi There") - 1,.output =
+                   (uint8_t *)
+                   
"\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",.
+                   output_size = 48,}
+       , {
+       .name = "HMAC-SHA2-512",
+       .algorithm = GNUTLS_MAC_SHA512,.key =
+                   (uint8_t *)
+                   
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
+                   key_size = 20,.plaintext =
+                   (uint8_t *) "Hi There",.plaintext_size =
+                   sizeof("Hi There") - 1,.output =
+                   (uint8_t *)
+                   
"\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54",.
+                   output_size = 64,}
+,};
+
+#define HASH_DATA_SIZE 64
+
+/* SHA1 and other hashes */
+static int test_hash(void)
+{
+       uint8_t data[HASH_DATA_SIZE];
+       int i, j, ret;
+       size_t data_size;
+
+       fprintf(stdout, "Tests on Hashes\n");
+       for (i = 0; i < sizeof(hash_vectors) / sizeof(hash_vectors[0]); i++) {
+
+               fprintf(stdout, "\t%s: ", hash_vectors[i].name);
+               /* import key */
+               if (hash_vectors[i].key != NULL) {
+
+                       ret = gnutls_hmac_fast( hash_vectors[i].algorithm,
+                               hash_vectors[i].key, hash_vectors[i].key_size,
+                               hash_vectors[i].plaintext, 
hash_vectors[i].plaintext_size,
+                               data);
+                       data_size = 
gnutls_hmac_get_len(hash_vectors[i].algorithm);
+                       if (ret < 0) {
+                               fprintf(stderr, "Error: %s:%d\n", __func__,
+                                       __LINE__);
+                               return 1;
+                       }
+               } else {
+                       ret = gnutls_hash_fast( hash_vectors[i].algorithm,
+                               hash_vectors[i].plaintext, 
hash_vectors[i].plaintext_size,
+                               data);
+                       data_size = 
gnutls_hash_get_len(hash_vectors[i].algorithm);
+                       if (ret < 0) {
+                               fprintf(stderr, "Error: %s:%d\n", __func__,
+                                       __LINE__);
+                               return 1;
+                       }
+               }
+
+               if (data_size != hash_vectors[i].output_size ||
+                   memcmp(data, hash_vectors[i].output,
+                          hash_vectors[i].output_size) != 0) {
+                       fprintf(stderr, "HASH test vector %d failed!\n", i);
+
+                       fprintf(stderr, "Output[%d]: ", (int)data_size);
+                       for (j = 0; j < data_size; j++)
+                               fprintf(stderr, "%.2x:", (int)data[j]);
+                       fprintf(stderr, "\n");
+
+                       fprintf(stderr, "Expected[%d]: ",
+                               hash_vectors[i].output_size);
+                       for (j = 0; j < hash_vectors[i].output_size; j++)
+                               fprintf(stderr, "%.2x:",
+                                       (int)hash_vectors[i].output[j]);
+                       fprintf(stderr, "\n");
+                       return 1;
+               }
+               
+               fprintf(stdout, "ok\n");
+       }
+
+       fprintf(stdout, "\n");
+
+       return 0;
+
+}
+
+
+int main(int argc, char** argv)
+{
+        gnutls_global_init();
+
+       if (test_aes())
+               return 1;
+
+       if (test_hash())
+               return 1;
+
+        gnutls_global_deinit();
+       return 0;
+}
diff --git a/tests/eagain-common.h b/tests/eagain-common.h
index 473e236..d75e787 100644
--- a/tests/eagain-common.h
+++ b/tests/eagain-common.h
@@ -1,7 +1,7 @@
 #define min(x,y) ((x)<(y)?(x):(y))
 //#define EAGAIN_DEBUG
 
-#define HANDSHAKE(c, s) \
+#define HANDSHAKE_EXPECT(c, s, clierr, serverr) \
   sret = cret = GNUTLS_E_AGAIN; \
   do \
     { \
@@ -14,8 +14,8 @@
           sret = gnutls_handshake (s); \
         } \
     } \
-  while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); \
-  if (cret < 0 || sret < 0) \
+  while ((cret == GNUTLS_E_AGAIN || (cret == 0 && sret == GNUTLS_E_AGAIN)) && 
(sret == GNUTLS_E_AGAIN || (sret == 0 && cret == GNUTLS_E_AGAIN))); \
+  if (cret != clierr || sret != serverr) \
     { \
       fprintf(stderr, "client: %s\n", gnutls_strerror(cret)); \
       fprintf(stderr, "server: %s\n", gnutls_strerror(sret)); \
@@ -23,6 +23,9 @@
       exit(1); \
     }
 
+#define HANDSHAKE(c, s) \
+  HANDSHAKE_EXPECT(c,s,0,0)
+
 #define TRANSFER(c, s, msg, msglen, buf, buflen) \
   do \
     { \
@@ -131,7 +134,7 @@ client_pull (gnutls_transport_ptr_t tr, void *data, size_t 
len)
 #ifdef EAGAIN_DEBUG
       fprintf(stderr, "eagain: Not enough data by server (asked for: %d, have: 
%d)\n", (int)len, (int)to_client_len);
 #endif
-      gnutls_transport_set_global_errno (EAGAIN);
+      gnutls_transport_set_errno ((gnutls_session_t)tr, EAGAIN);
       return -1;
     }
 
@@ -158,7 +161,7 @@ server_pull (gnutls_transport_ptr_t tr, void *data, size_t 
len)
 #ifdef EAGAIN_DEBUG
       fprintf(stderr, "eagain: Not enough data by client (asked for: %d, have: 
%d)\n", (int)len, (int)to_server_len);
 #endif
-      gnutls_transport_set_global_errno (EAGAIN);
+      gnutls_transport_set_errno ((gnutls_session_t)tr, EAGAIN);
       return -1;
     }
 
diff --git a/tests/safe-renegotiation/Makefile.am 
b/tests/safe-renegotiation/Makefile.am
index d6a5593..8b0c658 100644
--- a/tests/safe-renegotiation/Makefile.am
+++ b/tests/safe-renegotiation/Makefile.am
@@ -23,7 +23,8 @@ AM_CPPFLAGS = \
        -I$(top_builddir)/lib/includes
 
 AM_LDFLAGS = -no-install
-LDADD = ../../lib/libgnutls.la $(LTLIBGCRYPT) $(LIBSOCKET)
+LDADD = ../libutils.la \
+       ../../lib/libgnutls.la $(LTLIBGCRYPT) $(LIBSOCKET)
 
 ctests = srn0 srn1 srn2 srn3 srn4 srn5
 
diff --git a/tests/safe-renegotiation/srn0.c b/tests/safe-renegotiation/srn0.c
index 629fd76..71839f7 100644
--- a/tests/safe-renegotiation/srn0.c
+++ b/tests/safe-renegotiation/srn0.c
@@ -37,6 +37,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -44,80 +46,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -159,11 +87,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -176,7 +101,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (2);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -188,6 +113,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (server, "NORMAL", NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -196,53 +122,19 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (client, "NORMAL", NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE(client, server);
 
   if (!gnutls_safe_renegotiation_status (client) ||
       !gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0, "Session not using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -257,52 +149,14 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = 1;
+  HANDSHAKE(client, server);
 
   if (!gnutls_safe_renegotiation_status (client) ||
       !gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0,
                     "Rehandshaked session not using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
@@ -311,20 +165,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }
diff --git a/tests/safe-renegotiation/srn1.c b/tests/safe-renegotiation/srn1.c
index 2b996b0..6907d85 100644
--- a/tests/safe-renegotiation/srn1.c
+++ b/tests/safe-renegotiation/srn1.c
@@ -36,6 +36,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -43,80 +45,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -158,11 +86,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -175,7 +100,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (5);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -187,6 +112,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (server, "NORMAL:%SAFE_RENEGOTIATION", NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -196,6 +122,7 @@ main (int argc, char *argv[])
                               NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
   /* Check that initially no session use the extension. */
   if (gnutls_safe_renegotiation_status (server)
@@ -205,39 +132,7 @@ main (int argc, char *argv[])
       abort ();
     }
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while ((cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_SUCCESS)
-         && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SAFE_RENEGOTIATION_FAILED)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, 
GNUTLS_E_SAFE_RENEGOTIATION_FAILED);
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
   gnutls_bye (server, GNUTLS_SHUT_RDWR);
@@ -245,20 +140,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }
diff --git a/tests/safe-renegotiation/srn2.c b/tests/safe-renegotiation/srn2.c
index 8c9d444..d006aaa 100644
--- a/tests/safe-renegotiation/srn2.c
+++ b/tests/safe-renegotiation/srn2.c
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -41,80 +43,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -156,11 +84,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -173,7 +98,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (2);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -185,6 +110,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (server, "NORMAL", NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -193,6 +119,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (client, "NORMAL", NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
   /* Check that initially no session use the extension. */
   if (gnutls_safe_renegotiation_status (server)
@@ -202,42 +129,7 @@ main (int argc, char *argv[])
       abort ();
     }
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE(client, server);
 
   /* Check that both sessions use the extension. */
   if (!gnutls_safe_renegotiation_status (server)
@@ -248,7 +140,7 @@ main (int argc, char *argv[])
     }
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -263,45 +155,7 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = 1;
+  HANDSHAKE(client, server);
 
   /* Check that session still use the extension. */
   if (!gnutls_safe_renegotiation_status (server)
@@ -316,7 +170,7 @@ main (int argc, char *argv[])
      gnutls_safe_negotiation_set_initial (server, 0); */
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -331,51 +185,13 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = 1;
+  HANDSHAKE(client, server);
 
   /* Check that disabling the extension will break rehandshakes.
      gnutls_safe_renegotiation_set (client, 0); */
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -390,45 +206,7 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = 1;
+  HANDSHAKE(client, server);
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
   gnutls_bye (server, GNUTLS_SHUT_RDWR);
@@ -436,20 +214,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }
diff --git a/tests/safe-renegotiation/srn3.c b/tests/safe-renegotiation/srn3.c
index 71f0ac3..45a8980 100644
--- a/tests/safe-renegotiation/srn3.c
+++ b/tests/safe-renegotiation/srn3.c
@@ -36,6 +36,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -43,80 +45,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -158,11 +86,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -175,7 +100,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (2);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -188,6 +113,7 @@ main (int argc, char *argv[])
                               NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -196,6 +122,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (client, "NORMAL:%SAFE_RENEGOTIATION", NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
   /* Check that initially no session use the extension. */
   if (gnutls_safe_renegotiation_status (server)
@@ -205,39 +132,7 @@ main (int argc, char *argv[])
       abort ();
     }
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while ((cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_SUCCESS)
-         && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS));
-
-  if (cret != GNUTLS_E_SAFE_RENEGOTIATION_FAILED && sret != GNUTLS_E_SUCCESS)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE_EXPECT(client, server, GNUTLS_E_SAFE_RENEGOTIATION_FAILED, 
GNUTLS_E_AGAIN);
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
   gnutls_bye (server, GNUTLS_SHUT_RDWR);
@@ -245,20 +140,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }
diff --git a/tests/safe-renegotiation/srn4.c b/tests/safe-renegotiation/srn4.c
index 8ab1bb2..aa8ede4 100644
--- a/tests/safe-renegotiation/srn4.c
+++ b/tests/safe-renegotiation/srn4.c
@@ -36,6 +36,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -43,80 +45,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -158,11 +86,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -175,7 +100,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (2);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -187,6 +112,7 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (server, "NORMAL", NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -196,53 +122,19 @@ main (int argc, char *argv[])
                               NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE(client, server);
 
   if (gnutls_safe_renegotiation_status (client) ||
       gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0, "Session using safe renegotiation but shouldn't!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -257,53 +149,14 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_AGAIN
-            && sret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_AGAIN && sret != GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED)
-    exit_code = 1;
+  HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, 
GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED);
 
   if (gnutls_safe_renegotiation_status (client) ||
       gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0,
                     "Rehandshaked session not using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
@@ -312,20 +165,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }
diff --git a/tests/safe-renegotiation/srn5.c b/tests/safe-renegotiation/srn5.c
index 2eb1975..569d34c 100644
--- a/tests/safe-renegotiation/srn5.c
+++ b/tests/safe-renegotiation/srn5.c
@@ -37,6 +37,8 @@
 #include <string.h>
 #include <errno.h>
 #include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
 
 static void
 tls_log_func (int level, const char *str)
@@ -44,80 +46,6 @@ tls_log_func (int level, const char *str)
   fprintf (stderr, "|<%d>| %s", level, str);
 }
 
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_client_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_client, len);
-
-  memmove (to_client, to_client + len, to_client_len - len);
-  to_client_len -= len;
-
-  return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_server_len + len;
-  char *tmp;
-
-  tmp = realloc (to_server, newlen);
-  if (!tmp)
-    abort ();
-  to_server = tmp;
-
-  memcpy (to_server + to_server_len, data, len);
-  to_server_len = newlen;
-
-  return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
-  if (to_server_len < len)
-    {
-      gnutls_transport_set_global_errno (EAGAIN);
-      return -1;
-    }
-
-  memcpy (data, to_server, len);
-
-  memmove (to_server, to_server + len, to_server_len - len);
-  to_server_len -= len;
-
-  return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-  size_t newlen = to_client_len + len;
-  char *tmp;
-
-  tmp = realloc (to_client, newlen);
-  if (!tmp)
-    abort ();
-  to_client = tmp;
-
-  memcpy (to_client + to_client_len, data, len);
-  to_client_len = newlen;
-
-  return len;
-}
-
 static unsigned char server_cert_pem[] =
   "-----BEGIN CERTIFICATE-----\n"
   "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -159,11 +87,8 @@ const gnutls_datum_t server_key = { server_key_pem,
   sizeof (server_key_pem)
 };
 
-int
-main (int argc, char *argv[])
+void doit(void)
 {
-  int debug_level = argc - 1;
-  int exit_code = EXIT_SUCCESS;
   /* Server stuff. */
   gnutls_certificate_credentials_t serverx509cred;
   gnutls_session_t server;
@@ -176,7 +101,7 @@ main (int argc, char *argv[])
   /* General init. */
   gnutls_global_init ();
   gnutls_global_set_log_function (tls_log_func);
-  gnutls_global_set_log_level (debug_level);
+  if (debug) gnutls_global_set_log_level (2);
 
   /* Init server */
   gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -189,6 +114,7 @@ main (int argc, char *argv[])
                               NULL);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
+  gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
   gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -197,58 +123,24 @@ main (int argc, char *argv[])
   gnutls_priority_set_direct (client, "NORMAL", NULL);
   gnutls_transport_set_push_function (client, client_push);
   gnutls_transport_set_pull_function (client, client_pull);
+  gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS)
-    exit_code = EXIT_FAILURE;
+  HANDSHAKE(client, server);
 
   if (gnutls_safe_renegotiation_status (client))
     {
       tls_log_func (0, "Client thinks it is using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   if (gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0, "Server thinks it is using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   sret = gnutls_rehandshake (server);
-  if (debug_level > 0)
+  if (debug)
     {
       tls_log_func (0, "gnutls_rehandshake (server)...\n");
       tls_log_func (0, gnutls_strerror (sret));
@@ -263,53 +155,14 @@ main (int argc, char *argv[])
       abort ();
   }
 
-  cret = GNUTLS_E_AGAIN;
-  sret = GNUTLS_E_AGAIN;
-
-  do
-    {
-      static int max_iter = 0;
-      if (max_iter++ > 10)
-        abort ();
-
-      if (cret == GNUTLS_E_AGAIN)
-        {
-          cret = gnutls_handshake (client);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (client)...\n");
-              tls_log_func (0, gnutls_strerror (cret));
-              tls_log_func (0, "\n");
-            }
-        }
-
-      if (sret == GNUTLS_E_AGAIN)
-        {
-          sret = gnutls_handshake (server);
-          if (debug_level > 0)
-            {
-              tls_log_func (0, "second gnutls_handshake (server)...\n");
-              tls_log_func (0, gnutls_strerror (sret));
-              tls_log_func (0, "\n");
-            }
-        }
-    }
-  while (
-          /* Not done: */
-          !(sret == GNUTLS_E_AGAIN
-            && cret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED)
-          /* No error: */
-          && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN));
-
-  if (sret != GNUTLS_E_AGAIN && cret != GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED)
-    exit_code = 1;
+  HANDSHAKE_EXPECT(client, server, GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED, 
GNUTLS_E_AGAIN);
 
   if (gnutls_safe_renegotiation_status (client) ||
       gnutls_safe_renegotiation_status (server))
     {
       tls_log_func (0,
                     "Rehandshaked session not using safe renegotiation!\n");
-      exit_code = EXIT_FAILURE;
+      exit(1);
     }
 
   gnutls_bye (client, GNUTLS_SHUT_RDWR);
@@ -318,20 +171,15 @@ main (int argc, char *argv[])
   gnutls_deinit (client);
   gnutls_deinit (server);
 
-  free (to_server);
-  free (to_client);
-
   gnutls_certificate_free_credentials (serverx509cred);
+  gnutls_certificate_free_credentials (clientx509cred);
 
   gnutls_global_deinit ();
 
-  if (debug_level > 0)
+  if (debug)
     {
-      if (exit_code == 0)
-        puts ("Self-test successful");
-      else
-        puts ("Self-test failed");
+      puts ("Self-test successful");
     }
 
-  return exit_code;
+  return;
 }


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]