Commit a9ac898d authored by jfigus's avatar jfigus

Begin header file refactoring. This is a work-in-progress.

parent b058a3b7
......@@ -229,9 +229,9 @@ install:
fi
$(INSTALL) -d $(DESTDIR)$(includedir)/srtp
$(INSTALL) -d $(DESTDIR)$(libdir)
cp $(srcdir)/include/*.h $(DESTDIR)$(includedir)/srtp
cp $(srcdir)/crypto/include/*.h $(DESTDIR)$(includedir)/srtp
if [ "$(srcdir)" != "." ]; then cp crypto/include/*.h $(DESTDIR)$(includedir)/srtp; fi
cp $(srcdir)/include/srtp.h $(DESTDIR)$(includedir)/srtp
cp $(srcdir)/include/ekt.h $(DESTDIR)$(includedir)/srtp
cp $(srcdir)/include/rtp.h $(DESTDIR)$(includedir)/srtp
if [ -f libsrtp.a ]; then cp libsrtp.a $(DESTDIR)$(libdir)/; fi
if [ -f libsrtp.so ]; then cp libsrtp.so $(DESTDIR)$(libdir)/; fi
if [ "$(pkgconfig_DATA)" != "" ]; then \
......
......@@ -46,9 +46,9 @@
#ifndef AUTH_H
#define AUTH_H
#include "srtp.h"
#include "datatypes.h"
#include "err.h" /* error codes */
#include "crypto.h" /* for auth_type_id_t */
#include "crypto_types.h" /* for values of auth_type_id_t */
typedef struct auth_type_t *auth_type_pointer;
......
......@@ -46,10 +46,10 @@
#ifndef CIPHER_H
#define CIPHER_H
#include "srtp.h"
#include "datatypes.h"
#include "rdbx.h" /* for xtd_seq_num_t */
#include "err.h" /* for error codes */
#include "crypto.h" /* for cipher_type_id_t */
#include "crypto_types.h" /* for values of cipher_type_id_t */
......
/*
* crypto.h
*
* API for libcrypto
*
* David A. McGrew
* Cisco Systems, Inc.
*/
#ifndef CRYPTO_H
#define CRYPTO_H
/**
* @brief A cipher_type_id_t is an identifier for a particular cipher
* type.
*
* A cipher_type_id_t is an integer that represents a particular
* cipher type, e.g. the Advanced Encryption Standard (AES). A
* NULL_CIPHER is avaliable; this cipher leaves the data unchanged,
* and can be selected to indicate that no encryption is to take
* place.
*
* @ingroup Ciphers
*/
typedef uint32_t cipher_type_id_t;
/**
* @brief An auth_type_id_t is an identifier for a particular authentication
* function.
*
* An auth_type_id_t is an integer that represents a particular
* authentication function type, e.g. HMAC-SHA1. A NULL_AUTH is
* avaliable; this authentication function performs no computation,
* and can be selected to indicate that no authentication is to take
* place.
*
* @ingroup Authentication
*/
typedef uint32_t auth_type_id_t;
#endif /* CRYPTO_H */
......@@ -55,7 +55,6 @@
#include "err.h"
#include "crypto_types.h"
#include "key.h"
#include "crypto.h"
/*
* crypto_kernel_state_t defines the possible states:
......
......@@ -48,6 +48,7 @@
#include <stdio.h>
#include <stdarg.h>
#include "srtp.h"
/**
* @defgroup Error Error Codes
......@@ -58,42 +59,6 @@
*/
/*
* @brief err_status_t defines error codes.
*
* The enumeration err_status_t defines error codes. Note that the
* value of err_status_ok is equal to zero, which can simplify error
* checking somewhat.
*
*/
typedef enum {
err_status_ok = 0, /**< nothing to report */
err_status_fail = 1, /**< unspecified failure */
err_status_bad_param = 2, /**< unsupported parameter */
err_status_alloc_fail = 3, /**< couldn't allocate memory */
err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
err_status_init_fail = 5, /**< couldn't initialize */
err_status_terminus = 6, /**< can't process as much data as requested */
err_status_auth_fail = 7, /**< authentication failure */
err_status_cipher_fail = 8, /**< cipher failure */
err_status_replay_fail = 9, /**< replay check failed (bad index) */
err_status_replay_old = 10, /**< replay check failed (index too old) */
err_status_algo_fail = 11, /**< algorithm failed test routine */
err_status_no_such_op = 12, /**< unsupported operation */
err_status_no_ctx = 13, /**< no appropriate context found */
err_status_cant_check = 14, /**< unable to perform desired validation */
err_status_key_expired = 15, /**< can't use key any more */
err_status_socket_err = 16, /**< error in use of socket */
err_status_signal_err = 17, /**< error in use POSIX signals */
err_status_nonce_bad = 18, /**< nonce check failed */
err_status_read_fail = 19, /**< couldn't read data */
err_status_write_fail = 20, /**< couldn't write data */
err_status_parse_err = 21, /**< error parsing data */
err_status_encode_err = 22, /**< error encoding data */
err_status_semaphore_err = 23,/**< error while using semaphores */
err_status_pfkey_err = 24 /**< error while using pfkey */
} err_status_t;
/**
* @}
*/
......
......@@ -60,7 +60,40 @@
# include <winsock2.h>
#endif
//#include "srtp_priv.h"
#include "srtp.h"
/*
* RTP_HEADER_LEN indicates the size of an RTP header
*/
#define RTP_HEADER_LEN 12
/*
* RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation
*/
#define RTP_MAX_BUF_LEN 16384
typedef srtp_hdr_t rtp_hdr_t;
typedef struct {
srtp_hdr_t header;
char body[RTP_MAX_BUF_LEN];
} rtp_msg_t;
typedef struct rtp_sender_ctx_t {
rtp_msg_t message;
int socket;
srtp_ctx_t *srtp_ctx;
struct sockaddr_in addr; /* reciever's address */
} rtp_sender_ctx_t;
typedef struct rtp_receiver_ctx_t {
rtp_msg_t message;
int socket;
srtp_ctx_t *srtp_ctx;
struct sockaddr_in addr; /* receiver's address */
} rtp_receiver_ctx_t;
typedef struct rtp_sender_ctx_t *rtp_sender_t;
......@@ -125,15 +158,5 @@ void
rtp_receiver_dealloc(rtp_receiver_t rtp_ctx);
/*
* RTP_HEADER_LEN indicates the size of an RTP header
*/
#define RTP_HEADER_LEN 12
/*
* RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation
*/
#define RTP_MAX_BUF_LEN 16384
#endif /* RTP_H */
......@@ -49,26 +49,5 @@
#include "srtp_priv.h"
#include "rtp.h"
typedef srtp_hdr_t rtp_hdr_t;
typedef struct {
srtp_hdr_t header;
char body[RTP_MAX_BUF_LEN];
} rtp_msg_t;
typedef struct rtp_sender_ctx_t {
rtp_msg_t message;
int socket;
srtp_ctx_t *srtp_ctx;
struct sockaddr_in addr; /* reciever's address */
} rtp_sender_ctx_t;
typedef struct rtp_receiver_ctx_t {
rtp_msg_t message;
int socket;
srtp_ctx_t *srtp_ctx;
struct sockaddr_in addr; /* receiver's address */
} rtp_receiver_ctx_t;
#endif /* RTP_PRIV_H */
......@@ -51,9 +51,6 @@ extern "C" {
#endif
#include <stdint.h>
#include "crypto.h"
#include "crypto_types.h"
#include "err.h"
/**
* @defgroup SRTP Secure RTP
......@@ -101,8 +98,181 @@ extern "C" {
#define AES_192_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 24
#define AES_256_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 32
/*
* an srtp_hdr_t represents the srtp header
*
* in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
*
* (note that this definition follows that of RFC 1889 Appendix A, but
* is not identical)
*/
#ifndef WORDS_BIGENDIAN
/*
* srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
* this structure should be declared "unsigned int" instead of
* "unsigned char", but doing so causes the MS compiler to not
* fully pack the bit fields.
*/
typedef struct {
unsigned char cc:4; /* CSRC count */
unsigned char x:1; /* header extension flag */
unsigned char p:1; /* padding flag */
unsigned char version:2; /* protocol version */
unsigned char pt:7; /* payload type */
unsigned char m:1; /* marker bit */
uint16_t seq; /* sequence number */
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
} srtp_hdr_t;
#else /* BIG_ENDIAN */
typedef struct {
unsigned char version:2; /* protocol version */
unsigned char p:1; /* padding flag */
unsigned char x:1; /* header extension flag */
unsigned char cc:4; /* CSRC count */
unsigned char m:1; /* marker bit */
unsigned char pt:7; /* payload type */
uint16_t seq; /* sequence number */
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
} srtp_hdr_t;
#endif
typedef struct {
uint16_t profile_specific; /* profile-specific info */
uint16_t length; /* number of 32-bit words in extension */
} srtp_hdr_xtnd_t;
/*
* srtcp_hdr_t represents a secure rtcp header
*
* in this implementation, an srtcp header is assumed to be 32-bit
* alinged
*/
#ifndef WORDS_BIGENDIAN
typedef struct {
unsigned char rc:5; /* reception report count */
unsigned char p:1; /* padding flag */
unsigned char version:2; /* protocol version */
unsigned char pt:8; /* payload type */
uint16_t len; /* length */
uint32_t ssrc; /* synchronization source */
} srtcp_hdr_t;
typedef struct {
unsigned int index:31; /* srtcp packet index in network order! */
unsigned int e:1; /* encrypted? 1=yes */
/* optional mikey/etc go here */
/* and then the variable-length auth tag */
} srtcp_trailer_t;
#else /* BIG_ENDIAN */
typedef struct {
unsigned char version:2; /* protocol version */
unsigned char p:1; /* padding flag */
unsigned char rc:5; /* reception report count */
unsigned char pt:8; /* payload type */
uint16_t len; /* length */
uint32_t ssrc; /* synchronization source */
} srtcp_hdr_t;
typedef struct {
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
unsigned int count:5; /* varies by packet type */
unsigned int pt:8; /* payload type */
uint16_t length; /* len of uint32s of packet less header */
} rtcp_common_t;
typedef struct {
unsigned int e:1; /* encrypted? 1=yes */
unsigned int index:31; /* srtcp packet index */
/* optional mikey/etc go here */
/* and then the variable-length auth tag */
} srtcp_trailer_t;
#endif
/**
* @brief A cipher_type_id_t is an identifier for a particular cipher
* type.
*
* A cipher_type_id_t is an integer that represents a particular
* cipher type, e.g. the Advanced Encryption Standard (AES). A
* NULL_CIPHER is avaliable; this cipher leaves the data unchanged,
* and can be selected to indicate that no encryption is to take
* place.
*
* @ingroup Ciphers
*/
typedef uint32_t cipher_type_id_t;
/**
* @brief An auth_type_id_t is an identifier for a particular authentication
* function.
*
* An auth_type_id_t is an integer that represents a particular
* authentication function type, e.g. HMAC-SHA1. A NULL_AUTH is
* avaliable; this authentication function performs no computation,
* and can be selected to indicate that no authentication is to take
* place.
*
* @ingroup Authentication
*/
typedef uint32_t auth_type_id_t;
/*
* @brief err_status_t defines error codes.
*
* The enumeration err_status_t defines error codes. Note that the
* value of err_status_ok is equal to zero, which can simplify error
* checking somewhat.
*
*/
typedef enum {
err_status_ok = 0, /**< nothing to report */
err_status_fail = 1, /**< unspecified failure */
err_status_bad_param = 2, /**< unsupported parameter */
err_status_alloc_fail = 3, /**< couldn't allocate memory */
err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
err_status_init_fail = 5, /**< couldn't initialize */
err_status_terminus = 6, /**< can't process as much data as requested */
err_status_auth_fail = 7, /**< authentication failure */
err_status_cipher_fail = 8, /**< cipher failure */
err_status_replay_fail = 9, /**< replay check failed (bad index) */
err_status_replay_old = 10, /**< replay check failed (index too old) */
err_status_algo_fail = 11, /**< algorithm failed test routine */
err_status_no_such_op = 12, /**< unsupported operation */
err_status_no_ctx = 13, /**< no appropriate context found */
err_status_cant_check = 14, /**< unable to perform desired validation */
err_status_key_expired = 15, /**< can't use key any more */
err_status_socket_err = 16, /**< error in use of socket */
err_status_signal_err = 17, /**< error in use POSIX signals */
err_status_nonce_bad = 18, /**< nonce check failed */
err_status_read_fail = 19, /**< couldn't read data */
err_status_write_fail = 20, /**< couldn't write data */
err_status_parse_err = 21, /**< error parsing data */
err_status_encode_err = 22, /**< error encoding data */
err_status_semaphore_err = 23,/**< error while using semaphores */
err_status_pfkey_err = 24 /**< error while using pfkey */
} err_status_t;
typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
typedef struct srtp_ctx_t_ srtp_ctx_t;
/*
* nota bene: since libSRTP doesn't support the use of the MKI, the
* SRTP_MAX_TRAILER_LEN value is just the maximum tag length
......@@ -261,7 +431,7 @@ typedef struct srtp_policy_t {
* streams, each of which originates with a different participant.
*/
typedef struct srtp_ctx_t *srtp_t;
typedef srtp_ctx_t *srtp_t;
/**
......@@ -276,7 +446,7 @@ typedef struct srtp_ctx_t *srtp_t;
* a set of streams.
*
*/
typedef struct srtp_stream_ctx_t *srtp_stream_t;
typedef srtp_stream_ctx_t *srtp_stream_t;
......
......@@ -50,7 +50,6 @@
#include "rdbx.h"
#include "rdb.h"
#include "integers.h"
#include "crypto.h"
#include "cipher.h"
#include "auth.h"
#include "aes.h"
......@@ -60,113 +59,6 @@
#define SRTP_VER_STRING PACKAGE_STRING
#define SRTP_VERSION PACKAGE_VERSION
/*
* an srtp_hdr_t represents the srtp header
*
* in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
*
* (note that this definition follows that of RFC 1889 Appendix A, but
* is not identical)
*/
#ifndef WORDS_BIGENDIAN
/*
* srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
* this structure should be declared "unsigned int" instead of
* "unsigned char", but doing so causes the MS compiler to not
* fully pack the bit fields.
*/
typedef struct {
unsigned char cc:4; /* CSRC count */
unsigned char x:1; /* header extension flag */
unsigned char p:1; /* padding flag */
unsigned char version:2; /* protocol version */
unsigned char pt:7; /* payload type */
unsigned char m:1; /* marker bit */
uint16_t seq; /* sequence number */
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
} srtp_hdr_t;
#else /* BIG_ENDIAN */
typedef struct {
unsigned char version:2; /* protocol version */
unsigned char p:1; /* padding flag */
unsigned char x:1; /* header extension flag */
unsigned char cc:4; /* CSRC count */
unsigned char m:1; /* marker bit */
unsigned char pt:7; /* payload type */
uint16_t seq; /* sequence number */
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
} srtp_hdr_t;
#endif
typedef struct {
uint16_t profile_specific; /* profile-specific info */
uint16_t length; /* number of 32-bit words in extension */
} srtp_hdr_xtnd_t;
/*
* srtcp_hdr_t represents a secure rtcp header
*
* in this implementation, an srtcp header is assumed to be 32-bit
* alinged
*/
#ifndef WORDS_BIGENDIAN
typedef struct {
unsigned char rc:5; /* reception report count */
unsigned char p:1; /* padding flag */
unsigned char version:2; /* protocol version */
unsigned char pt:8; /* payload type */
uint16_t len; /* length */
uint32_t ssrc; /* synchronization source */
} srtcp_hdr_t;
typedef struct {
unsigned int index:31; /* srtcp packet index in network order! */
unsigned int e:1; /* encrypted? 1=yes */
/* optional mikey/etc go here */
/* and then the variable-length auth tag */
} srtcp_trailer_t;
#else /* BIG_ENDIAN */
typedef struct {
unsigned char version:2; /* protocol version */
unsigned char p:1; /* padding flag */
unsigned char rc:5; /* reception report count */
unsigned char pt:8; /* payload type */
uint16_t len; /* length */
uint32_t ssrc; /* synchronization source */
} srtcp_hdr_t;
typedef struct {
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
unsigned int count:5; /* varies by packet type */
unsigned int pt:8; /* payload type */
uint16_t length; /* len of uint32s of packet less header */
} rtcp_common_t;
typedef struct {
unsigned int e:1; /* encrypted? 1=yes */
unsigned int index:31; /* srtcp packet index */
/* optional mikey/etc go here */
/* and then the variable-length auth tag */
} srtcp_trailer_t;
#endif
/*
* the following declarations are libSRTP internal functions
*/
......@@ -216,7 +108,7 @@ typedef enum direction_t {
* cipher_t and auth_t pointers will point to the same structures
*/
typedef struct srtp_stream_ctx_t {
typedef struct srtp_stream_ctx_t_ {
uint32_t ssrc;
cipher_t *rtp_cipher;
auth_t *rtp_auth;
......@@ -232,19 +124,19 @@ typedef struct srtp_stream_ctx_t {
ekt_stream_t ekt;
uint8_t salt[SRTP_AEAD_SALT_LEN]; /* used with GCM mode for SRTP */
uint8_t c_salt[SRTP_AEAD_SALT_LEN]; /* used with GCM mode for SRTCP */
struct srtp_stream_ctx_t *next; /* linked list of streams */
} srtp_stream_ctx_t;
struct srtp_stream_ctx_t_ *next; /* linked list of streams */
} strp_stream_ctx_t_;
/*
* an srtp_ctx_t holds a stream list and a service description
*/
typedef struct srtp_ctx_t {
srtp_stream_ctx_t *stream_list; /* linked list of streams */
srtp_stream_ctx_t *stream_template; /* act as template for other streams */
typedef struct srtp_ctx_t_ {
struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */
struct srtp_stream_ctx_t_ *stream_template; /* act as template for other streams */
void *user_data; /* user custom data */
} srtp_ctx_t;
} srtp_ctx_t_;
......
......@@ -42,8 +42,10 @@
*
*/
#include "srtp.h"
#include "srtp_priv.h"
#include "crypto_types.h"
#include "err.h"
#include "ekt.h" /* for SRTP Encrypted Key Transport */
#include "alloc.h" /* for crypto_alloc() */
#ifdef OPENSSL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment