mirror of https://github.com/sipwise/rtpengine.git
parent
292a676d96
commit
7877b7ce14
@ -0,0 +1,62 @@
|
||||
#include "rtp.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "str.h"
|
||||
#include "crypto.h"
|
||||
|
||||
|
||||
|
||||
|
||||
struct rtp_header {
|
||||
unsigned char v_p_x_cc;
|
||||
unsigned char m_pt;
|
||||
u_int16_t seq_num;
|
||||
u_int32_t timestamp;
|
||||
u_int32_t ssrc;
|
||||
u_int32_t csrc[];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static inline int check_session_key(struct crypto_context *c) {
|
||||
str s;
|
||||
|
||||
if (c->have_session_key)
|
||||
return 0;
|
||||
|
||||
str_init_len(&s, c->session_key, c->crypto_suite->session_key_len);
|
||||
if (crypto_gen_session_key(c, &s, 0x00))
|
||||
return -1;
|
||||
str_init_len(&s, c->session_auth_key, c->crypto_suite->srtp_auth_key_len);
|
||||
if (crypto_gen_session_key(c, &s, 0x01))
|
||||
return -1;
|
||||
str_init_len(&s, c->session_salt, c->crypto_suite->session_salt_len);
|
||||
if (crypto_gen_session_key(c, &s, 0x02))
|
||||
return -1;
|
||||
|
||||
c->have_session_key = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* XXX some error handling/logging here */
|
||||
int rtp_avp2savp(str *s, struct crypto_context *c) {
|
||||
struct rtp_header *rtp;
|
||||
|
||||
if (s->len < sizeof(*rtp))
|
||||
return -1;
|
||||
|
||||
rtp = (void *) s->s;
|
||||
|
||||
if (check_session_key(c))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtp_savp2avp(str *s, struct crypto_context *c) {
|
||||
if (check_session_key(c))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#ifndef _RTP_H_
|
||||
#define _RTP_H_
|
||||
|
||||
|
||||
|
||||
#include "str.h"
|
||||
|
||||
|
||||
|
||||
struct crypto_context;
|
||||
|
||||
int rtp_avp2savp(str *, struct crypto_context *);
|
||||
int rtp_savp2avp(str *, struct crypto_context *);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue