Browse Source

remove a pointless enum

git.mgm/mediaproxy-ng/github/master
Richard Fuchs 13 years ago
parent
commit
292a676d96
3 changed files with 25 additions and 30 deletions
  1. +13
    -10
      daemon/crypto.c
  2. +4
    -12
      daemon/crypto.h
  3. +8
    -8
      daemon/sdp.c

+ 13
- 10
daemon/crypto.c View File

@ -3,12 +3,13 @@
#include <string.h>
#include "str.h"
#include "aux.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] = {
const struct crypto_suite crypto_suites[] = {
{
.name = "AES_CM_128_HMAC_SHA1_80",
.master_key_len = 128,
.master_salt_len = 112,
@ -22,7 +23,7 @@ const struct crypto_suite_params crypto_suite_params[__CS_LAST] = {
.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,
@ -36,7 +37,7 @@ const struct crypto_suite_params crypto_suite_params[__CS_LAST] = {
.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,
@ -52,15 +53,17 @@ const struct crypto_suite_params crypto_suite_params[__CS_LAST] = {
},
};
const int num_crypto_suites = ARRAYSIZE(crypto_suites);
enum crypto_suite crypto_find_suite(const str *s) {
const struct crypto_suite *crypto_find_suite(const str *s) {
int i, l;
const struct crypto_suite_params *cs;
const struct crypto_suite *cs;
for (i = CS_UNKNOWN + 1; i < __CS_LAST; i++) {
cs = &crypto_suite_params[i];
for (i = 0; i < num_crypto_suites; i++) {
cs = &crypto_suites[i];
if (!cs->name)
continue;
@ -71,8 +74,8 @@ enum crypto_suite crypto_find_suite(const str *s) {
if (strncasecmp(cs->name, s->s, s->len))
continue;
return i;
return cs;
}
return CS_UNKNOWN;
return NULL;
}

+ 4
- 12
daemon/crypto.h View File

@ -8,15 +8,6 @@
/* 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,
@ -32,7 +23,7 @@ enum mac {
__MAC_LAST
};
struct crypto_suite_params {
struct crypto_suite {
const char *name;
unsigned int
master_key_len,
@ -52,11 +43,12 @@ struct crypto_suite_params {
extern const struct crypto_suite_params crypto_suite_params[__CS_LAST];
extern const struct crypto_suite crypto_suites[];
extern const int num_crypto_suites;
enum crypto_suite crypto_find_suite(const str *);
const struct crypto_suite *crypto_find_suite(const str *);


+ 8
- 8
daemon/sdp.c View File

@ -93,7 +93,7 @@ struct attribute_crypto {
str mki_str;
unsigned int tag;
enum crypto_suite crypto_suite;
const struct crypto_suite *crypto_suite;
str master_key;
str salt;
char key_salt_buf[30];
@ -309,7 +309,6 @@ static int parse_attribute_ssrc(struct sdp_attribute *output) {
static int parse_attribute_crypto(struct sdp_attribute *output) {
char *start, *end;
struct attribute_crypto *c;
const struct crypto_suite_params *cs;
int salt_key_len, enc_salt_key_len;
int b64_state = 0;
unsigned int b64_save = 0;
@ -328,11 +327,11 @@ static int parse_attribute_crypto(struct sdp_attribute *output) {
c = &output->u.crypto;
c->crypto_suite = crypto_find_suite(&c->crypto_suite_str);
if (c->crypto_suite == CS_UNKNOWN)
if (!c->crypto_suite)
return -1;
cs = &crypto_suite_params[c->crypto_suite];
/* assume everything is a multiple of 8 */
salt_key_len = (cs->master_key_len + cs->master_salt_len) / 8;
salt_key_len = (c->crypto_suite->master_key_len
+ c->crypto_suite->master_salt_len) / 8;
assert(sizeof(c->key_salt_buf) >= salt_key_len);
enc_salt_key_len = ceil((double) salt_key_len * 4.0/3.0);
@ -348,9 +347,9 @@ static int parse_attribute_crypto(struct sdp_attribute *output) {
return -1;
c->master_key.s = c->key_salt_buf;
c->master_key.len = cs->master_key_len / 8;
c->master_key.len = c->crypto_suite->master_key_len / 8;
c->salt.s = c->master_key.s + c->master_key.len;
c->salt.len = cs->master_salt_len / 8;
c->salt.len = c->crypto_suite->master_salt_len / 8;
c->lifetime_str = c->key_params_str;
str_shift(&c->lifetime_str, 7 + enc_salt_key_len);
@ -383,7 +382,8 @@ static int parse_attribute_crypto(struct sdp_attribute *output) {
else
c->lifetime = strtoull(c->lifetime_str.s, NULL, 10);
if (!c->lifetime || c->lifetime > cs->srtp_lifetime || c->lifetime > cs->srtcp_lifetime)
if (!c->lifetime || c->lifetime > c->crypto_suite->srtp_lifetime
|| c->lifetime > c->crypto_suite->srtcp_lifetime)
return -1;
}


Loading…
Cancel
Save