diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index c763be33095694fb4c7b83ec7580bab3369560b6..b3c7942faea1458115a65cee3c4a9b9702d96a73 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -186,6 +186,24 @@ set(GIT_BRANCH        "UNKNOWN")
 set(GIT_COMMIT_HASH   "UNKNOWN")
 set(GIT_COMMIT_DATE   "UNKNOWN")
 
+#This is to detect nettle version changes between Ubuntu 14.04/16.04
+set ( nettle_cmd "nettle-hash" )
+set ( nettle_arg "-V" )
+execute_process(COMMAND  ${nettle_cmd} ${nettle_arg}   RESULT_VARIABLE rv OUTPUT_VARIABLE ov ERROR_VARIABLE ev)
+
+string(REGEX MATCH "[+-]?[0-9]+([.][0-9]+)?" nv ${ov})
+
+message("NETTLE_VERSION = ${nv}")
+
+# we need to remove decimal as floating point arithematic does not work properly with C preprocessor
+STRING(REGEX REPLACE "[.]" "" nv ${nv})
+
+if ("${nv}" STREQUAL "")
+  message( FATAL_ERROR "The nettle version not detected properly. Try to run build_oai -I again" )
+endif()
+
+set (NETTLE_VERSION "${nv}")
+add_definitions("-DNETTLE_VERSION=${NETTLE_VERSION}")
 
 find_package(Git)
 if(GIT_FOUND)
diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper
index 8d6de5d61c021227ae4f932e93aa2ceafebae51b..99504b3dc897d9ded55754b77cefb8d87c392554 100755
--- a/cmake_targets/tools/build_helper
+++ b/cmake_targets/tools/build_helper
@@ -334,17 +334,72 @@ check_install_oai_software() {
 	wget
 
     $SUDO update-alternatives --set liblapack.so /usr/lib/atlas-base/atlas/liblapack.so
-    $SUDO apt-get install -y libgnutls-dev nettle-dev nettle-bin
+    
+    #Remove old gnutls/nettle installation that was done from sources
+    remove_nettle_from_source
+    
+    $SUDO apt-get install -y nettle-dev nettle-bin
+    remove_gnutls_from_source
+
+    $SUDO apt-get install -y libgnutls-dev
     
     install_asn1c_from_source
 }
 
+### Remove Nettle installation which was done from sources
+remove_nettle_from_source() {
+    nettle_uninstall_log=$OPENAIR_DIR/cmake_targets/log/nettle_uninstall_log.txt
+    echo_info "\nUn-Installing Nettle from sources. The log file for nettle un-installation is here: $nettle_uninstall_log "
+    (
+    $SUDO apt-get remove -y nettle-dev nettle-bin 
+    cd /tmp
+    echo "Downloading nettle archive"
+    $SUDO rm -rf /tmp/nettle-2.5.tar.gz* /tmp/nettle-2.5
+    wget https://ftp.gnu.org/gnu/nettle/nettle-2.5.tar.gz
+    if [ $? -ne 0 ]; then
+      wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
+    fi
+    if [ ! -f nettle-2.5.tar.gz ]; then
+      echo_error "Could not download nettle source files"
+      cd -
+      return
+    fi
+    tar -xzf nettle-2.5.tar.gz
+    cd nettle-2.5/
+    ./configure --disable-openssl --enable-shared --prefix=/usr 
+    $SUDO make uninstall || true 
+    ) >& $nettle_uninstall_log
+}
+
+### Remove Gnutls from source
+remove_gnutls_from_source(){
+    gnutls_uninstall_log=$OPENAIR_DIR/cmake_targets/log/gnutls_uninstall_log.txt
+    echo_info "\nUn-Installing Gnutls. The log file for Gnutls un-installation is here: $gnutls_uninstall_log "
+    (
+    $SUDO apt-get remove -y libgnutls-dev
+    cd /tmp 
+    echo "Downloading gnutls archive"
+    $SUDO rm -rf /tmp/gnutls-3.1.23.tar.xz* /tmp/gnutls-3.1.23
+    wget http://mirrors.dotsrc.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz || \
+      wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz
+    if [ ! -f gnutls-3.1.23.tar.xz ]; then
+      echo_error "Could not download gnutls source files"
+      cd -
+      return
+    fi
+    tar -xJf gnutls-3.1.23.tar.xz
+    cd gnutls-3.1.23/
+    ./configure --prefix=/usr
+    $SUDO make uninstall || true
+    )>& $gnutls_uninstall_log
+}
+
 install_asn1c_from_source(){
     asn1_install_log=$OPENAIR_DIR/cmake_targets/log/asn1c_install_log.txt
     echo_info "\nInstalling ASN1. The log file for ASN1 installation is here: $asn1_install_log "
     (
     $SUDO rm -rf /tmp/asn1c
-    $SUDO GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/oai/asn1c.git /tmp/asn1c
+    GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/oai/asn1c.git /tmp/asn1c
     cd /tmp/asn1c
     ./configure
     make -j`nproc`
diff --git a/openair2/UTIL/OSA/osa_stream_eea.c b/openair2/UTIL/OSA/osa_stream_eea.c
index acd341232e125600ac53a36a2c0204a56e56620f..08e0d44441379849fbcf2c6f72a45d429ce9be64 100644
--- a/openair2/UTIL/OSA/osa_stream_eea.c
+++ b/openair2/UTIL/OSA/osa_stream_eea.c
@@ -199,8 +199,13 @@ int stream_encrypt_eea2(stream_cipher_t *stream_cipher, uint8_t **out)
   }
 #endif
 
+#if NETTLE_VERSION <= 27
+  nettle_aes128.set_encrypt_key(ctx, stream_cipher->key_length,
+                                stream_cipher->key);
+#else
   nettle_aes128.set_encrypt_key(ctx, 
                                 stream_cipher->key);
+#endif
 
   nettle_ctr_crypt(ctx, nettle_aes128.encrypt,
                    nettle_aes128.block_size, m,
diff --git a/openair3/SECU/nas_stream_eea2.c b/openair3/SECU/nas_stream_eea2.c
index 799aaaf432ddff26bf7dd1bdfaa6dd9f72677cef..df3a1ed82c1ea424a1487cc7e2c08e63e6eb86aa 100644
--- a/openair3/SECU/nas_stream_eea2.c
+++ b/openair3/SECU/nas_stream_eea2.c
@@ -85,8 +85,13 @@ int nas_stream_encrypt_eea2(nas_stream_cipher_t *stream_cipher, uint8_t *out)
   }
 #endif
 
+#if NETTLE_VERSION <= 27
+  nettle_aes128.set_encrypt_key(ctx, stream_cipher->key_length,
+                                stream_cipher->key);
+#else
   nettle_aes128.set_encrypt_key(ctx,
                                 stream_cipher->key);
+#endif
 
   nettle_ctr_crypt(ctx, nettle_aes128.encrypt,
                    nettle_aes128.block_size, m,