The enclosed patch adds MKI support to libsrtp. The test suite has been updated so that it continues to work. However, there are no new tests that verifies the MKI implementation.
The API is changed to make it possible to specify more than one key. There is however currently no support for actually using more than one key. This change was made to reduce the number of times users of this library will have to update their code.
The patch also fixes two other issues:
srtp_unprotect() and srtp_unprotect_rtcp() didn't properly check that it didn't read past the supplied packet. It may have been possible to construct an evil packet that will cause a buffer overflow, but I have not fully analyzed this. It was easier to just add some defensive code. As a result, srtp_unprotect() and srtp_unprotect_rtcp() can now fail with err_status_parse_err. (Maybe a new error code should have been added instead?)
SRTCP was misspelled as "srtpc" in a comment.
SRTP_MAX_MKI_LEN has been added, and somewhat arbitrarily set at 128. This define is actually only used to compute a new and larger value for SRTP_MAX_TRAILER_LEN. Since the MKI can be of any size, and most sensible applications only use at most 4 bytes for it, it makes little sense to punish all applications with 128 bytes overhead. Maybe srtp_get_trailer_length() should be reinstated? It could return the proper value for a particular stream.