srtp_cipher.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package srtp
  2. import "github.com/pion/rtp"
  3. // cipher represents a implementation of one
  4. // of the SRTP Specific ciphers
  5. type srtpCipher interface {
  6. // authTagLen returns auth key length of the cipher.
  7. // See the note below.
  8. rtpAuthTagLen() (int, error)
  9. rtcpAuthTagLen() (int, error)
  10. // aeadAuthTagLen returns AEAD auth key length of the cipher.
  11. // See the note below.
  12. aeadAuthTagLen() (int, error)
  13. getRTCPIndex([]byte) uint32
  14. encryptRTP([]byte, *rtp.Header, []byte, uint32) ([]byte, error)
  15. encryptRTCP([]byte, []byte, uint32, uint32) ([]byte, error)
  16. decryptRTP([]byte, []byte, *rtp.Header, int, uint32) ([]byte, error)
  17. decryptRTCP([]byte, []byte, uint32, uint32) ([]byte, error)
  18. }
  19. /*
  20. NOTE: Auth tag and AEAD auth tag are placed at the different position in SRTCP
  21. In non-AEAD cipher, the authentication tag is placed *after* the ESRTCP word
  22. (Encrypted-flag and SRTCP index).
  23. > AES_128_CM_HMAC_SHA1_80
  24. > | RTCP Header | Encrypted payload |E| SRTCP Index | Auth tag |
  25. > ^ |----------|
  26. > | ^
  27. > | authTagLen=10
  28. > aeadAuthTagLen=0
  29. In AEAD cipher, the AEAD authentication tag is embedded in the ciphertext.
  30. It is *before* the ESRTCP word (Encrypted-flag and SRTCP index).
  31. > AEAD_AES_128_GCM
  32. > | RTCP Header | Encrypted payload | AEAD auth tag |E| SRTCP Index |
  33. > |---------------| ^
  34. > ^ authTagLen=0
  35. > aeadAuthTagLen=16
  36. See https://tools.ietf.org/html/rfc7714 for the full specifications.
  37. */