protection_profile.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package srtp
  2. import "fmt"
  3. // ProtectionProfile specifies Cipher and AuthTag details, similar to TLS cipher suite
  4. type ProtectionProfile uint16
  5. // Supported protection profiles
  6. // See https://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
  7. const (
  8. ProtectionProfileAes128CmHmacSha1_80 ProtectionProfile = 0x0001
  9. ProtectionProfileAes128CmHmacSha1_32 ProtectionProfile = 0x0002
  10. ProtectionProfileAeadAes128Gcm ProtectionProfile = 0x0007
  11. )
  12. func (p ProtectionProfile) keyLen() (int, error) {
  13. switch p {
  14. case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80, ProtectionProfileAeadAes128Gcm:
  15. return 16, nil
  16. default:
  17. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  18. }
  19. }
  20. func (p ProtectionProfile) saltLen() (int, error) {
  21. switch p {
  22. case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
  23. return 14, nil
  24. case ProtectionProfileAeadAes128Gcm:
  25. return 12, nil
  26. default:
  27. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  28. }
  29. }
  30. func (p ProtectionProfile) rtpAuthTagLen() (int, error) {
  31. switch p {
  32. case ProtectionProfileAes128CmHmacSha1_80:
  33. return 10, nil
  34. case ProtectionProfileAes128CmHmacSha1_32:
  35. return 4, nil
  36. case ProtectionProfileAeadAes128Gcm:
  37. return 0, nil
  38. default:
  39. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  40. }
  41. }
  42. func (p ProtectionProfile) rtcpAuthTagLen() (int, error) {
  43. switch p {
  44. case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
  45. return 10, nil
  46. case ProtectionProfileAeadAes128Gcm:
  47. return 0, nil
  48. default:
  49. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  50. }
  51. }
  52. func (p ProtectionProfile) aeadAuthTagLen() (int, error) {
  53. switch p {
  54. case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
  55. return 0, nil
  56. case ProtectionProfileAeadAes128Gcm:
  57. return 16, nil
  58. default:
  59. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  60. }
  61. }
  62. func (p ProtectionProfile) authKeyLen() (int, error) {
  63. switch p {
  64. case ProtectionProfileAes128CmHmacSha1_32, ProtectionProfileAes128CmHmacSha1_80:
  65. return 20, nil
  66. case ProtectionProfileAeadAes128Gcm:
  67. return 0, nil
  68. default:
  69. return 0, fmt.Errorf("%w: %#v", errNoSuchSRTPProfile, p)
  70. }
  71. }