|
Packit Service |
31306d |
/*
|
|
Packit Service |
31306d |
* This file is part of the SSH Library
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* Copyright (c) 2018 by Anderson Toshiyuki Sasaki
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* The SSH Library is free software; you can redistribute it and/or modify
|
|
Packit Service |
31306d |
* it under the terms of the GNU Lesser General Public License as published by
|
|
Packit Service |
31306d |
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
|
Packit Service |
31306d |
* option) any later version.
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* The SSH Library is distributed in the hope that it will be useful, but
|
|
Packit Service |
31306d |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit Service |
31306d |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
Packit Service |
31306d |
* License for more details.
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
31306d |
* along with the SSH Library; see the file COPYING. If not, write to
|
|
Packit Service |
31306d |
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
Packit Service |
31306d |
* MA 02111-1307, USA.
|
|
Packit Service |
31306d |
*/
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#include "config.h"
|
|
Packit Service |
31306d |
#include "libssh/crypto.h"
|
|
Packit Service |
31306d |
#include "libssh/threads.h"
|
|
Packit Service |
31306d |
#include <libssh/callbacks.h>
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#if (GCRYPT_VERSION_NUMBER >= 0x010600)
|
|
Packit Service |
31306d |
/* libgcrypt >= 1.6 does not support custom callbacks */
|
|
Packit Service |
31306d |
GCRY_THREAD_OPTION_PTHREAD_IMPL;
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks)
|
|
Packit Service |
31306d |
{
|
|
Packit Service |
31306d |
(void) user_callbacks;
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
return SSH_OK;
|
|
Packit Service |
31306d |
}
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#else
|
|
Packit Service |
31306d |
/* Libgcrypt < 1.6 specific way of handling thread callbacks */
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
static struct gcry_thread_cbs gcrypt_threads_callbacks;
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks)
|
|
Packit Service |
31306d |
{
|
|
Packit Service |
31306d |
int cmp;
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
if (user_callbacks == NULL) {
|
|
Packit Service |
31306d |
return SSH_OK;
|
|
Packit Service |
31306d |
}
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
cmp = strcmp(user_callbacks->type, "threads_noop");
|
|
Packit Service |
31306d |
if (cmp == 0) {
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 ||
|
|
Packit Service |
31306d |
GCRY_THREAD_OPTION_DEFAULT;
|
|
Packit Service |
31306d |
} else {
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 ||
|
|
Packit Service |
31306d |
GCRY_THREAD_OPTION_USER;
|
|
Packit Service |
31306d |
}
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.mutex_init = user_callbacks->mutex_init;
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.mutex_destroy = user_callbacks->mutex_destroy;
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.mutex_lock = user_callbacks->mutex_lock;
|
|
Packit Service |
31306d |
gcrypt_threads_callbacks.mutex_unlock = user_callbacks->mutex_unlock;
|
|
Packit Service |
31306d |
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks);
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
return SSH_OK;
|
|
Packit Service |
31306d |
}
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#endif /* GCRYPT_VERSION_NUMBER */
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
void crypto_thread_finalize(void)
|
|
Packit Service |
31306d |
{
|
|
Packit Service |
31306d |
return;
|
|
Packit Service |
31306d |
}
|