]> git.sesse.net Git - vlc/commitdiff
SRTP: remove dedicated gcrypt initialization, use VLC one
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 19 Jul 2011 15:01:52 +0000 (18:01 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 19 Jul 2011 15:15:34 +0000 (18:15 +0300)
Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
libs/srtp/Makefile.am
libs/srtp/srtp.c
libs/srtp/test-aes.c
modules/access/rtp/rtp.c
modules/stream_out/rtp.c

index 8b7522be9f00d829a59e531aaa6b5a3aa7a5dbcd..b90bed1a4271de1b0f94b7f8ca1f19d503c41b92 100644 (file)
@@ -32,11 +32,6 @@ srtp_LDADD = libvlc_srtp.la
 test_recv_LDADD = libvlc_srtp.la
 test_aes_LDADD = @GCRYPT_LIBS@
 
-if !HAVE_WIN32
-libvlc_srtp_la_LIBADD += -lpthread
-test_aes_LDADD += -lpthread
-endif
-
 lcov-run:
        rm -Rf *.gcda lcov
        $(MAKE) $(AM_MAKEFLAGS) check
index 26f13290903a0422b16120f8dc1d3f13a715264e..766834c4d5d89f6e4c9092c407342a442436b0b9 100644 (file)
@@ -43,8 +43,6 @@
 # include <winsock2.h>
 #else
 # include <netinet/in.h>
-# include <pthread.h>
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
 #endif
 
 #define debug( ... ) (void)0
@@ -86,41 +84,6 @@ static inline unsigned rcc_mode (const srtp_session_t *s)
     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)
 {
@@ -170,7 +133,7 @@ static int proto_create (srtp_proto_t *p, int gcipher, int gmd)
 srtp_session_t *
 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;
 
     int cipher, md;
index 463f0b1a48084aea11beaa192b9905652ee8d83f..ae55f34b109c135b2e74e14ea96d2cd6148ab208 100644 (file)
@@ -143,8 +143,6 @@ static void test_keystream (void)
 
 static void srtp_test (void)
 {
-    if (init_libgcrypt ())
-        fatal ("Libgcrypt initialization error");
     test_derivation ();
     test_keystream ();
 }
index c0ccad4266bda5087bd0a726e28f2aa4db24f3a7..050a6e726b575c427cfe6a20317041d04696732f 100644 (file)
@@ -37,6 +37,8 @@
 #include "rtp.h"
 #ifdef HAVE_SRTP
 # include <srtp.h>
+# include <gcrypt.h>
+# include <vlc_gcrypt.h>
 #endif
 
 #define RTP_CACHING_TEXT N_("RTP de-jitter buffer length (msec)")
@@ -285,6 +287,7 @@ static int Open (vlc_object_t *obj)
     char *key = var_CreateGetNonEmptyString (demux, "srtp-key");
     if (key)
     {
+        vlc_gcrypt_init ();
         p_sys->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10,
                                    SRTP_PRF_AES_CM, SRTP_RCC_MODE1);
         if (p_sys->srtp == NULL)
index 3e41159f843df0f7b752876c66adf97d90de0ea9..b12b34e5afa214291bc0bdd1b283bbb670ff346b 100644 (file)
@@ -42,6 +42,8 @@
 #include <vlc_rand.h>
 #ifdef HAVE_SRTP
 # include <srtp.h>
+# include <gcrypt.h>
+# include <vlc_gcrypt.h>
 #endif
 
 #include "rtp.h"
@@ -995,6 +997,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     char *key = var_GetNonEmptyString (p_stream, SOUT_CFG_PREFIX"key");
     if (key)
     {
+        vlc_gcrypt_init ();
         id->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10,
                                    SRTP_PRF_AES_CM, SRTP_RCC_MODE1);
         if (id->srtp == NULL)