Begin header file refactoring. This is a work-in-progress.
diff --git a/Makefile.in b/Makefile.in
index eb4ce65..b5b07ac 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -229,9 +229,9 @@
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 \
diff --git a/crypto/include/auth.h b/crypto/include/auth.h
index 5b5e4b2..f56e3a5 100644
--- a/crypto/include/auth.h
+++ b/crypto/include/auth.h
@@ -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;
diff --git a/crypto/include/cipher.h b/crypto/include/cipher.h
index d0d6b57..53d3041 100644
--- a/crypto/include/cipher.h
+++ b/crypto/include/cipher.h
@@ -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 */
diff --git a/crypto/include/crypto.h b/crypto/include/crypto.h
deleted file mode 100644
index 0e9667d..0000000
--- a/crypto/include/crypto.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 */
-
-
diff --git a/crypto/include/crypto_kernel.h b/crypto/include/crypto_kernel.h
index caccfa0..f012296 100644
--- a/crypto/include/crypto_kernel.h
+++ b/crypto/include/crypto_kernel.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:
diff --git a/crypto/include/err.h b/crypto/include/err.h
index 4f401a6..b56416f 100644
--- a/crypto/include/err.h
+++ b/crypto/include/err.h
@@ -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;
-
/**
* @}
*/
diff --git a/include/rtp.h b/include/rtp.h
index 0e0119c..2e8201a 100644
--- a/include/rtp.h
+++ b/include/rtp.h
@@ -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 @@
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 */
diff --git a/include/rtp_priv.h b/include/rtp_priv.h
index 1421386..2501846 100644
--- a/include/rtp_priv.h
+++ b/include/rtp_priv.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 */
diff --git a/include/srtp.h b/include/srtp.h
index 48416d3..eb8630c 100644
--- a/include/srtp.h
+++ b/include/srtp.h
@@ -51,9 +51,6 @@
#endif
#include <stdint.h>
-#include "crypto.h"
-#include "crypto_types.h"
-#include "err.h"
/**
* @defgroup SRTP Secure RTP
@@ -101,7 +98,180 @@
#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
@@ -261,7 +431,7 @@
* 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 @@
* a set of streams.
*
*/
-typedef struct srtp_stream_ctx_t *srtp_stream_t;
+typedef srtp_stream_ctx_t *srtp_stream_t;
diff --git a/include/srtp_priv.h b/include/srtp_priv.h
index 170df5b..de6bf6c 100644
--- a/include/srtp_priv.h
+++ b/include/srtp_priv.h
@@ -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"
@@ -61,113 +60,6 @@
#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 @@
* 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 @@
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_;
diff --git a/srtp/srtp.c b/srtp/srtp.c
index 8841a9e..1c3aaa7 100644
--- a/srtp/srtp.c
+++ b/srtp/srtp.c
@@ -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