mirror of https://github.com/sipwise/rtpengine.git
parent
a923a52a60
commit
e63edeb875
@ -0,0 +1,78 @@
|
||||
#include "crypto.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "str.h"
|
||||
|
||||
|
||||
|
||||
/* all lengths are in bits, some code assumes everything to be multiples of 8 */
|
||||
const struct crypto_suite_params crypto_suite_params[__CS_LAST] = {
|
||||
[CS_AES_CM_128_HMAC_SHA1_80] = {
|
||||
.name = "AES_CM_128_HMAC_SHA1_80",
|
||||
.master_key_len = 128,
|
||||
.master_salt_len = 112,
|
||||
.srtp_lifetime = 1ULL << 48,
|
||||
.srtcp_lifetime = 1ULL << 31,
|
||||
.cipher = CIPHER_AES_CM,
|
||||
.encryption_key = 128,
|
||||
.mac = MAC_HMAC_SHA1,
|
||||
.srtp_auth_tag = 80,
|
||||
.srtcp_auth_tag = 80,
|
||||
.srtp_auth_key_len = 160,
|
||||
.srtcp_auth_key_len = 160,
|
||||
},
|
||||
[CS_AES_CM_128_HMAC_SHA1_32] = {
|
||||
.name = "AES_CM_128_HMAC_SHA1_32",
|
||||
.master_key_len = 128,
|
||||
.master_salt_len = 112,
|
||||
.srtp_lifetime = 1ULL << 48,
|
||||
.srtcp_lifetime = 1ULL << 31,
|
||||
.cipher = CIPHER_AES_CM,
|
||||
.encryption_key = 128,
|
||||
.mac = MAC_HMAC_SHA1,
|
||||
.srtp_auth_tag = 32,
|
||||
.srtcp_auth_tag = 80,
|
||||
.srtp_auth_key_len = 160,
|
||||
.srtcp_auth_key_len = 160,
|
||||
},
|
||||
[CS_F8_128_HMAC_SHA1_80] = {
|
||||
.name = "F8_128_HMAC_SHA1_80",
|
||||
.master_key_len = 128,
|
||||
.master_salt_len = 112,
|
||||
.srtp_lifetime = 1ULL << 48,
|
||||
.srtcp_lifetime = 1ULL << 31,
|
||||
.cipher = CIPHER_AES_F8,
|
||||
.encryption_key = 128,
|
||||
.mac = MAC_HMAC_SHA1,
|
||||
.srtp_auth_tag = 80,
|
||||
.srtcp_auth_tag = 80,
|
||||
.srtp_auth_key_len = 160,
|
||||
.srtcp_auth_key_len = 160,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
enum crypto_suite crypto_find_suite(const str *s) {
|
||||
int i, l;
|
||||
const struct crypto_suite_params *cs;
|
||||
|
||||
for (i = CS_UNKNOWN + 1; i < __CS_LAST; i++) {
|
||||
cs = &crypto_suite_params[i];
|
||||
if (!cs->name)
|
||||
continue;
|
||||
|
||||
l = strlen(cs->name);
|
||||
if (l != s->len)
|
||||
continue;
|
||||
|
||||
if (strncasecmp(cs->name, s->s, s->len))
|
||||
continue;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
return CS_UNKNOWN;
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
#ifndef _CRYPTO_H_
|
||||
#define _CRYPTO_H_
|
||||
|
||||
|
||||
|
||||
#include "str.h"
|
||||
|
||||
|
||||
|
||||
/* XXX get rid of the enums and replace with struct pointers? */
|
||||
enum crypto_suite {
|
||||
CS_UNKNOWN = 0,
|
||||
CS_AES_CM_128_HMAC_SHA1_80,
|
||||
CS_AES_CM_128_HMAC_SHA1_32,
|
||||
CS_F8_128_HMAC_SHA1_80,
|
||||
|
||||
__CS_LAST
|
||||
};
|
||||
|
||||
enum cipher {
|
||||
CIPHER_UNKNOWN = 0,
|
||||
CIPHER_AES_CM,
|
||||
CIPHER_AES_F8,
|
||||
|
||||
__CIPHER_LAST
|
||||
};
|
||||
|
||||
enum mac {
|
||||
MAC_UNKNOWN = 0,
|
||||
MAC_HMAC_SHA1,
|
||||
|
||||
__MAC_LAST
|
||||
};
|
||||
|
||||
struct crypto_suite_params {
|
||||
const char *name;
|
||||
unsigned int
|
||||
master_key_len,
|
||||
master_salt_len,
|
||||
encryption_key,
|
||||
srtp_auth_tag,
|
||||
srtcp_auth_tag,
|
||||
srtp_auth_key_len,
|
||||
srtcp_auth_key_len;
|
||||
unsigned long long int
|
||||
srtp_lifetime,
|
||||
srtcp_lifetime;
|
||||
enum cipher cipher;
|
||||
enum mac mac;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
extern const struct crypto_suite_params crypto_suite_params[__CS_LAST];
|
||||
|
||||
|
||||
|
||||
enum crypto_suite crypto_find_suite(const str *);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue