This function is used for calculating digest position for RTMP handshake
packets.
Signed-off-by: Martin Storsjö <martin@martin.st>
... | ... |
@@ -57,4 +57,15 @@ |
57 | 57 |
int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, |
58 | 58 |
const uint8_t *key, int keylen, uint8_t *dst); |
59 | 59 |
|
60 |
+/** |
|
61 |
+ * Calculate digest position for RTMP handshake packets. |
|
62 |
+ * |
|
63 |
+ * @param buf input buffer (should be 1536 bytes) |
|
64 |
+ * @param off offset in buffer where to start calculating digest position |
|
65 |
+ * @param mod_val value used for computing modulo |
|
66 |
+ * @param add_val value added at the end (after computing modulo) |
|
67 |
+ */ |
|
68 |
+int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, |
|
69 |
+ int add_val); |
|
70 |
+ |
|
60 | 71 |
#endif /* AVFORMAT_RTMP_H */ |
... | ... |
@@ -632,6 +632,18 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, |
632 | 632 |
return 0; |
633 | 633 |
} |
634 | 634 |
|
635 |
+int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, |
|
636 |
+ int add_val) |
|
637 |
+{ |
|
638 |
+ int i, digest_pos = 0; |
|
639 |
+ |
|
640 |
+ for (i = 0; i < 4; i++) |
|
641 |
+ digest_pos += buf[i + off]; |
|
642 |
+ digest_pos = digest_pos % mod_val + add_val; |
|
643 |
+ |
|
644 |
+ return digest_pos; |
|
645 |
+} |
|
646 |
+ |
|
635 | 647 |
/** |
636 | 648 |
* Put HMAC-SHA2 digest of packet data (except for the bytes where this digest |
637 | 649 |
* will be stored) into that packet. |
... | ... |
@@ -641,12 +653,9 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, |
641 | 641 |
*/ |
642 | 642 |
static int rtmp_handshake_imprint_with_digest(uint8_t *buf) |
643 | 643 |
{ |
644 |
- int i, digest_pos = 0; |
|
645 |
- int ret; |
|
644 |
+ int ret, digest_pos; |
|
646 | 645 |
|
647 |
- for (i = 8; i < 12; i++) |
|
648 |
- digest_pos += buf[i]; |
|
649 |
- digest_pos = (digest_pos % 728) + 12; |
|
646 |
+ digest_pos = ff_rtmp_calc_digest_pos(buf, 8, 728, 12); |
|
650 | 647 |
|
651 | 648 |
ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, |
652 | 649 |
rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN, |
... | ... |
@@ -666,13 +675,10 @@ static int rtmp_handshake_imprint_with_digest(uint8_t *buf) |
666 | 666 |
*/ |
667 | 667 |
static int rtmp_validate_digest(uint8_t *buf, int off) |
668 | 668 |
{ |
669 |
- int i, digest_pos = 0; |
|
670 | 669 |
uint8_t digest[32]; |
671 |
- int ret; |
|
670 |
+ int ret, digest_pos; |
|
672 | 671 |
|
673 |
- for (i = 0; i < 4; i++) |
|
674 |
- digest_pos += buf[i + off]; |
|
675 |
- digest_pos = (digest_pos % 728) + off + 4; |
|
672 |
+ digest_pos = ff_rtmp_calc_digest_pos(buf, off, 728, off + 4); |
|
676 | 673 |
|
677 | 674 |
ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, |
678 | 675 |
rtmp_server_key, SERVER_KEY_OPEN_PART_LEN, |