Commit f3d6e5a1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

SRTP: remove dedicated gcrypt initialization, use VLC one

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
(cherry picked from commit f1a8ab79baee2aa7fbce87f4479b6f0557d9e2a5)
parent d1fbab4d
...@@ -32,11 +32,6 @@ srtp_LDADD = libvlc_srtp.la ...@@ -32,11 +32,6 @@ srtp_LDADD = libvlc_srtp.la
test_recv_LDADD = libvlc_srtp.la test_recv_LDADD = libvlc_srtp.la
test_aes_LDADD = @GCRYPT_LIBS@ test_aes_LDADD = @GCRYPT_LIBS@
if !HAVE_WIN32
libvlc_srtp_la_LIBADD += -lpthread
test_aes_LDADD += -lpthread
endif
lcov-run: lcov-run:
rm -Rf *.gcda lcov rm -Rf *.gcda lcov
$(MAKE) $(AM_MAKEFLAGS) check $(MAKE) $(AM_MAKEFLAGS) check
......
...@@ -43,8 +43,6 @@ ...@@ -43,8 +43,6 @@
# include <winsock2.h> # include <winsock2.h>
#else #else
# include <netinet/in.h> # include <netinet/in.h>
# include <pthread.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif #endif
#define debug( ... ) (void)0 #define debug( ... ) (void)0
...@@ -86,41 +84,6 @@ static inline unsigned rcc_mode (const srtp_session_t *s) ...@@ -86,41 +84,6 @@ static inline unsigned rcc_mode (const srtp_session_t *s)
return (s->flags >> 4) & 3; return (s->flags >> 4) & 3;
} }
static bool libgcrypt_usable = false;
static void initonce_libgcrypt (void)
{
#ifndef WIN32
gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
#endif
if ((gcry_check_version ("1.1.94") == NULL)
|| gcry_control (GCRYCTL_DISABLE_SECMEM, 0)
|| gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0))
return;
libgcrypt_usable = true;
}
static int init_libgcrypt (void)
{
int retval;
#ifndef WIN32
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once (&once, initonce_libgcrypt);
#else
# warning FIXME: This is not thread-safe.
if (!libgcrypt_usable)
initonce_libgcrypt ();
#endif
retval = libgcrypt_usable ? 0 : -1;
return retval;
}
static void proto_destroy (srtp_proto_t *p) static void proto_destroy (srtp_proto_t *p)
{ {
...@@ -170,7 +133,7 @@ static int proto_create (srtp_proto_t *p, int gcipher, int gmd) ...@@ -170,7 +133,7 @@ static int proto_create (srtp_proto_t *p, int gcipher, int gmd)
srtp_session_t * srtp_session_t *
srtp_create (int encr, int auth, unsigned tag_len, int prf, unsigned flags) srtp_create (int encr, int auth, unsigned tag_len, int prf, unsigned flags)
{ {
if ((flags & ~SRTP_FLAGS_MASK) || init_libgcrypt ()) if ((flags & ~SRTP_FLAGS_MASK))
return NULL; return NULL;
int cipher, md; int cipher, md;
......
...@@ -143,8 +143,6 @@ static void test_keystream (void) ...@@ -143,8 +143,6 @@ static void test_keystream (void)
static void srtp_test (void) static void srtp_test (void)
{ {
if (init_libgcrypt ())
fatal ("Libgcrypt initialization error");
test_derivation (); test_derivation ();
test_keystream (); test_keystream ();
} }
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "rtp.h" #include "rtp.h"
#ifdef HAVE_SRTP #ifdef HAVE_SRTP
# include <srtp.h> # include <srtp.h>
# include <gcrypt.h>
# include <vlc_gcrypt.h>
#endif #endif
#define RTP_CACHING_TEXT N_("RTP de-jitter buffer length (msec)") #define RTP_CACHING_TEXT N_("RTP de-jitter buffer length (msec)")
...@@ -276,6 +278,7 @@ static int Open (vlc_object_t *obj) ...@@ -276,6 +278,7 @@ static int Open (vlc_object_t *obj)
char *key = var_CreateGetNonEmptyString (demux, "srtp-key"); char *key = var_CreateGetNonEmptyString (demux, "srtp-key");
if (key) if (key)
{ {
vlc_gcrypt_init ();
p_sys->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10, p_sys->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10,
SRTP_PRF_AES_CM, SRTP_RCC_MODE1); SRTP_PRF_AES_CM, SRTP_RCC_MODE1);
if (p_sys->srtp == NULL) if (p_sys->srtp == NULL)
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include <vlc_rand.h> #include <vlc_rand.h>
#ifdef HAVE_SRTP #ifdef HAVE_SRTP
# include <srtp.h> # include <srtp.h>
# include <gcrypt.h>
# include <vlc_gcrypt.h>
#endif #endif
#include "rtp.h" #include "rtp.h"
...@@ -1006,6 +1008,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1006,6 +1008,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
char *key = var_CreateGetNonEmptyString (p_stream, SOUT_CFG_PREFIX"key"); char *key = var_CreateGetNonEmptyString (p_stream, SOUT_CFG_PREFIX"key");
if (key) if (key)
{ {
vlc_gcrypt_init ();
id->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10, id->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10,
SRTP_PRF_AES_CM, SRTP_RCC_MODE1); SRTP_PRF_AES_CM, SRTP_RCC_MODE1);
if (id->srtp == NULL) if (id->srtp == NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment