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;
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;
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)
|| gcry_cipher_setkey (prf, key, keylen))
return -1;
+#if 0
/* RTP key derivation */
if (s->kdr != 0)
{
}
}
else
+#endif
memset (r, 0, sizeof (r));
if (proto_derive (&s->rtp, prf, salt, saltlen, r, 6, false))
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)