Skip to content
Snippets Groups Projects
Commit ae155930 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #3696: Detect and initialise libgcrypt, because libssh2 can be linked against it

parent 6507e0de
No related branches found
No related tags found
No related merge requests found
# - Try to find GCrypt: a crypto library
# This will define:
# GCRYPT_FOUND - system has GCrypt
# GCRYPT_INCLUDE_DIR - the GCrypt include directory (cached)
# GCRYPT_INCLUDE_DIRS - the GCrypt include directories
# (identical to GCRYPT_INCLUDE_DIR)
# GCRYPT_LIBRARY - the GCrypt library (cached)
# GCRYPT_LIBRARIES - the GCrypt libraries
# (identical to GCRYPT_LIBRARY)
# Copyright (C) 2009
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite 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 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
#
# $Id$
if(NOT GCRYPT_FOUND)
find_path(GCRYPT_INCLUDE_DIR gcrypt.h
HINTS ${GCRYPT_ROOT_DIR} PATH_SUFFIXES include)
find_library(GCRYPT_LIBRARY gcrypt
HINTS ${GCRYPT_ROOT_DIR} PATH_SUFFIXES lib)
mark_as_advanced(GCRYPT_INCLUDE_DIR GCRYPT_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GCrypt DEFAULT_MSG
GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR)
set(GCRYPT_INCLUDE_DIRS ${GCRYPT_INCLUDE_DIR})
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
endif(NOT GCRYPT_FOUND)
......@@ -49,7 +49,8 @@ lofar_package(GPUProc 1.0 DEPENDS ${_gpuproc_deps})
lofar_find_package(OpenMP REQUIRED)
lofar_find_package(LibSSH2 REQUIRED)
lofar_find_package(OpenSSL REQUIRED)
lofar_find_package(OpenSSL)
lofar_find_package(GCrypt)
lofar_find_package(Boost REQUIRED)
lofar_find_package(MPI)
lofar_find_package(FFTW3 COMPONENTS single double threads REQUIRED) # 'double threads' for FFT unit test refs
......
......@@ -29,7 +29,16 @@
#include <unistd.h>
#include <vector>
#include <sys/select.h>
#ifdef HAVE_OPENSSL
#include <openssl/crypto.h>
#endif
#ifdef HAVE_GCRYPT
#include <pthread.h>
#include <gcrypt.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
#include <Common/LofarLogger.h>
#include <Common/SystemCallException.h>
......@@ -701,6 +710,7 @@ namespace LOFAR
#ifdef HAVE_OPENSSL
std::vector< SmartPtr<Mutex> > openssl_mutexes;
static void lock_callback(int mode, int type, const char *file, int line)
......@@ -718,10 +728,11 @@ namespace LOFAR
{
return static_cast<unsigned long>(pthread_self());
}
#endif
bool SSH_Init()
{
#ifdef HAVE_OPENSSL
// initialise openssl
openssl_mutexes.resize(CRYPTO_num_locks());
for (size_t i = 0; i < openssl_mutexes.size(); ++i)
......@@ -729,6 +740,12 @@ namespace LOFAR
CRYPTO_set_id_callback(&thread_id_callback);
CRYPTO_set_locking_callback(&lock_callback);
#endif
#ifdef HAVE_GCRYPT
// initialise gcrypt
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
#endif
#if LIBSSH2_VERSION_NUM >= 0x010205
// initialise libssh2
......@@ -748,11 +765,13 @@ namespace LOFAR
libssh2_exit();
#endif
#ifdef HAVE_OPENSSL
// exit openssl
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_id_callback(NULL);
openssl_mutexes.clear();
#endif
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment