1 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_CRYPTO_CRYPTO__
2 #define __KINESIS_VIDEO_WEBRTC_CLIENT_CRYPTO_CRYPTO__
10 #ifdef KVS_USE_OPENSSL
11 #define KVS_RSA_F4 RSA_F4
12 #define KVS_MD5_DIGEST_LENGTH MD5_DIGEST_LENGTH
13 #define KVS_SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
14 #define KVS_MD5_DIGEST(m, mlen, ob) MD5((m), (mlen), (ob));
15 #define KVS_SHA1_HMAC(k, klen, m, mlen, ob, plen) \
16 CHK(NULL != HMAC(EVP_sha1(), (k), (INT32) (klen), (m), (mlen), (ob), (plen)), STATUS_HMAC_GENERATION_ERROR);
17 #define KVS_CRYPTO_INIT() \
19 OpenSSL_add_ssl_algorithms(); \
20 SSL_load_error_strings(); \
23 #define LOG_OPENSSL_ERROR(s) \
24 while ((sslErr = ERR_get_error()) != 0) { \
25 if (sslErr != SSL_ERROR_WANT_WRITE && sslErr != SSL_ERROR_WANT_READ) { \
26 DLOGW("%s failed with %s", (s), ERR_error_string(sslErr, NULL)); \
31 KVS_SRTP_PROFILE_AES128_CM_HMAC_SHA1_80 = SRTP_AES128_CM_SHA1_80,
32 KVS_SRTP_PROFILE_AES128_CM_HMAC_SHA1_32 = SRTP_AES128_CM_SHA1_32,
35 #define KVS_RSA_F4 0x10001L
36 #define KVS_MD5_DIGEST_LENGTH 16
37 #define KVS_SHA1_DIGEST_LENGTH 20
38 #define KVS_MD5_DIGEST(m, mlen, ob) mbedtls_md5_ret((m), (mlen), (ob));
39 #define KVS_SHA1_HMAC(k, klen, m, mlen, ob, plen) \
40 CHK(0 == mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), (k), (klen), (m), (mlen), (ob)), STATUS_HMAC_GENERATION_ERROR); \
41 *(plen) = mbedtls_md_get_size(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1));
42 #define KVS_CRYPTO_INIT() \
45 #define LOG_MBEDTLS_ERROR(s, ret) \
47 CHAR __mbedtlsErr[1024]; \
48 if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { \
49 mbedtls_strerror(ret, __mbedtlsErr, SIZEOF(__mbedtlsErr)); \
50 DLOGW("%s failed with %s", (s), __mbedtlsErr); \
55 KVS_SRTP_PROFILE_AES128_CM_HMAC_SHA1_80 = MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80,
56 KVS_SRTP_PROFILE_AES128_CM_HMAC_SHA1_32 = MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32,
59 #error "A Crypto implementation is required."