[vlc-commits] SRTP: remove dedicated gcrypt initialization, use VLC one

Rémi Denis-Courmont git at videolan.org
Tue Jul 19 17:17:54 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 19 18:01:52 2011 +0300| [f1a8ab79baee2aa7fbce87f4479b6f0557d9e2a5] | committer: Rémi Denis-Courmont

SRTP: remove dedicated gcrypt initialization, use VLC one

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f1a8ab79baee2aa7fbce87f4479b6f0557d9e2a5
---

 libs/srtp/Makefile.am    |    5 -----
 libs/srtp/srtp.c         |   39 +--------------------------------------
 libs/srtp/test-aes.c     |    2 --
 modules/access/rtp/rtp.c |    3 +++
 modules/stream_out/rtp.c |    3 +++
 5 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/libs/srtp/Makefile.am b/libs/srtp/Makefile.am
index 8b7522b..b90bed1 100644
--- a/libs/srtp/Makefile.am
+++ b/libs/srtp/Makefile.am
@@ -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
diff --git a/libs/srtp/srtp.c b/libs/srtp/srtp.c
index 26f1329..766834c 100644
--- a/libs/srtp/srtp.c
+++ b/libs/srtp/srtp.c
@@ -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;
diff --git a/libs/srtp/test-aes.c b/libs/srtp/test-aes.c
index 463f0b1..ae55f34 100644
--- a/libs/srtp/test-aes.c
+++ b/libs/srtp/test-aes.c
@@ -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 ();
 }
diff --git a/modules/access/rtp/rtp.c b/modules/access/rtp/rtp.c
index c0ccad4..050a6e7 100644
--- a/modules/access/rtp/rtp.c
+++ b/modules/access/rtp/rtp.c
@@ -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)
diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 3e41159..b12b34e 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -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)



More information about the vlc-commits mailing list