2
0

fuzzer.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #define MAX_KEY_LEN 46
  2. #define EXTRACT(dest, src, srcsize, copysize) \
  3. { \
  4. memcpy((dest), (src), (copysize)); \
  5. (src) += (copysize); \
  6. (srcsize) -= (copysize); \
  7. }
  8. /* Extract data if src contains sufficient bytes, otherwise go to end */
  9. #define EXTRACT_IF(dest, src, srcsize, copysize) \
  10. { \
  11. if ((srcsize) < (copysize)) { \
  12. goto end; \
  13. } else { \
  14. EXTRACT((dest), (src), (srcsize), (copysize)); \
  15. } \
  16. }
  17. #include <stdint.h>
  18. #if UINTPTR_MAX == 0xffffffff
  19. #define FUZZ_32BIT
  20. #elif UINTPTR_MAX == 0xffffffffffffffff
  21. #else
  22. #error "Cannot detect word size"
  23. #endif
  24. typedef srtp_err_status_t (
  25. *fuzz_srtp_func)(srtp_t, void *, int *, uint8_t, unsigned int);
  26. typedef void (*fuzz_srtp_crypto_policy_func)(srtp_crypto_policy_t *);
  27. typedef srtp_err_status_t (*fuzz_srtp_get_length_func)(const srtp_t,
  28. uint8_t,
  29. unsigned int,
  30. uint32_t *);
  31. struct fuzz_srtp_params {
  32. uint8_t srtp_func;
  33. uint8_t srtp_crypto_policy_func;
  34. uint16_t window_size;
  35. uint8_t allow_repeat_tx;
  36. uint8_t ssrc_type;
  37. unsigned int ssrc_value;
  38. uint8_t key[MAX_KEY_LEN];
  39. uint8_t mki;
  40. };
  41. static srtp_err_status_t fuzz_srtp_protect(srtp_t srtp_sender,
  42. void *hdr,
  43. int *len,
  44. uint8_t use_mki,
  45. unsigned int mki);
  46. static srtp_err_status_t fuzz_srtp_unprotect(srtp_t srtp_sender,
  47. void *hdr,
  48. int *len,
  49. uint8_t use_mki,
  50. unsigned int mki);
  51. static srtp_err_status_t fuzz_srtp_protect_rtcp(srtp_t srtp_sender,
  52. void *hdr,
  53. int *len,
  54. uint8_t use_mki,
  55. unsigned int mki);
  56. static srtp_err_status_t fuzz_srtp_unprotect_rtcp(srtp_t srtp_sender,
  57. void *hdr,
  58. int *len,
  59. uint8_t use_mki,
  60. unsigned int mki);
  61. static srtp_err_status_t fuzz_srtp_protect_mki(srtp_t srtp_sender,
  62. void *hdr,
  63. int *len,
  64. uint8_t use_mki,
  65. unsigned int mki);
  66. static srtp_err_status_t fuzz_srtp_protect_rtcp_mki(srtp_t srtp_sender,
  67. void *hdr,
  68. int *len,
  69. uint8_t use_mki,
  70. unsigned int mki);
  71. static srtp_err_status_t fuzz_srtp_unprotect_mki(srtp_t srtp_sender,
  72. void *hdr,
  73. int *len,
  74. uint8_t use_mki,
  75. unsigned int mki);
  76. static srtp_err_status_t fuzz_srtp_unprotect_rtcp_mki(srtp_t srtp_sender,
  77. void *hdr,
  78. int *len,
  79. uint8_t use_mki,
  80. unsigned int mki);
  81. static srtp_err_status_t fuzz_srtp_get_protect_length(const srtp_t srtp_ctx,
  82. uint8_t use_mki,
  83. unsigned int mki,
  84. uint32_t *length);
  85. static srtp_err_status_t fuzz_srtp_get_protect_mki_length(const srtp_t srtp_ctx,
  86. uint8_t use_mki,
  87. unsigned int mki,
  88. uint32_t *length);
  89. static srtp_err_status_t fuzz_srtp_get_protect_rtcp_length(
  90. const srtp_t srtp_ctx,
  91. uint8_t use_mki,
  92. unsigned int mki,
  93. uint32_t *length);
  94. static srtp_err_status_t fuzz_srtp_get_protect_rtcp_mki_length(
  95. const srtp_t srtp_ctx,
  96. uint8_t use_mki,
  97. unsigned int mki,
  98. uint32_t *length);
  99. struct fuzz_srtp_func_ext {
  100. fuzz_srtp_func srtp_func;
  101. bool protect;
  102. fuzz_srtp_get_length_func get_length;
  103. };
  104. const struct fuzz_srtp_func_ext srtp_funcs[] = {
  105. { fuzz_srtp_protect, true, fuzz_srtp_get_protect_length },
  106. { fuzz_srtp_unprotect, false, NULL },
  107. { fuzz_srtp_protect_rtcp, true, fuzz_srtp_get_protect_rtcp_length },
  108. { fuzz_srtp_unprotect_rtcp, false, NULL },
  109. { fuzz_srtp_protect_mki, true, fuzz_srtp_get_protect_mki_length },
  110. { fuzz_srtp_unprotect_mki, false, NULL },
  111. { fuzz_srtp_protect_rtcp_mki, true, fuzz_srtp_get_protect_rtcp_mki_length },
  112. { fuzz_srtp_unprotect_rtcp_mki, false, NULL }
  113. };
  114. struct fuzz_srtp_crypto_policy_func_ext {
  115. fuzz_srtp_crypto_policy_func crypto_policy_func;
  116. const char *name;
  117. };
  118. const struct fuzz_srtp_crypto_policy_func_ext fuzz_srtp_crypto_policies[] = {
  119. { srtp_crypto_policy_set_rtp_default, "" },
  120. { srtp_crypto_policy_set_rtcp_default, "" },
  121. { srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32,
  122. "srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32" },
  123. { srtp_crypto_policy_set_aes_cm_128_null_auth,
  124. "srtp_crypto_policy_set_aes_cm_128_null_auth" },
  125. { srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32,
  126. "srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32" },
  127. { srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80,
  128. "srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80" },
  129. { srtp_crypto_policy_set_aes_cm_256_null_auth,
  130. "srtp_crypto_policy_set_aes_cm_256_null_auth" },
  131. { srtp_crypto_policy_set_null_cipher_hmac_null,
  132. "srtp_crypto_policy_set_null_cipher_hmac_null" },
  133. { srtp_crypto_policy_set_null_cipher_hmac_sha1_80,
  134. "srtp_crypto_policy_set_null_cipher_hmac_sha1_80" },
  135. #ifdef OPENSSL
  136. { srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32,
  137. "srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32" },
  138. { srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80,
  139. "srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80" },
  140. { srtp_crypto_policy_set_aes_cm_192_null_auth,
  141. "srtp_crypto_policy_set_aes_cm_192_null_auth" },
  142. { srtp_crypto_policy_set_aes_gcm_128_16_auth,
  143. "srtp_crypto_policy_set_aes_gcm_128_16_auth" },
  144. { srtp_crypto_policy_set_aes_gcm_128_8_auth,
  145. "srtp_crypto_policy_set_aes_gcm_128_8_auth" },
  146. { srtp_crypto_policy_set_aes_gcm_128_8_only_auth,
  147. "srtp_crypto_policy_set_aes_gcm_128_8_only_auth" },
  148. { srtp_crypto_policy_set_aes_gcm_256_16_auth,
  149. "srtp_crypto_policy_set_aes_gcm_256_16_auth" },
  150. { srtp_crypto_policy_set_aes_gcm_256_8_auth,
  151. "srtp_crypto_policy_set_aes_gcm_256_8_auth" },
  152. { srtp_crypto_policy_set_aes_gcm_256_8_only_auth,
  153. "srtp_crypto_policy_set_aes_gcm_256_8_only_auth" },
  154. #endif
  155. };
  156. struct fuzz_srtp_ssrc_type_ext {
  157. srtp_ssrc_type_t srtp_ssrc_type;
  158. const char *name;
  159. };
  160. const struct fuzz_srtp_ssrc_type_ext fuzz_ssrc_type_map[] = {
  161. { ssrc_undefined, "ssrc_undefined" },
  162. { ssrc_specific, "ssrc_specific" },
  163. { ssrc_any_inbound, "ssrc_any_inbound" },
  164. { ssrc_any_outbound, "ssrc_any_outbound" },
  165. };