]> git.sesse.net Git - vlc/blobdiff - libs/srtp/srtp.c
Fix hashing when using RFC4711
[vlc] / libs / srtp / srtp.c
index daf0e18d203db42b3e8f97f033bba23109063fa3..60c07b6f72bfa0b7e25eecef27fed0c5aa292ded 100644 (file)
@@ -90,13 +90,13 @@ static bool libgcrypt_usable = false;
 
 static void initonce_libgcrypt (void)
 {
-    if ((gcry_check_version ("1.1.94") == NULL)
-     || gcry_control (GCRYCTL_DISABLE_SECMEM, 0)
-     || gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0)
 #ifndef WIN32
-     || gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread)
+    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;
@@ -111,13 +111,16 @@ static int init_libgcrypt (void)
 
     pthread_mutex_lock (&mutex);
     pthread_once (&once, initonce_libgcrypt);
-    retval = -libgcrypt_usable;
-    pthread_mutex_unlock (&mutex);
 #else
 # warning FIXME: This is not thread-safe.
     if (!libgcrypt_usable)
         initonce_libgcrypt ();
-    retval = -libgcrypt_usable;
+#endif
+
+    retval = libgcrypt_usable ? 0 : -1;
+
+#ifndef WIN32
+    pthread_mutex_unlock (&mutex);
 #endif
 
     return retval;
@@ -205,7 +208,7 @@ srtp_create (int encr, int auth, unsigned tag_len, int prf, unsigned flags)
             return NULL;
     }
 
-    if (tag_len > gcry_md_get_algo_dlen (auth))
+    if (tag_len > gcry_md_get_algo_dlen (md))
         return NULL;
 
     if (prf != SRTP_PRF_AES_CM)
@@ -328,6 +331,7 @@ srtp_derive (srtp_session_t *s, const void *key, size_t keylen,
      || gcry_cipher_setkey (prf, key, keylen))
         return -1;
 
+#if 0
     /* RTP key derivation */
     if (s->kdr != 0)
     {
@@ -341,6 +345,7 @@ srtp_derive (srtp_session_t *s, const void *key, size_t keylen,
         }
     }
     else
+#endif
         memset (r, 0, sizeof (r));
 
     if (proto_derive (&s->rtp, prf, salt, saltlen, r, 6, false))
@@ -646,7 +651,16 @@ srtp_recv (srtp_session_t *s, uint8_t *buf, size_t *lenp)
             rcc = roc;
 
         const uint8_t *tag = rtp_digest (s, buf, len, rcc);
-        if (memcmp (buf + len + roc_len, tag, s->tag_len))
+#if 0
+        printf ("Computed: 0x");
+        for (unsigned i = 0; i < tag_len; i++)
+            printf ("%02x", tag[i]);
+        printf ("\nReceived: 0x");
+        for (unsigned i = 0; i < tag_len; i++)
+            printf ("%02x", buf[len + roc_len + i]);
+        puts ("");
+#endif
+        if (memcmp (buf + len + roc_len, tag, tag_len))
             return EACCES;
 
         if (roc_len)