[vlc-commits] SRTP: remove dedicated gcrypt initialization, use VLC one
Rémi Denis-Courmont
git at videolan.org
Tue Jul 19 18:11:54 CEST 2011
vlc/vlc-1.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 19 18:01:52 2011 +0300| [f3d6e5a1ecdc990a5e69c5ee8c75ad44c5a335a7] | committer: Rémi Denis-Courmont
SRTP: remove dedicated gcrypt initialization, use VLC one
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
(cherry picked from commit f1a8ab79baee2aa7fbce87f4479b6f0557d9e2a5)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=f3d6e5a1ecdc990a5e69c5ee8c75ad44c5a335a7
---
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 e1cd6b1..03f882f 100755
--- a/modules/access/rtp/rtp.c
+++ b/modules/access/rtp/rtp.c
@@ -39,6 +39,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)")
@@ -276,6 +278,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 e6a247a..954a3c1 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"
@@ -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");
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